diff --git a/novaclient/v1_1/client.py b/novaclient/v1_1/client.py index c002e1f96..9b5e97397 100644 --- a/novaclient/v1_1/client.py +++ b/novaclient/v1_1/client.py @@ -27,7 +27,7 @@ class Client(object): def __init__(self, username, api_key, project_id, auth_url, timeout=None): self.flavors = flavors.FlavorManager(self) self.images = images.ImageManager(self) - self.security_groups = security_groups.SecurityGroupManager(self) + self.security_groups = security_groups.SecurityGroupManager(self) self.servers = servers.ServerManager(self) self.zones = zones.ZoneManager(self) diff --git a/novaclient/v1_1/security_groups.py b/novaclient/v1_1/security_groups.py index a1bd2fbe3..2f58f051a 100644 --- a/novaclient/v1_1/security_groups.py +++ b/novaclient/v1_1/security_groups.py @@ -25,45 +25,51 @@ class SecurityGroup(base.Resource): def __repr__(self): return "" % self.uuid + def __str__(self): + return self.uuid + @property def uuid(self): return self.name + def delete(self): + self.manager.delete(self) + class SecurityGroupManager(base.ManagerWithFind): resource_class = SecurityGroup def create(self, name, description): """ - Create a security group - - :param name: name for the security group to dreate - :param description: description of the security group - """ + Create a security group + + :param name: name for the security group to dreate + :param description: description of the security group + """ body = {"security_group": {"name": name, 'description': description}} return self._create('/extras/security_groups', body, 'security_group') def delete(self, id): """ - Delete a security group - - :param id: The security group ID to delete - """ + Delete a security group + + :param id: The security group ID to delete + """ return self._delete('/extras/security_groups/%s' % id) def get(self, id): """ - Get a security group - - :param id: The security group ID to get - :rtype: :class:`SecurityGroup` + Get a security group + + :param id: The security group ID to get + :rtype: :class:`SecurityGroup` """ return self._get('/extras/security_groups/%s' % id, 'security_group') def list(self): """ Get a list of all security_groups - + :rtype: list of :class:`SecurityGroup` """ return self._list("/extras/security_groups", "security_groups") diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index 9585e8314..e85331f56 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -378,16 +378,16 @@ class FakeHTTPClient(base_client.HTTPClient): # Security Groups # def get_extras_security_groups(self, **kw): - return (200, {"security_groups": [ - {'name': 'test', 'description': 'FAKE_SECURITY_GROUP'} - ]}) + return (200, {"security_groups": [ + {'name': 'test', 'description': 'FAKE_SECURITY_GROUP'} + ]}) def delete_extras_security_groups_test(self, **kw): - return (202, None) + return (202, None) def post_extras_security_groups(self, body, **kw): - assert body.keys() == ['security_group'] - fakes.assert_has_keys(body['security_group'], - required=['name','description']) - r = {'security_group': self.get_extras_security_groups()[1]['security_groups'][0]} - return (202, r) + assert body.keys() == ['security_group'] + fakes.assert_has_keys(body['security_group'], + required=['name','description']) + r = {'security_group': self.get_extras_security_groups()[1]['security_groups'][0]} + return (202, r)