contrail-neutron-plugin
contrail-neutron-plugin copied to clipboard
resource_list not work correctly
file:neutron_plugin_contrail/plugins/opencontrail/vnc_client/vn_res_handler.py
def resource_list(self, context=None, filters=None, fields=None):
| contrail_extensions_enabled = self._kwargs.get(
| 'contrail_extensions_enabled', False)
| contrail_exts_enabled = contrail_extensions_enabled
| ret_dict = {}
|
| def _collect_without_prune(net_ids):
| for net_id in net_ids:
| try:
| net_obj = self._resource_get(id=net_id)
| net_info = self.vn_to_neutron_dict(
| net_obj,
| contrail_extensions_enabled=contrail_exts_enabled,
| fields=fields)
| ret_dict[net_id] = net_info
| except vnc_exc.NoIdError:
| pass
| # end _collect_without_prune
|
| # collect phase
| all_net_objs = [] # all n/ws in all projects
| if context and not context['is_admin']:
| if filters and 'id' in filters:
| _collect_without_prune(filters['id'])
| elif filters and 'name' in filters:
| net_objs = self._network_list_project(context['tenant'])
| all_net_objs.extend(net_objs)
| all_net_objs.extend(self._network_list_shared())
| all_net_objs.extend(self._network_list_router_external())
| elif (filters and 'shared' in filters and filters['shared'][0] and
| 'router:external' not in filters):
| all_net_objs.extend(self._network_list_shared())
#wrong
| elif (filters and 'router:external' in filters and
| 'shared' not in filters):
| all_net_objs.extend(self._network_list_router_external())
| elif (filters and 'router:external' in filters and
| 'shared' in filters):
#end of wrong code
| all_net_objs.extend(self._network_list_shared_and_ext())
| else:
| project_uuid = self._project_id_neutron_to_vnc(
| context['tenant'])
| if not filters:
| all_net_objs.extend(self._network_list_router_external())
| all_net_objs.extend(self._network_list_shared())
| all_net_objs.extend(self._network_list_project(project_uuid))
#########################
| elif (filters and 'router:external' in filters and
| 'shared' not in filters):
| all_net_objs.extend(self._network_list_router_external())
| elif (filters and 'router:external' in filters and
| 'shared' in filters):
the filters is a dictionary like below:
{u'shared': [False], u'tenant_id': [u'f96d2b5b15c84e2e82e78a9a388679a4'], u'router:external': [False]}
the condition should be both the key in filter and the value is True when it's a bool.
The right code:
elif (filters and 'router:external' in filters and filters['router:external'][0] and
'shared' not in filters):
all_net_objs.extend(self._network_list_router_external())
elif (filters and 'router:external' in filters and filters['router:external'][0] and
'shared' in filters and filters['shared'][0]):
all_net_objs.extend(self._network_list_shared_and_ext())