From 33be140a6ea14b9ffff9d43a41f332656413caf5 Mon Sep 17 00:00:00 2001 From: Gary Kotton <gkotton@vmware.com> Date: Sat, 17 Feb 2018 02:58:19 +0200 Subject: [PATCH] NSX|TVD: add ability to add extra filters Certain resources require certain filters. For example, a V user, where the service tenant is T will not show the IP addresses on the 'nova list' command. This requires that the 'id' be filtered. Change-Id: I8b563d1b80974bcee3ed839eaec202052a8ec784 --- vmware_nsx/plugins/nsx/plugin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/plugins/nsx/plugin.py b/vmware_nsx/plugins/nsx/plugin.py index 5d8f78276b..801ee3b603 100644 --- a/vmware_nsx/plugins/nsx/plugin.py +++ b/vmware_nsx/plugins/nsx/plugin.py @@ -319,7 +319,7 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, p = self._get_plugin_from_net_id(context, id) return p.get_network(context, id, fields=fields) - def _get_plugin_for_request(self, context, filters): + def _get_plugin_for_request(self, context, filters, keys=None): project_id = context.project_id if filters: if filters.get('tenant_id'): @@ -329,8 +329,12 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, else: # we have specific filters on the request. If those are # specific enough, we should not filter by project - if filters.get('device_id'): + if filters.get('id'): return + if keys: + for key in keys: + if filters.get(key): + return # If there are multiple tenants/projects being requested then # we will not filter according to the plugin if isinstance(project_id, list): @@ -342,7 +346,8 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, page_reverse=False): # Read project plugin to filter relevant projects according to # plugin - req_p = self._get_plugin_for_request(context, filters) + req_p = self._get_plugin_for_request(context, filters, + keys=['shared']) filters = filters or {} with db_api.context_manager.reader.using(context): networks = ( @@ -398,7 +403,8 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, page_reverse=False): # Read project plugin to filter relevant projects according to # plugin - req_p = self._get_plugin_for_request(context, filters) + req_p = self._get_plugin_for_request(context, filters, + keys=['device_id']) filters = filters or {} with db_api.context_manager.reader.using(context): ports = (