Skip to content

Commit

Permalink
Use obj_uuids to filter SGs instead of prune phase
Browse files Browse the repository at this point in the history
Change-Id: I9ce41d519795ded195e4773d84dbd09b5cf40541
Partial-Bug: #1480901
  • Loading branch information
safchain authored and opencontrail-ci-admin committed Aug 6, 2015
1 parent a2057b4 commit 2bbf547
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Expand Up @@ -478,7 +478,7 @@ def _ipam_list_project(self, project_id):
return resp_dict['network-ipams']
#end _ipam_list_project

def _security_group_list_project(self, project_id):
def _security_group_list_project(self, project_id, filters=None):
if project_id:
try:
project_uuid = str(uuid.UUID(project_id))
Expand All @@ -489,8 +489,12 @@ def _security_group_list_project(self, project_id):
else:
project_uuid = None

obj_uuids=None
if filters and 'id' in filters:
obj_uuids = filters['id']
sg_objs = self._vnc_lib.security_groups_list(parent_id=project_uuid,
detail=True)
detail=True,
obj_uuids=obj_uuids)
return sg_objs
#end _security_group_list_project

Expand Down Expand Up @@ -3677,29 +3681,27 @@ def security_group_list(self, context, filters=None):

all_sgs = [] # all sgs in all projects
if context and not context['is_admin']:
project_sgs = self._security_group_list_project(str(uuid.UUID(context['tenant'])))
project_sgs = self._security_group_list_project(str(uuid.UUID(context['tenant'])), filters)
all_sgs.append(project_sgs)
else: # admin context
if filters and 'tenant_id' in filters:
project_ids = self._validate_project_ids(context,
filters['tenant_id'])
for p_id in project_ids:
project_sgs = self._security_group_list_project(p_id)
project_sgs = self._security_group_list_project(p_id, filters)
all_sgs.append(project_sgs)
else: # no filters
all_sgs.append(self._security_group_list_project(None))
else: # no tenant_id filter
all_sgs.append(self._security_group_list_project(None, filters))

# prune phase
for project_sgs in all_sgs:
for sg_obj in project_sgs:
if not self._filters_is_present(filters, 'id', sg_obj.uuid):
continue
if not self._filters_is_present(filters, 'name',
sg_obj.get_display_name() or sg_obj.name):
continue
try:
sg_info = self._security_group_vnc_to_neutron(sg_obj)
except NoIdError:
except NoIdError:
continue
except Exception as e:
self.logger.error("Error in security_group_list: %s", str(e))
Expand Down Expand Up @@ -3805,23 +3807,20 @@ def security_group_rule_list(self, context=None, filters=None):
project_ids = self._validate_project_ids(context,
filters['tenant_id'])
for p_id in project_ids:
project_sgs = self._security_group_list_project(p_id)
project_sgs = self._security_group_list_project(p_id, filters)
all_sgs.append(project_sgs)
else: # no filters
p_id = None
if context and not context['is_admin']:
p_id = str(uuid.UUID(context['tenant']))
all_sgs.append(self._security_group_list_project(p_id))
all_sgs.append(self._security_group_list_project(p_id, filters))

# prune phase
for project_sgs in all_sgs:
for sg_obj in project_sgs:
# TODO implement same for name specified in filter
if not self._filters_is_present(filters, 'id', sg_obj.uuid):
continue
try:
sgr_info = self.security_group_rules_read(sg_obj.uuid, sg_obj)
except NoIdError:
except NoIdError:
continue
except Exception as e:
self.logger.error("Error in security_group_rule_list: %s",
Expand Down

0 comments on commit 2bbf547

Please sign in to comment.