Ejemplo n.º 1
0
 def _get_vpp_router(self, context, router_id):
     try:
         router = self._get_by_id(context, Router, router_id)
     except Exception:
         raise n_exc.BadRequest("L3 Router not found for router_id: %s",
                                router_id)
     return router
Ejemplo n.º 2
0
    def _get_router_interface(self, context, router_id, router_dict):

        """Populate the param: "router_dict" with values and return.

        SideEffect: Changes the parameter: router_dict
        Returns the router_dict populated with the network, subnet
        gateway ip_address, GPE locators for vxlan, network type,
        segmentation ID, is_ipv6, VRF and prefix-length information so
        vpp-agent can create the vpp router interface.

        Arguments:-
        1. router_dict: The router dictionary to be populated with data.
        It must contain the key "port_id", which is used to populate the
        router dict.
        2. router_id: Router ID

        """

        port_id = router_dict['port_id']
        port = self._core_plugin.get_port(context, port_id)
        network = self._core_plugin.get_network(context,
                                                port['network_id'])
        fixed_ips = [ip for ip in port['fixed_ips']]
        if not fixed_ips:
            n_exc.BadRequest('vpp-router-service: A router port must '
                             'have at least one fixed IP address')
        # TODO(najoy): Handle multiple fixed-ips on a router port
        fixed_ip = fixed_ips[0]
        subnet = self._core_plugin.get_subnet(context,
                                              fixed_ip['subnet_id'])
        router_dict['gateway_ip'] = fixed_ip['ip_address']
        router_dict['subnet_id'] = subnet['id']
        router_dict['fixed_ips'] = fixed_ips

        address = ip_network(subnet['cidr'])
        router_dict['network_id'] = network['id']
        router_dict['is_ipv6'] = True if address.version == 6 else False
        router_dict['prefixlen'] = address.prefixlen
        router_dict['mtu'] = network['mtu']
        router_dict['segmentation_id'] = network[provider.SEGMENTATION_ID]
        router_dict['net_type'] = network[provider.NETWORK_TYPE]
        if router_dict['net_type'] == 'vxlan':
            router_dict['physnet'] = self.gpe_physnet
        else:
            router_dict['physnet'] = network[provider.PHYSICAL_NETWORK]
        # Get VRF corresponding to the router
        vrf_id = db.get_router_vrf(context.session, router_id)
        router_dict['vrf_id'] = vrf_id
        return router_dict