def _create_global_router(self, context, hosting_device_id, hd_to_gr_dict,
                           tenant_router, logical_global_router):
     r_spec = {
         'router': {
             # global routers are not tied to any tenant
             'tenant_id': '',
             'name': self._global_router_name(hosting_device_id),
             'admin_state_up': True
         }
     }
     global_router, r_hd_b_db = self._l3_plugin.do_create_router(
         context, r_spec, tenant_router[routertype.TYPE_ATTR], False, True,
         hosting_device_id, ROUTER_ROLE_GLOBAL)
     # make the global router a redundancy router for the logical
     # global router (which we treat as a hidden "user visible
     # router" (how's that for a contradiction of terms! :-) )
     with context.session.begin(subtransactions=True):
         ha_priority = (ha_db.DEFAULT_MASTER_PRIORITY -
                        len(hd_to_gr_dict) * ha_db.PRIORITY_INCREASE_STEP)
         r_b_b = ha_db.RouterRedundancyBinding(
             redundancy_router_id=global_router['id'],
             priority=ha_priority,
             user_router_id=logical_global_router['id'])
         context.session.add(r_b_b)
     return global_router
 def _conditionally_add_global_router(self, context, router):
     # We could filter on hosting device id but we don't so we get all
     # global routers for this router type. We can then use that count to
     # determine which ha priority a new global router should get.
     filters = {
         routerrole.ROUTER_ROLE_ATTR: [ROUTER_ROLE_GLOBAL],
         routertype.TYPE_ATTR: [router[routertype.TYPE_ATTR]]
     }
     global_routers = {
         r[HOSTING_DEVICE_ATTR]: r
         for r in self._l3_plugin.get_routers(
             context, filters=filters, fields=[HOSTING_DEVICE_ATTR])
     }
     hosting_device_id = router[HOSTING_DEVICE_ATTR]
     if hosting_device_id not in global_routers:
         # must create global router on hosting device
         # all global routers are connected to the external network
         ext_nw = router[l3.EXTERNAL_GW_INFO]['network_id']
         r_spec = {
             'router': {
                 # global routers are not tied to any tenant
                 'tenant_id': '',
                 'name': self._global_router_name(hosting_device_id),
                 'admin_state_up': True,
                 l3.EXTERNAL_GW_INFO: {
                     'network_id': ext_nw
                 }
             }
         }
         with context.session.begin(subtransactions=True):
             global_router, r_hd_b_db = self._l3_plugin.do_create_router(
                 context, r_spec, router[routertype.TYPE_ATTR], False, True,
                 hosting_device_id, ROUTER_ROLE_GLOBAL)
             log_global_router = (
                 self._conditionally_add_logical_global_router(
                     context, router))
             # make the global router a redundancy router for the logical
             # global router (which we treat as a hidden "user visible
             # router" (how's that for a contradiction! :-) )
             ha_priority = (
                 ha_db.DEFAULT_MASTER_PRIORITY +
                 len(global_routers) * ha_db.PRIORITY_INCREASE_STEP)
             r_b_b = ha_db.RouterRedundancyBinding(
                 redundancy_router_id=global_router['id'],
                 priority=ha_priority,
                 user_router_id=log_global_router['id'])
         context.session.add(r_b_b)
         self._l3_plugin.add_type_and_hosting_device_info(
             context, global_router)
         for ni in self._l3_plugin.get_notifiers(context, [global_router]):
             if ni['notifier']:
                 ni['notifier'].routers_updated(context, ni['routers'])