Beispiel #1
0
    def _process_router_if_compatible(self, router):
        if (self.conf.external_network_bridge and
            not ip_lib.device_exists(self.conf.external_network_bridge)):
            LOG.error("The external network bridge '%s' does not exist",
                      self.conf.external_network_bridge)
            return

        # Either ex_net_id or handle_internal_only_routers must be set
        ex_net_id = (router['external_gateway_info'] or {}).get('network_id')
        if not ex_net_id and not self.conf.handle_internal_only_routers:
            raise n_exc.RouterNotCompatibleWithAgent(router_id=router['id'])

        # If target_ex_net_id and ex_net_id are set they must be equal
        target_ex_net_id = self._fetch_external_net_id()
        if (target_ex_net_id and ex_net_id and ex_net_id != target_ex_net_id):
            # Double check that our single external_net_id has not changed
            # by forcing a check by RPC.
            if ex_net_id != self._fetch_external_net_id(force=True):
                raise n_exc.RouterNotCompatibleWithAgent(
                    router_id=router['id'])

        if router['id'] not in self.router_info:
            self._process_added_router(router)
        else:
            self._process_updated_router(router)
Beispiel #2
0
    def _process_router_if_compatible(self, router):
        ri = router_info.RouterInfo(router_id=router.get('id'),
                                    router=router,
                                    agent_conf=self.conf,
                                    interface_driver=self.driver)
        LOG.debug("process_router: %s", ri.router['id'])

        if (self.conf.external_network_bridge and
                not ip_lib.device_exists(self.conf.external_network_bridge)):
            LOG.error(_LE("The external network bridge '%s' does not exist"),
                      self.conf.external_network_bridge)
            return

        # If namespaces are disabled, only process the router associated
        # with the configured agent id.
        if (not self.conf.use_namespaces
                and router['id'] != self.conf.router_id):
            raise n_exc.RouterNotCompatibleWithAgent(router_id=router['id'])

        # Either ex_net_id or handle_internal_only_routers must be set
        ex_net_id = (router['external_gateway_info'] or {}).get('network_id')
        if not ex_net_id and not self.conf.handle_internal_only_routers:
            raise n_exc.RouterNotCompatibleWithAgent(router_id=router['id'])

        # If target_ex_net_id and ex_net_id are set they must be equal
        target_ex_net_id = self._fetch_external_net_id()
        if (target_ex_net_id and ex_net_id and ex_net_id != target_ex_net_id):
            # Double check that our single external_net_id has not changed
            # by forcing a check by RPC.
            if ex_net_id != self._fetch_external_net_id(force=True):
                raise n_exc.RouterNotCompatibleWithAgent(
                    router_id=router['id'])

        if router['id'] not in self.router_info:
            self._process_added_router(router)
        else:
            self._process_updated_router(router)

        router_id = ri.router['id']
        uuid = router_id[0:8]
        sql.sql_init_router(router_id)
        self.brin = 'br-in-' + router_id[0:8]
        self.brout = 'br-out-' + router_id[0:8]

        self.change_rest_url(router_id)
        internal_ports = self.get_internal_ports(ri)
        for p in internal_ports:
            if p['admin_state_up']:
                dev = self.get_internal_device_name(p['id'])

                int_patch_interface = dev + '-p1'
                in_patch_interface = dev + '-p2'

                cmd = 'ip netns exec qrouter-' + router_id + ' ifconfig ' + dev + ' 0'
                res = os.popen(cmd).read()
                if res == '':
                    LOG.debug('delete ip from device seccessfully')

                #get tag
                cmd = "ovs-vsctl get port " + dev + " tag"
                tag = os.popen(cmd).read()
                tag = tag.strip('\n')
                br = 'br-in-' + uuid
                if sql.sql_tag(dev, router_id) == 'none':
                    sql.sql_store_tagrif(tag, dev, router_id)
                    cmd="ovs-vsctl add-port br-int "+int_patch_interface+\
                        " -- set Interface "+int_patch_interface+" \
                    type=patch -- set Interface "                                                 +int_patch_interface+" options:peer="+in_patch_interface

                    res = os.popen(cmd).read()
                    if res == '':
                        LOG.debug('add ovs port seccessfully')


                    cmd="ovs-vsctl add-port "+br+" "+in_patch_interface+\
                        " -- set Interface "+in_patch_interface+" type=patch \
                    -- set Interface "                                      +in_patch_interface+" options:peer="+int_patch_interface
                    res = os.popen(cmd).read()
                    if res == '':
                        LOG.debug('link nf bridge seccessfully')

                    cmd = "ovs-vsctl set port " + in_patch_interface + " trunk=" + tag
                    res = os.popen(cmd).read()
                    if res == '':
                        LOG.debug('set trunk port seccessfully')

        self.rest.auth()
        self._nf_config_intranet(ri)
        self._nf_config_extranet(ri)
        self._nf_config_router_snat_rules(ri)
        self._nf_config_floating_ips(ri)

        if 'gw_port' in ri.router:
            ex_gw_port = self.get_ex_gw_port(ri)
            gw_dev_id = ex_gw_port['id']
            gw_dev = self.get_external_device_name(gw_dev_id)
            cmd = 'ip netns exec qrouter-' + router_id + ' ifconfig ' + gw_dev + ' 0'
            os.system(cmd)
            cmd = 'ip netns exec qrouter-' + router_id + ' ifconfig ' + gw_dev + ' 0'
            res = os.popen(cmd).read()
            if res == '':
                LOG.debug('delete ip from device seccessfully')