Ejemplo n.º 1
0
    def remove_router_interface(self, context, router_id, interface_info):
        """Remove a subnet of a network from an existing router."""

        new_router = (super(AristaL3ServicePlugin,
                            self).remove_router_interface(
                                context, router_id, interface_info))

        # Get network information of the subnet that is being removed
        subnet = self.get_subnet(context, new_router['subnet_id'])
        network_id = subnet['network_id']

        # For SVI removal from Arista HW, segmentation ID is needed
        ml2_db = NetworkContext(self, context, {'id': network_id})
        seg_id = ml2_db.network_segments[0]['segmentation_id']

        router = super(AristaL3ServicePlugin,
                       self).get_router(context, router_id)
        router_info = copy.deepcopy(new_router)
        router_info['seg_id'] = seg_id
        router_info['name'] = router['name']

        try:
            self.driver.remove_router_interface(context, router_info)
            return new_router
        except Exception as exc:
            LOG.error(
                _("Error removing interface %(interface)s from "
                  "router %(router_id)s on Arista HW"
                  "Exception =(exc)s") % {
                      'interface': interface_info,
                      'router_id': router_id,
                      'exc': exc
                  })
Ejemplo n.º 2
0
    def add_router_interface(self, context, router_id, interface_info):
        """Add a subnet of a network to an existing router."""

        new_router = super(AristaL3ServicePlugin,
                           self).add_router_interface(context, router_id,
                                                      interface_info)

        # Get network info for the subnet that is being added to the router.
        # Check if the interface information is by port-id or subnet-id
        add_by_port, add_by_sub = self._validate_interface_info(interface_info)
        if add_by_sub:
            subnet = self.get_subnet(context, interface_info['subnet_id'])
        elif add_by_port:
            port = self.get_port(context, interface_info['port_id'])
            subnet_id = port['fixed_ips'][0]['subnet_id']
            subnet = self.get_subnet(context, subnet_id)
        network_id = subnet['network_id']

        # To create SVI's in Arista HW, the segmentation Id is required
        # for this network.
        ml2_db = NetworkContext(self, context, {'id': network_id})
        seg_id = ml2_db.network_segments[0]['segmentation_id']

        # Package all the info needed for Hw programming
        router = super(AristaL3ServicePlugin,
                       self).get_router(context, router_id)
        router_info = copy.deepcopy(new_router)
        router_info['seg_id'] = seg_id
        router_info['name'] = router['name']
        router_info['cidr'] = subnet['cidr']
        router_info['gip'] = subnet['gateway_ip']
        router_info['ip_version'] = subnet['ip_version']

        try:
            self.driver.add_router_interface(context, router_info)
            return new_router
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error Adding subnet %(subnet)s to "
                      "router %(router_id)s on Arista HW") % {
                          'subnet': subnet,
                          'router_id': router_id
                      })
                super(AristaL3ServicePlugin,
                      self).remove_router_interface(context, router_id,
                                                    interface_info)
Ejemplo n.º 3
0
    def synchronize(self):
        """Synchronizes Router DB from Neturon DB with EOS.

        Walks through the Neturon Db and ensures that all the routers
        created in Netuton DB match with EOS. After creating appropriate
        routers, it ensures to add interfaces as well.
        Uses idempotent properties of EOS configuration, which means
        same commands can be repeated.
        """
        LOG.info(_('Syncing Neutron Router DB <-> EOS'))
        ctx = nctx.get_admin_context()

        routers = super(AristaL3ServicePlugin, self).get_routers(ctx)
        for r in routers:
            tenant_id = r['tenant_id']
            ports = self.ndb.get_all_ports_for_tenant(tenant_id)

            try:
                self.driver.create_router(self, tenant_id, r)

            except Exception:
                continue

            # Figure out which interfaces are added to this router
            for p in ports:
                if p['device_id'] == r['id']:
                    net_id = p['network_id']
                    subnet_id = p['fixed_ips'][0]['subnet_id']
                    subnet = self.ndb.get_subnet_info(subnet_id)
                    ml2_db = NetworkContext(self, ctx, {'id': net_id})
                    seg_id = ml2_db.network_segments[0]['segmentation_id']

                    r['seg_id'] = seg_id
                    r['cidr'] = subnet['cidr']
                    r['gip'] = subnet['gateway_ip']
                    r['ip_version'] = subnet['ip_version']

                    try:
                        self.driver.add_router_interface(self, r)
                    except Exception:
                        LOG.error(
                            _("Error Adding interface %(subnet_id)s to "
                              "router %(router_id)s on Arista HW") % {
                                  'subnet_id': subnet_id,
                                  'router_id': r
                              })
    def create_vxnet(self,
                     vxnet_id,
                     vni,
                     ip_network,
                     gateway_ip,
                     user_id,
                     network_type=NETWORK_TYPE_VXLAN,
                     enable_dhcp=False):
        '''
        vxnet is a network with only one subnet
        '''

        network = {
            "tenant_id": user_id,
            "id": vxnet_id,
            "name": vxnet_id,
            'provider:network_type': network_type
        }
        # for subinterface case, network type is "local" and don't specify vni
        if vni:
            network['provider:segmentation_id'] = vni

        network_context = NetworkContext(network,
                                         plugin_context=PluginContext(user_id))

        self.ml2.create_network_precommit(network_context)
        self.ml2.create_network_postcommit(network_context)

        subnet_id = vxnet_id
        subnet = {
            "tenant_id": user_id,
            "id": subnet_id,
            "name": subnet_id,
            'network_id': vxnet_id,
            'gateway_ip': gateway_ip,
            'cidr': ip_network,
            'enable_dhcp': enable_dhcp
        }

        subnet_context = SubnetContext(subnet,
                                       network,
                                       plugin_context=PluginContext(user_id))
        self.ml2.create_subnet_precommit(subnet_context)
        self.ml2.create_subnet_postcommit(subnet_context)
Ejemplo n.º 5
0
    def _get_network_info(self, context, subnet):
        """
        Gets the network info from the context and brocade db

        :param:context: Contains the network details
        :param:subnet: Contains the subnet details
        :returns:vlan_id - VLAN ID of the network
        :returns:gateway_ip_cidr - Gateway IP address with network length.
            Example: 1.1.1.1/24
        """
        cidr = subnet["cidr"]
        net_addr, net_len = self.net_addr(cidr)
        gateway_ip = subnet["gateway_ip"]
        network_id = subnet['network_id']
        ml2_db = NetworkContext(self, context, {'id': network_id})
        vlan_id = ml2_db.network_segments[0]['segmentation_id']
        gateway_ip_cidr = gateway_ip + '/' + str(net_len)

        return vlan_id, gateway_ip_cidr
    def delete_vxnet(self, vxnet_id, user_id):

        network = {"tenant_id": user_id, "id": vxnet_id, "name": vxnet_id}

        network_context = NetworkContext(network)

        subnet_id = vxnet_id
        subnet = {
            "tenant_id": user_id,
            "id": subnet_id,
            "name": subnet_id,
            'network_id': vxnet_id
        }

        subnet_context = SubnetContext(subnet, network)

        self.ml2.delete_subnet_precommit(subnet_context)
        self.ml2.delete_subnet_postcommit(subnet_context)

        self.ml2.delete_network_precommit(network_context)
        self.ml2.delete_network_postcommit(network_context)