def get_router_details(self, request, id, **kwargs): context = request.context context.is_admin = False routers_controller = self._get_resource_controller('routers') _request = resource.Request({'neutron.context': context}) router = routers_controller.show(_request, id) ports_controller = self._get_resource_controller('ports') _request = resource.Request({ 'QUERY_STRING': ('device_id=%(id)s&device_owner=%(owner)s' % { 'id': id, 'owner': 'network:router_interface' }), 'neutron.context': context }) ports = ports_controller.index(_request) # NOTE(gongysh) fill in subnet name subnetid_portfixedip_dict = {} for port in ports['ports']: if port['fixed_ips']: fixed_ip = port['fixed_ips'][0] fixed_ips = subnetid_portfixedip_dict.get( fixed_ip['subnet_id'], []) fixed_ips.append(fixed_ip) subnetid_portfixedip_dict[fixed_ip['subnet_id']] = fixed_ips subnetids = subnetid_portfixedip_dict.keys() plugin = manager.NeutronManager.get_service_plugins()[constants.CORE] subnets = plugin.get_subnets(context, filters={'id': subnetids}) for subnet in subnets: for fixed_ip in subnetid_portfixedip_dict[subnet['id']]: fixed_ip['subnet_name'] = subnet['name'] fixed_ip['cidr'] = subnet['cidr'] # NOTE(gongysh) fill in network name netid_port_dict = {} for port in ports['ports']: netports = netid_port_dict.get(port['network_id'], []) netports.append(port) netid_port_dict[port['network_id']] = netports netids = netid_port_dict.keys() nets = plugin.get_networks(context, filters={'id': netids}) for net in nets: for netport in netid_port_dict[net['id']]: netport['network_name'] = net['name'] router.update(ports) return router
def setUp(self): super(RequestTestCase, self).setUp() self.req = wsgi_resource.Request({'foo': 'bar'})