From: gongysh Date: Wed, 20 Mar 2013 01:22:52 +0000 (+0800) Subject: refactor _get_sync_routers to use get_routers. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6bc72e683862741192ab480133f2a1d88020e179;p=openstack-build%2Fneutron-build.git refactor _get_sync_routers to use get_routers. By using get_routers, get_sync_data() can get all attributes including attributes provided by extensions which extend router ext. Change-Id: I4be761dadd18eed19f4e54676e77d99bcc4a4745 --- diff --git a/quantum/db/extraroute_db.py b/quantum/db/extraroute_db.py index 82425278d..45854ad22 100644 --- a/quantum/db/extraroute_db.py +++ b/quantum/db/extraroute_db.py @@ -154,17 +154,6 @@ class ExtraRoute_db_mixin(l3_db.L3_NAT_db_mixin): context, router['id']) return routers - def get_sync_data(self, context, router_ids=None, active=None): - """Query routers and their related floating_ips, interfaces.""" - with context.session.begin(subtransactions=True): - routers = super(ExtraRoute_db_mixin, - self).get_sync_data(context, router_ids, - active=active) - for router in routers: - router['routes'] = self._get_extra_routes_by_router_id( - context, router['id']) - return routers - def _confirm_router_interface_not_in_use(self, context, router_id, subnet_id): super(ExtraRoute_db_mixin, self)._confirm_router_interface_not_in_use( diff --git a/quantum/db/l3_db.py b/quantum/db/l3_db.py index 48e202f57..b428fa581 100644 --- a/quantum/db/l3_db.py +++ b/quantum/db/l3_db.py @@ -126,7 +126,8 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): 'tenant_id': router['tenant_id'], 'admin_state_up': router['admin_state_up'], 'status': router['status'], - 'external_gateway_info': None} + 'external_gateway_info': None, + 'gw_port_id': router['gw_port_id']} if router['gw_port_id']: nw_id = router.gw_port['network_id'] res['external_gateway_info'] = {'network_id': nw_id} @@ -846,20 +847,15 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): if it is None, all of routers will be queried. @return: a list of dicted routers with dicted gw_port populated if any """ - router_query = context.session.query(Router) - if router_ids: - if 1 == len(router_ids): - router_query = router_query.filter(Router.id == router_ids[0]) - else: - router_query = router_query.filter(Router.id.in_(router_ids)) + filters = {'id': router_ids} if router_ids else {} if active is not None: - router_query = router_query.filter(Router.admin_state_up == active) - routers = router_query.all() + filters['admin_state_up'] = [active] + router_dicts = self.get_routers(context, filters=filters) gw_port_ids = [] - if not routers: + if not router_dicts: return [] - for router in routers: - gw_port_id = router.gw_port_id + for router_dict in router_dicts: + gw_port_id = router_dict['gw_port_id'] if gw_port_id: gw_port_ids.append(gw_port_id) gw_ports = [] @@ -868,15 +864,11 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): gw_port_id_gw_port_dict = {} for gw_port in gw_ports: gw_port_id_gw_port_dict[gw_port['id']] = gw_port - router_id_gw_port_id_dict = {} - for router in routers: - router_id_gw_port_id_dict[router.id] = router.gw_port_id - routers_list = [self._make_router_dict(c, None) for c in routers] - for router in routers_list: - gw_port_id = router_id_gw_port_id_dict[router['id']] + for router_dict in router_dicts: + gw_port_id = router_dict['gw_port_id'] if gw_port_id: - router['gw_port'] = gw_port_id_gw_port_dict[gw_port_id] - return routers_list + router_dict['gw_port'] = gw_port_id_gw_port_dict[gw_port_id] + return router_dicts def _get_sync_floating_ips(self, context, router_ids): """Query floating_ips that relate to list of router_ids."""