Exemplo n.º 1
0
    def create_router(self, context, router):
        is_ha = self._is_ha(router['router'])

        if is_ha and l3_dvr_db.is_distributed_router(router['router']):
            raise l3_ha.DistributedHARouterNotSupported()

        router['router']['ha'] = is_ha
        router_dict = super(L3_HA_NAT_db_mixin,
                            self).create_router(context, router)

        if is_ha:
            try:
                router_db = self._get_router(context, router_dict['id'])
                ha_network = self.get_ha_network(context,
                                                 router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(context,
                                                         router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_dict['id'])
            router_dict['ha_vr_id'] = router_db.extra_attributes.ha_vr_id
        return router_dict
Exemplo n.º 2
0
    def _create_router_db(self, context, router, tenant_id):
        router['ha'] = self._is_ha(router)

        if router['ha'] and l3_dvr_db.is_distributed_router(router):
            raise l3_ha.DistributedHARouterNotSupported()

        with context.session.begin(subtransactions=True):
            router_db = super(L3_HA_NAT_db_mixin, self)._create_router_db(
                context, router, tenant_id)

        if router['ha']:
            try:
                ha_network = self.get_ha_network(context,
                                                 router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(context,
                                                         router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_db.id)

        return router_db
Exemplo n.º 3
0
    def create_router(self, context, router):
        is_ha = self._is_ha(router['router'])

        if is_ha and l3_dvr_db.is_distributed_router(router['router']):
            raise l3_ha.DistributedHARouterNotSupported()

        router['router']['ha'] = is_ha
        router_dict = super(L3_HA_NAT_db_mixin,
                            self).create_router(context, router)

        if is_ha:
            try:
                router_db = self._get_router(context, router_dict['id'])
                ha_network = self.get_ha_network(context, router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(
                        context, router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_dict['id'])
            router_dict['ha_vr_id'] = router_db.extra_attributes.ha_vr_id
        return router_dict
Exemplo n.º 4
0
    def _create_router_db(self, context, router, tenant_id):
        router['ha'] = self._is_ha(router)

        if router['ha'] and l3_dvr_db.is_distributed_router(router):
            raise l3_ha.DistributedHARouterNotSupported()

        with context.session.begin(subtransactions=True):
            router_db = super(L3_HA_NAT_db_mixin,
                              self)._create_router_db(context, router,
                                                      tenant_id)

        if router['ha']:
            try:
                ha_network = self.get_ha_network(context, router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(
                        context, router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_db.id)

        return router_db
    def create_router(self, context, router):
        is_ha = self._is_ha(router['router'])

        if is_ha and l3_dvr_db.is_distributed_router(router['router']):
            raise l3_ha.DistributedHARouterNotSupported()

        router['router']['ha'] = is_ha
        router_dict = super(L3_HA_NAT_db_mixin,
                            self).create_router(context, router)

        if is_ha:
            if cfg.CONF.mulity_ha_network_one_tenant:
                router_db = self._get_router(context, router_dict['id'])
                ha_network_list = self.get_ha_network_list(context, router_db.tenant_id)
                if not ha_network_list:
                    ha_network_list = [self._create_ha_network(context,
                                                         router_db.tenant_id)]
                def get_vr_id():
                    flag = 1
                    for ha_network in ha_network_list:
                        try:
                            self._set_vr_id(context, router_db, ha_network)
                            flag = 0
                            LOG.debug("get the vr_id from  ha network %s" %ha_network.network['id'])
                            break
                        except l3_ha.NoVRIDAvailable:
                            LOG.debug("the ha network %s vr_id is over " %ha_network.network['id'])

                    if flag:
                        LOG.debug("create new ha network")
                        ha_network = self._create_ha_network(context,
                                                         router_db.tenant_id)
                        self._set_vr_id(context, router_db, ha_network)
                    self._create_router_ha_network_info(context, router_db.id, ha_network.network['id'])
                    self._create_ha_interfaces(context, router_db, ha_network)
                    self._notify_ha_interfaces_updated(context, router_db.id)
                    router_dict['ha_vr_id'] = router_db.extra_attributes.ha_vr_id
                try:
                    get_vr_id()
                except Exception:
                     with excutils.save_and_reraise_exception():
                        self.delete_router(context, router_dict['id'])
            else:
                try:
                    router_db = self._get_router(context, router_dict['id'])
                    ha_network = self.get_ha_network(context,
                                                 router_db.tenant_id)
                    if not ha_network:
                        ha_network = self._create_ha_network(context,
                                                         router_db.tenant_id)

                    self._set_vr_id(context, router_db, ha_network)
                    self._create_ha_interfaces(context, router_db, ha_network)
                    self._notify_ha_interfaces_updated(context, router_db.id)
                except Exception:
                    with excutils.save_and_reraise_exception():
                        self.delete_router(context, router_dict['id'])
                router_dict['ha_vr_id'] = router_db.extra_attributes.ha_vr_id
        return router_dict
Exemplo n.º 6
0
 def _get_device_owner(self, context, router=None):
     """Get device_owner for the specified router."""
     router_is_uuid = isinstance(router, six.string_types)
     if router_is_uuid:
         router = self._get_router(context, router)
     if is_ha_router(router) and not is_distributed_router(router):
         return constants.DEVICE_OWNER_HA_REPLICATED_INT
     return super(L3_HA_NAT_db_mixin,
                  self)._get_device_owner(context, router)
Exemplo n.º 7
0
 def _get_device_owner(self, context, router=None):
     """Get device_owner for the specified router."""
     router_is_uuid = isinstance(router, six.string_types)
     if router_is_uuid:
         router = self._get_router(context, router)
     if is_ha_router(router) and not is_distributed_router(router):
         return constants.DEVICE_OWNER_HA_REPLICATED_INT
     return super(L3_HA_NAT_db_mixin,
                  self)._get_device_owner(context, router)
Exemplo n.º 8
0
 def _should_notify_on_fip_update():
     if not fip:
         return False
     for info in removed_routers:
         if info['router_id'] == fip['router_id']:
             return False
     try:
         router = l3plugin._get_router(context, fip['router_id'])
     except l3_exc.RouterNotFound:
         return False
     return l3_dvr_db.is_distributed_router(router)
Exemplo n.º 9
0
 def _should_notify_on_fip_update():
     if not fip:
         return False
     for info in removed_routers:
         if info['router_id'] == fip['router_id']:
             return False
     try:
         router = l3plugin._get_router(context, fip['router_id'])
     except l3_exc.RouterNotFound:
         return False
     return l3_dvr_db.is_distributed_router(router)
Exemplo n.º 10
0
    def _make_router_dict(self, router):
        distributed = l3_dvr_db.is_distributed_router(router)
        res = {'id': router['id'],
               'name': router['name'],
               'tenant_id': router['tenant_id'],
               'admin_state_up': router['admin_state_up'],
               'status': router['status'],
               'gw_port_id': router['gw_port_id'],
               'distributed': distributed,
               constants.METERING_LABEL_KEY: []}

        return res
Exemplo n.º 11
0
    def _make_router_dict(self, router):
        distributed = l3_dvr_db.is_distributed_router(router)
        res = {
            'id': router['id'],
            'name': router['name'],
            'tenant_id': router['tenant_id'],
            'admin_state_up': router['admin_state_up'],
            'status': router['status'],
            'gw_port_id': router['gw_port_id'],
            'distributed': distributed,
            constants.METERING_LABEL_KEY: []
        }

        return res
Exemplo n.º 12
0
    def _check_port_has_port_forwarding(self, resource, event,
                                        trigger, payload=None):
        port_id = payload.request_body['floatingip'].get('port_id')
        if not port_id:
            return

        pf_objs = pf.PortForwarding.get_objects(
            payload.context, internal_port_id=port_id)
        if not pf_objs:
            return
        # Port may not bind to host yet, or port may migrate from one
        # dvr_no_external host to one dvr host. So we just do not allow
        # all dvr router's floating IP to be binded to a port which
        # already has port forwarding.
        router = self.l3_plugin.get_router(payload.context.elevated(),
                                           pf_objs[0].router_id)
        if l3_dvr_db.is_distributed_router(router):
            raise pf_exc.PortHasPortForwarding(port_id=port_id)
Exemplo n.º 13
0
 def _test__is_distributed_router(self, router, expected):
     result = l3_dvr_db.is_distributed_router(router)
     self.assertEqual(expected, result)
Exemplo n.º 14
0
 def _test__is_distributed_router(self, router, expected):
     result = l3_dvr_db.is_distributed_router(router)
     self.assertEqual(expected, result)
Exemplo n.º 15
0
    def dvr_handle_new_service_port(self,
                                    context,
                                    port,
                                    dest_host=None,
                                    unbound_migrate=False,
                                    router_id=None):
        """Handle new dvr service port creation.

        When a new dvr service port is created, this function will
        schedule a dvr router to new compute node if needed and notify
        l3 agent on that node.
        The 'dest_host' will provide the destination host of the port in
        case of service port migration.
        If an unbound port migrates and becomes a bound port, send
        notification to the snat_agents and to the bound host.
        """
        port_host = dest_host or port[portbindings.HOST_ID]
        l3_agent_on_host = (self.get_l3_agents(context,
                                               filters={'host': [port_host]})
                            or [None])[0]
        if not l3_agent_on_host:
            return

        if dest_host and router_id is not None:
            # Make sure we create the floatingip agent gateway port
            # for the destination node if fip is associated with this
            # fixed port
            l3plugin = directory.get_plugin(plugin_constants.L3)
            router = l3plugin._get_router(context, router_id)
            if l3_dvr_db.is_distributed_router(router):
                (l3plugin.
                 check_for_fip_and_create_agent_gw_port_on_host_if_not_exists(
                     context, port, dest_host))
            else:
                LOG.debug(
                    "Port-in-Migration: Floating IP has a non-"
                    "distributed router %(router_id)s",
                    {'router_id': router_id})

        subnet_ids = [ip['subnet_id'] for ip in port['fixed_ips']]
        router_ids = self.get_dvr_routers_by_subnet_ids(context, subnet_ids)
        if not router_ids:
            return
        agent_port_host_match = False
        if unbound_migrate:
            # This might be a case were it is migrating from unbound
            # to a bound port.
            # In that case please forward the notification to the
            # snat_nodes hosting the routers.
            # Make a call here to notify the snat nodes.
            snat_agent_list = self.get_dvr_snat_agent_list(context)
            for agent in snat_agent_list:
                LOG.debug(
                    'DVR: Handle new unbound migration port, '
                    'host %(host)s, router_ids %(router_ids)s', {
                        'host': agent.host,
                        'router_ids': router_ids
                    })
                self.l3_rpc_notifier.routers_updated_on_host(
                    context, router_ids, agent.host)
                if agent.host == port_host:
                    agent_port_host_match = True
        if not agent_port_host_match:
            connected_router_ids = set(router_ids)
            for router_id in router_ids:
                connected_router_ids.update(
                    self._get_other_dvr_router_ids_connected_router(
                        context, router_id))

            LOG.debug(
                'DVR: Handle new service port, host %(host)s, '
                'router ids %(router_ids)s', {
                    'host': port_host,
                    'router_ids': connected_router_ids
                })
            self.l3_rpc_notifier.routers_updated_on_host(
                context, connected_router_ids, port_host)