From a540167587ccbbea16227a66170ac1d3ad68bfcb Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Wed, 29 Apr 2015 15:02:59 -0400 Subject: [PATCH] Update secgroup API for new get/list/search API Security group API now conforms to the new get/list/search interface. Instead of a Nova object being returned, we now return a dict (or list of dicts). Change-Id: I0b84ef6065101948ffb2a0f56235bda7a071ad17 --- shade/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/shade/__init__.py b/shade/__init__.py index 535f804ed..0044fba6f 100644 --- a/shade/__init__.py +++ b/shade/__init__.py @@ -824,6 +824,10 @@ class OpenStackCloud(object): flavors = self.list_flavors() return self._filter_list(flavors, name_or_id, filters) + def search_security_groups(self, name_or_id=None, filters=None): + groups = self.list_security_groups() + return self._filter_list(groups, name_or_id, filters) + def list_networks(self): return self.manager.submitTask(_tasks.NetworkList())['networks'] @@ -848,6 +852,11 @@ class OpenStackCloud(object): self.manager.submitTask(_tasks.FlavorList()) ) + def list_security_groups(self): + return meta.obj_list_to_dict( + self.manager.submitTask(_tasks.SecurityGroupList()) + ) + def get_network(self, name_or_id, filters=None): return self._get_entity(self.search_networks, name_or_id, filters) @@ -863,6 +872,10 @@ class OpenStackCloud(object): def get_flavor(self, name_or_id, filters=None): return self._get_entity(self.search_flavors, name_or_id, filters) + def get_security_group(self, name_or_id, filters=None): + return self._get_entity(self.search_security_groups, + name_or_id, filters) + # TODO(Shrews): This will eventually need to support tenant ID and # provider networks, which are admin-level params. def create_network(self, name, shared=False, admin_state_up=True): @@ -1492,12 +1505,6 @@ class OpenStackCloud(object): groups = meta.get_groups_from_server(self, server, server_vars) return dict(server_vars=server_vars, groups=groups) - def get_security_group(self, name_or_id): - for secgroup in self.manager.submitTask(_tasks.SecurityGroupList()): - if name_or_id in (secgroup.name, secgroup.id): - return secgroup - return None - def get_openstack_vars(self, server): return meta.get_hostvars_from_server(self, server)