summaryrefslogtreecommitdiff
path: root/novaclient/v2/security_groups.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/security_groups.py')
-rw-r--r--novaclient/v2/security_groups.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/novaclient/v2/security_groups.py b/novaclient/v2/security_groups.py
new file mode 100644
index 0000000..40d1e7f
--- /dev/null
+++ b/novaclient/v2/security_groups.py
@@ -0,0 +1,96 @@
1# Copyright 2011 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16"""
17Security group interface (1.1 extension).
18"""
19
20import six
21from six.moves.urllib import parse
22
23from novaclient import base
24
25
26class SecurityGroup(base.Resource):
27 def __str__(self):
28 return str(self.id)
29
30 def delete(self):
31 self.manager.delete(self)
32
33 def update(self):
34 self.manager.update(self)
35
36
37class SecurityGroupManager(base.ManagerWithFind):
38 resource_class = SecurityGroup
39
40 def create(self, name, description):
41 """
42 Create a security group
43
44 :param name: name for the security group to create
45 :param description: description of the security group
46 :rtype: the security group object
47 """
48 body = {"security_group": {"name": name, 'description': description}}
49 return self._create('/os-security-groups', body, 'security_group')
50
51 def update(self, group, name, description):
52 """
53 Update a security group
54
55 :param group: The security group to update (group or ID)
56 :param name: name for the security group to update
57 :param description: description for the security group to update
58 :rtype: the security group object
59 """
60 body = {"security_group": {"name": name, 'description': description}}
61 return self._update('/os-security-groups/%s' % base.getid(group),
62 body, 'security_group')
63
64 def delete(self, group):
65 """
66 Delete a security group
67
68 :param group: The security group to delete (group or ID)
69 :rtype: None
70 """
71 self._delete('/os-security-groups/%s' % base.getid(group))
72
73 def get(self, group_id):
74 """
75 Get a security group
76
77 :param group_id: The security group to get by ID
78 :rtype: :class:`SecurityGroup`
79 """
80 return self._get('/os-security-groups/%s' % group_id,
81 'security_group')
82
83 def list(self, search_opts=None):
84 """
85 Get a list of all security_groups
86
87 :rtype: list of :class:`SecurityGroup`
88 """
89 search_opts = search_opts or {}
90
91 qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
92
93 query_string = '?%s' % parse.urlencode(qparams) if qparams else ''
94
95 return self._list('/os-security-groups%s' % query_string,
96 'security_groups')