Merge "refactor _get_sync_routers to use get_routers."
This commit is contained in:
@@ -154,17 +154,6 @@ class ExtraRoute_db_mixin(l3_db.L3_NAT_db_mixin):
|
|||||||
context, router['id'])
|
context, router['id'])
|
||||||
return routers
|
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,
|
def _confirm_router_interface_not_in_use(self, context, router_id,
|
||||||
subnet_id):
|
subnet_id):
|
||||||
super(ExtraRoute_db_mixin, self)._confirm_router_interface_not_in_use(
|
super(ExtraRoute_db_mixin, self)._confirm_router_interface_not_in_use(
|
||||||
|
@@ -126,7 +126,8 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
|
|||||||
'tenant_id': router['tenant_id'],
|
'tenant_id': router['tenant_id'],
|
||||||
'admin_state_up': router['admin_state_up'],
|
'admin_state_up': router['admin_state_up'],
|
||||||
'status': router['status'],
|
'status': router['status'],
|
||||||
'external_gateway_info': None}
|
'external_gateway_info': None,
|
||||||
|
'gw_port_id': router['gw_port_id']}
|
||||||
if router['gw_port_id']:
|
if router['gw_port_id']:
|
||||||
nw_id = router.gw_port['network_id']
|
nw_id = router.gw_port['network_id']
|
||||||
res['external_gateway_info'] = {'network_id': nw_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.
|
if it is None, all of routers will be queried.
|
||||||
@return: a list of dicted routers with dicted gw_port populated if any
|
@return: a list of dicted routers with dicted gw_port populated if any
|
||||||
"""
|
"""
|
||||||
router_query = context.session.query(Router)
|
filters = {'id': router_ids} if router_ids else {}
|
||||||
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))
|
|
||||||
if active is not None:
|
if active is not None:
|
||||||
router_query = router_query.filter(Router.admin_state_up == active)
|
filters['admin_state_up'] = [active]
|
||||||
routers = router_query.all()
|
router_dicts = self.get_routers(context, filters=filters)
|
||||||
gw_port_ids = []
|
gw_port_ids = []
|
||||||
if not routers:
|
if not router_dicts:
|
||||||
return []
|
return []
|
||||||
for router in routers:
|
for router_dict in router_dicts:
|
||||||
gw_port_id = router.gw_port_id
|
gw_port_id = router_dict['gw_port_id']
|
||||||
if gw_port_id:
|
if gw_port_id:
|
||||||
gw_port_ids.append(gw_port_id)
|
gw_port_ids.append(gw_port_id)
|
||||||
gw_ports = []
|
gw_ports = []
|
||||||
@@ -868,15 +864,11 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
|
|||||||
gw_port_id_gw_port_dict = {}
|
gw_port_id_gw_port_dict = {}
|
||||||
for gw_port in gw_ports:
|
for gw_port in gw_ports:
|
||||||
gw_port_id_gw_port_dict[gw_port['id']] = gw_port
|
gw_port_id_gw_port_dict[gw_port['id']] = gw_port
|
||||||
router_id_gw_port_id_dict = {}
|
for router_dict in router_dicts:
|
||||||
for router in routers:
|
gw_port_id = router_dict['gw_port_id']
|
||||||
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']]
|
|
||||||
if gw_port_id:
|
if gw_port_id:
|
||||||
router['gw_port'] = gw_port_id_gw_port_dict[gw_port_id]
|
router_dict['gw_port'] = gw_port_id_gw_port_dict[gw_port_id]
|
||||||
return routers_list
|
return router_dicts
|
||||||
|
|
||||||
def _get_sync_floating_ips(self, context, router_ids):
|
def _get_sync_floating_ips(self, context, router_ids):
|
||||||
"""Query floating_ips that relate to list of router_ids."""
|
"""Query floating_ips that relate to list of router_ids."""
|
||||||
|
Reference in New Issue
Block a user