Exemplo n.º 1
0
    def create_network_postcommit(self, mech_context):
        """Create Network on the switch."""

        LOG.debug("create_network_postcommit: called")

        if self.is_flat_network(mech_context.network_segments[0]):
            return

        network = mech_context.current
        # use network_id to get the network attributes
        # ONLY depend on our db for getting back network attributes
        # this is so we can replay postcommit from db
        context = mech_context._plugin_context

        network_id = network['id']
        network = brocade_db.get_network(context, network_id)
        network['network_type']
        network['tenant_id']
        vlan_id = network['vlan']
        segments = mech_context.network_segments
        # currently supports only one segment per network
        segment = segments[0]
        physical_network = segment['physical_network']

        try:
            self._driver.create_network(self._device_dict, physical_network,
                                        vlan_id)
        except Exception:
            LOG.exception(_LE("Brocade NOS driver: failed in create network"))
            brocade_db.delete_network(context, network_id)
            raise Exception(
                _("Brocade Mechanism: create_network_postcommmit failed"))
    def create_port_precommit(self, mech_context):
        """Create logical port on the switch (db update)."""

        LOG.debug("create_port_precommit: called")
        if self.is_flat_network(mech_context.network.network_segments[0]):
            return

        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']
        admin_state_up = port['admin_state_up']

        context = mech_context._plugin_context

        network = brocade_db.get_network(context, network_id)
        vlan_id = network['vlan']

        try:
            brocade_db.create_port(context, port_id, network_id,
                                   None,
                                   vlan_id, tenant_id, admin_state_up,
                                   None)
        except Exception:
            LOG.exception(_LE("Brocade Mechanism: failed to create port"
                              " in db"))
            raise Exception(
                _("Brocade Mechanism: create_port_precommit failed"))
Exemplo n.º 3
0
    def create_subnet_postcommit(self, mech_context):
        """Noop now, it is left here for future."""
        LOG.debug("create_subnet_postcommit: called")
        network = mech_context.network._network
        subnet = mech_context.current
        vlan_id = brocade_db.get_network(mech_context._plugin_context,
                                         subnet['network_id'])['vlan']

        required_seqs = self.get_project_access_list_seqs(subnet['project_id'])
        
        if self.tenants_acl_name:
            LOG.debug('refreshing acl, required_seqs: %s' % required_seqs)
            ret = self.fabric_driver.refresh_acl(self.tenants_acl_name, required_seqs)
            LOG.debug('refreshed acls, returned: %s' % ret)
        else
            LOG.debug('tenants_acl_name unset, skipping acl refresh')

        gateway_ip = subnet['gateway_ip']
        gateway_subnet = str(subnet['cidr']).split('/')[1]
        gateway_address= "%s/%s" % (gateway_ip, gateway_subnet)
        try:
            network_name = network['name']
            vrf_name = self.internal_vrf_name
            if '-pub-' in network_name:
                vrf_name = self.external_vrf_name
            self.fabric_driver.create_subnet(vlan_id, gateway_address)
        except Exception as ex:
            LOG.exception('Error creating subnet: %s' % repr(ex))
            raise ex
Exemplo n.º 4
0
    def create_port_precommit(self, mech_context):
        """Create logical port on the switch (db update)."""

        LOG.debug("create_port_precommit: called")
        if self.is_flat_network(mech_context.network.network_segments[0]):
            return

        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']
        admin_state_up = port['admin_state_up']

        context = mech_context._plugin_context

        network = brocade_db.get_network(context, network_id)
        vlan_id = network['vlan']

        try:
            brocade_db.create_port(context, port_id, network_id, None, vlan_id,
                                   tenant_id, admin_state_up, None)
        except Exception:
            LOG.exception(
                _LE("Brocade Mechanism: failed to create port"
                    " in db"))
            raise Exception(
                _("Brocade Mechanism: create_port_precommit failed"))
Exemplo n.º 5
0
    def remove_router_interface(self, context, router_id, interface_info):
        """Deletes svi from NOS device."""
        LOG.debug(
            "BrocadeSVIPlugin.remove_router_interface called: "
            "router_id=%(router_id)s "
            "interface_info=%(interface_info)r", {
                'router_id': router_id,
                'interface_info': interface_info
            })

        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin,
                         self).remove_router_interface(context, router_id,
                                                       interface_info)
            try:
                subnet = self._core_plugin._get_subnet(context,
                                                       info['subnet_id'])
                cidr = subnet['cidr']
                net_addr, net_len = self.net_addr(cidr)
                gateway_ip = subnet['gateway_ip']
                network_id = subnet['network_id']
                bnet = brocade_db.get_network(context, network_id)
                vlan_id = bnet['vlan']
                gateway_ip_cidr = gateway_ip + '/' + str(net_len)
                LOG.debug(
                    "remove_router_interface removed cidr %(cidr)s"
                    " from the pool,"
                    " network_id %(net_id)s bnet %(bnet)s"
                    " vlan %(vlan_id)d", {
                        'cidr': gateway_ip_cidr,
                        'net_id': network_id,
                        'bnet': bnet,
                        'vlan_id': int(vlan_id)
                    })
                switch = self._switch
                self._driver.delete_svi(switch['address'], switch['username'],
                                        switch['password'],
                                        switch['rbridge_id'], vlan_id,
                                        gateway_ip_cidr, str(router_id))
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error(
                        _LE("Fail remove of interface from brocade "
                            "router interface. info=%(info)s, "
                            "router_id=%(router_id)s"), {
                                "info": info,
                                "router_id": router_id
                            })
        return True
Exemplo n.º 6
0
 def delete_network_precommit(self, context):
     network = context.current
     provider_type = network['provider:network_type']
     brocade_network = brocade_db.get_network(context._plugin_context, network['id'])
     segmentation_id = brocade_network.vlan
     vrf_name = self.internal_vrf_name
     if '-pub-' in network['name']:
         vrf_name = self.external_vrf_name
     try:
         self.fabric_driver.delete_network(segmentation_id)
         brocade_db.delete_network(context._plugin_context, network['id'])
     except Exception as ex:
         LOG.exception("Error in create_network_postcommit.")
         raise ex
     return True
Exemplo n.º 7
0
    def remove_router_interface(self, context, router_id, interface_info):
        """Deletes svi from NOS device"""
        LOG.debug(
            "BrocadeSVIPlugin.remove_router_interface called: "
            "router_id=%(router_id)s "
            "interface_info=%(interface_info)r", {
                'router_id': router_id,
                'interface_info': interface_info
            })
        remove_by_port, remove_by_subnet = (self._validate_interface_info(
            interface_info, for_removal=True))
        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin,
                         self).remove_router_interface(context, router_id,
                                                       interface_info)

        try:
            subnet = self._core_plugin._get_subnet(context, info['subnet_id'])
            if self._svi['redundancy'] and remove_by_subnet:
                self._core_plugin.delete_port(context,
                                              info['port_id'],
                                              l3_port_check=False)
            cidr = subnet['cidr']
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet['gateway_ip']
            network_id = subnet['network_id']
            tenant_id = subnet['tenant_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug(
                "remove_router_interface removed cidr (%s)"
                "from the pool, network_id (%s) bnet (%s) vlan (%d) ",
                gateway_ip_cidr, network_id, bnet, int(vlan_id))
            brocade_db.delete_svi(context, router_id, tenant_id, vlan_id,
                                  gateway_ip, str(net_len))
            self._invoke_nos_driver_api("delete_svi", router_id, vlan_id,
                                        gateway_ip_cidr)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _LE("Failed to remove interface from brocade router"
                        "interface. info=%(info)s,"
                        " router_id=%(router_id)s"), {
                            "info": info,
                            "router_id": router_id
                        })
Exemplo n.º 8
0
    def create_port_postcommit(self, mech_context):
        """Associate the assigned MAC address to the portprofile."""

        LOG.debug("create_port_postcommit: called")
        if self.is_flat_network(mech_context.network.network_segments[0]):
            return

        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']

        context = mech_context._plugin_context

        network = brocade_db.get_network(context, network_id)
        if not network:
            LOG.info(_LI("network not populated nothing to be done"))
            return
        vlan_id = network['vlan']

        interface_mac = port['mac_address']

        # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx
        mac = self.mac_reformat_62to34(interface_mac)
        try:
            self._driver.associate_mac_to_network(self._switch['address'],
                                                  self._switch['username'],
                                                  self._switch['password'],
                                                  vlan_id, mac)
        except Exception:
            LOG.exception(
                _LE("Brocade NOS driver: failed to associate mac %s"),
                interface_mac)
            raise Exception(
                _("Brocade switch exception: create_port_postcommit failed"))

        LOG.info(
            _LI("created port (postcommit): port_id=%(port_id)s"
                " network_id=%(network_id)s tenant_id=%(tenant_id)s"), {
                    'port_id': port_id,
                    'network_id': network_id,
                    'tenant_id': tenant_id
                })
    def remove_router_interface(self, context, router_id, interface_info):
        """Deletes svi from NOS device."""
        LOG.debug("BrocadeSVIPlugin.remove_router_interface called: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})

        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin, self).remove_router_interface(
                context, router_id, interface_info)
            try:
                subnet = self._core_plugin._get_subnet(context,
                                                       info['subnet_id'])
                cidr = subnet['cidr']
                net_addr, net_len = self.net_addr(cidr)
                gateway_ip = subnet['gateway_ip']
                network_id = subnet['network_id']
                bnet = brocade_db.get_network(context, network_id)
                vlan_id = bnet['vlan']
                gateway_ip_cidr = gateway_ip + '/' + str(net_len)
                LOG.debug("remove_router_interface removed cidr %(cidr)s"
                          " from the pool,"
                          " network_id %(net_id)s bnet %(bnet)s"
                          " vlan %(vlan_id)d",
                          {'cidr': gateway_ip_cidr,
                           'net_id': network_id,
                           'bnet': bnet,
                           'vlan_id': int(vlan_id)})
                switch = self._switch
                self._driver.delete_svi(switch['address'],
                                        switch['username'],
                                        switch['password'],
                                        switch['rbridge_id'],
                                        vlan_id,
                                        gateway_ip_cidr,
                                        str(router_id))
            except Exception:
                with excutils.save_and_reraise_exception():
                    LOG.error(_LE("Fail remove of interface from brocade "
                                  "router interface. info=%(info)s, "
                                  "router_id=%(router_id)s"),
                              {"info": info, "router_id": router_id})
        return True
    def delete_port_postcommit(self, mech_context):
        """Dissociate MAC address from the portprofile."""

        LOG.debug("delete_port_postcommit: called")
        if self.is_flat_network(mech_context.network.network_segments[0]):
            return
        port = mech_context.current
        port_id = port['id']
        network_id = port['network_id']
        tenant_id = port['tenant_id']

        context = mech_context._plugin_context

        network = brocade_db.get_network(context, network_id)
        if not network:
            LOG.info(_LI("network not populated nothing to be done"))
            return
        vlan_id = network['vlan']

        interface_mac = port['mac_address']

        # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx
        mac = self.mac_reformat_62to34(interface_mac)
        try:
            self._driver.dissociate_mac_from_network(
                self._switch['address'],
                self._switch['username'],
                self._switch['password'],
                vlan_id,
                mac)
        except Exception:
            LOG.exception(
                _LE("Brocade NOS driver: failed to dissociate MAC %s"),
                interface_mac)
            raise Exception(
                _("Brocade switch exception, delete_port_postcommit failed"))

        LOG.info(
            _LI("delete port (postcommit): port_id=%(port_id)s"
                " network_id=%(network_id)s tenant_id=%(tenant_id)s"),
            {'port_id': port_id,
             'network_id': network_id, 'tenant_id': tenant_id})
Exemplo n.º 11
0
    def create_network_postcommit(self, mech_context):
        """Create Network as a portprofile on the switch."""

        LOG.debug("create_network_postcommit: called")
        if self.is_flat_network(mech_context.network_segments[0]):
            return

        network = mech_context.current
        # use network_id to get the network attributes
        # ONLY depend on our db for getting back network attributes
        # this is so we can replay postcommit from db
        context = mech_context._plugin_context

        network_id = network['id']
        network = brocade_db.get_network(context, network_id)
        network_type = network.network_type
        tenant_id = network['tenant_id']
        vlan_id = network['vlan']

        try:
            self._driver.create_network(self._switch['address'],
                                        self._switch['username'],
                                        self._switch['password'], vlan_id)
        except Exception:
            LOG.exception(_LE("Brocade NOS driver: failed in create network"))
            brocade_db.delete_network(context, network_id)
            raise Exception(
                _("Brocade Mechanism: create_network_postcommmit failed"))

        LOG.info(
            _LI("created network (postcommit): %(network_id)s"
                " of network type = %(network_type)s"
                " with vlan = %(vlan_id)s"
                " for tenant %(tenant_id)s"), {
                    'network_id': network_id,
                    'network_type': network_type,
                    'vlan_id': vlan_id,
                    'tenant_id': tenant_id
                })
    def remove_router_interface(self, context, router_id, interface_info):
        """Deletes svi from NOS device"""
        LOG.debug("BrocadeSVIPlugin.remove_router_interface called: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})
        remove_by_port, remove_by_subnet = (
            self._validate_interface_info(interface_info, for_removal=True)
        )
        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin, self).remove_router_interface(
                context, router_id, interface_info)

        try:
            subnet = self._core_plugin._get_subnet(context, info['subnet_id'])
            if self._svi['redundancy'] and remove_by_subnet:
                self._core_plugin.delete_port(context, info['port_id'],
                                              l3_port_check=False)
            cidr = subnet['cidr']
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet['gateway_ip']
            network_id = subnet['network_id']
            tenant_id = subnet['tenant_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug("remove_router_interface removed cidr (%s)"
                      "from the pool, network_id (%s) bnet (%s) vlan (%d) ",
                      gateway_ip_cidr, network_id, bnet, int(vlan_id))
            brocade_db.delete_svi(context, router_id, tenant_id, vlan_id,
                                  gateway_ip, str(net_len))
            self._invoke_nos_driver_api("delete_svi", router_id,
                                        vlan_id, gateway_ip_cidr)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Failed to remove interface from brocade router"
                              "interface. info=%(info)s,"
                              " router_id=%(router_id)s"),
                          {"info": info, "router_id": router_id})
    def create_network_postcommit(self, mech_context):
        """Create Network as a portprofile on the switch."""

        LOG.debug("create_network_postcommit: called")
        if self.is_flat_network(mech_context.network_segments[0]):
            return

        network = mech_context.current
        # use network_id to get the network attributes
        # ONLY depend on our db for getting back network attributes
        # this is so we can replay postcommit from db
        context = mech_context._plugin_context

        network_id = network['id']
        network = brocade_db.get_network(context, network_id)
        network_type = network.network_type
        tenant_id = network['tenant_id']
        vlan_id = network['vlan']

        try:
            self._driver.create_network(self._switch['address'],
                                        self._switch['username'],
                                        self._switch['password'],
                                        vlan_id)
        except Exception:
            LOG.exception(_LE("Brocade NOS driver: failed in create network"))
            brocade_db.delete_network(context, network_id)
            raise Exception(
                _("Brocade Mechanism: create_network_postcommmit failed"))

        LOG.info(_LI("created network (postcommit): %(network_id)s"
                     " of network type = %(network_type)s"
                     " with vlan = %(vlan_id)s"
                     " for tenant %(tenant_id)s"),
                 {'network_id': network_id,
                  'network_type': network_type,
                  'vlan_id': vlan_id,
                  'tenant_id': tenant_id})
Exemplo n.º 14
0
    def delete_subnet_postcommit(self, mech_context):
        LOG.debug("delete_subnet_precommit: called")
        subnet = mech_context.current
        vlan_id = brocade_db.get_network(mech_context._plugin_context,
                                         subnet['network_id'])['vlan']
        
        required_seqs = self.get_project_access_list_seqs(subnet['project_id'])

        if self.tenants_acl_name:
            LOG.debug('refreshing acl, required_seqs: %s' % required_seqs)
            ret = self.fabric_driver.refresh_acl(self.tenants_acl_name, required_seqs)
            LOG.debug('refreshed acls, returned: %s' % ret)
        else:
            LOG.debug('tenants_acl_name unset, skipping acl refresh')

        gateway_ip = subnet['gateway_ip']
        gateway_subnet = subnet['cidr'].split('/')[1]
        gateway_address= "%s/%s" % (gateway_ip, gateway_subnet)
        gateway_address= "%s/%s" % (gateway_ip, gateway_subnet)
        try:
            self.fabric_driver.delete_subnet(vlan_id, gateway_address)
        except Exception:
            LOG.exception('Error deleting subnet: %s' % repr(ex))
            raise ex
Exemplo n.º 15
0
    def add_router_interface(self, context, router_id, interface_info):
        """creates svi on NOS device and assigns ip addres to SVI."""
        LOG.debug(
            "BrocadeSVIPlugin.add_router_interface on VDX: "
            "router_id=%(router_id)s "
            "interface_info=%(interface_info)r", {
                'router_id': router_id,
                'interface_info': interface_info
            })

        with context.session.begin(subtransactions=True):

            info = super(BrocadeSVIPlugin,
                         self).add_router_interface(context, router_id,
                                                    interface_info)

            port = db.get_port(context.session, info["port_id"])

            # shutting down neutron port to allow NOS to do Arp/Routing
            port['admin_state_up'] = False
            port['port'] = port
            self._core_plugin.update_port(context, info["port_id"], port)

            interface_info = info
            subnet = self._core_plugin._get_subnet(context,
                                                   interface_info["subnet_id"])
            cidr = subnet["cidr"]
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet["gateway_ip"]
            network_id = subnet['network_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug(
                "Allocated cidr %(cidr)s from the pool, "
                "network_id %(net_id)s "
                "bnet %(bnet)s "
                "vlan %(vlan_id)d ", {
                    'cidr': gateway_ip_cidr,
                    'net_id': network_id,
                    'bnet': bnet,
                    'vlan_id': int(vlan_id)
                })
            port_filters = {
                'network_id': [network_id],
                'device_owner': [DEVICE_OWNER_ROUTER_INTF]
            }
            port_count = self._core_plugin.get_ports_count(
                context, port_filters)
            LOG.info(
                _LI("BrocadeSVIPlugin.add_router_interface ports_count "
                    "%d"), port_count)

            # port count is checked against 2 since the current port is already
            # added to db
            if port_count == 2:
                # This subnet is already part of some router
                # (this is not supported in this version of brocade svi plugin)
                msg = _("BrocadeSVIPlugin: adding redundant router interface "
                        "is not supported")
                LOG.error(msg)
                raise Exception(msg)

        try:
            switch = self._switch
            self._driver.create_svi(switch['address'], switch['username'],
                                    switch['password'], switch['rbridge_id'],
                                    vlan_id, gateway_ip_cidr, str(router_id))
        except Exception:
            LOG.error(
                _LE("Failed to create Brocade resources to add router "
                    "interface. info=%(info)s, router_id=%(router_id)s"), {
                        "info": info,
                        "router_id": router_id
                    })
            with excutils.save_and_reraise_exception():
                with context.session.begin(subtransactions=True):
                    self.remove_router_interface(context, router_id,
                                                 interface_info)
        return info
    def add_router_interface(self, context, router_id, interface_info):
        """creates svi on NOS device and assigns ip addres to SVI"""
        LOG.debug("BrocadeSVIPlugin.add_router_interface called: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})
        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin, self).add_router_interface(
                context, router_id, interface_info)
        try:
            port = self._core_plugin._get_port(context, info["port_id"])
            # shutting  down neutron port to allow NOS to do Arp/Routing
            # Propose to community to allow this to do more gracefully
            port.update({"admin_state_up": False})
            interface_info = info
            subnet = self._core_plugin._get_subnet(context,
                                                   interface_info["subnet_id"])
            cidr = subnet["cidr"]
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet["gateway_ip"]
            network_id = subnet['network_id']
            tenant_id = subnet['tenant_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug("Allocated cidr (%s) from the pool, network_id(%s)"
                      "bnet (%s) vlan (%d) ", gateway_ip_cidr, network_id,
                      bnet, int(vlan_id))
            port_filters = {'network_id': [network_id],
                            'device_owner': [DEVICE_OWNER_ROUTER_INTF]}
            port_count = self._core_plugin.get_ports_count(context,
                                                           port_filters)
            LOG.info(_LI("BrocadeSVIPlugin.add_router_interface"
                         " ports_count %d"), port_count)
            # port count is checked against 2 since the
            # current port is already added to db
            if port_count == 2:
                # This subnet is already part of some router is not
                # supported
                # in this version of brocadesvi plugin
                LOG.error(_LE("BrocadeSVIPlugin:adding redundent router"
                              "interface is not supported"))
                raise Exception(_("BrocadeSVIPlugin:adding redundent"
                                  "router interface is not supported"))
            # res = self._update_ips_for_port(context, port)
            # gateway_ip = res['ip_address']
            # gateway_ip_cidr  = gateway_ip +'/'+str(net_len)
            brocade_db.create_svi(context, router_id, tenant_id, str(vlan_id),
                                  True, gateway_ip, str(net_len))
            self._invoke_nos_driver_api("create_svi", router_id, vlan_id,
                                        gateway_ip_cidr, context, port)
            self._update_firewall(context, vlan_id, tenant_id)

        except Exception:
            LOG.error(_LE("Failed to create Brocade resources to add router "
                          "interface. info=%(info)s, router_id=%(router_id)s"),
                      {"info": info, "router_id": router_id})
            with excutils.save_and_reraise_exception():
                self._invoke_nos_driver_api("delete_svi", router_id,
                                            vlan_id, gateway_ip_cidr)
                with context.session.begin(subtransactions=True):
                    info = super(BrocadeSVIPlugin, self).\
                        remove_router_interface(context,
                                                router_id,
                                                interface_info)

        return info
Exemplo n.º 17
0
    def add_router_interface(self, context, router_id, interface_info):
        """creates svi on NOS device and assigns ip addres to SVI"""
        LOG.debug(
            "BrocadeSVIPlugin.add_router_interface called: "
            "router_id=%(router_id)s "
            "interface_info=%(interface_info)r", {
                'router_id': router_id,
                'interface_info': interface_info
            })
        with context.session.begin(subtransactions=True):
            info = super(BrocadeSVIPlugin,
                         self).add_router_interface(context, router_id,
                                                    interface_info)
        try:
            port = self._core_plugin._get_port(context, info["port_id"])
            # shutting  down neutron port to allow NOS to do Arp/Routing
            # Propose to community to allow this to do more gracefully
            port.update({"admin_state_up": False})
            interface_info = info
            subnet = self._core_plugin._get_subnet(context,
                                                   interface_info["subnet_id"])
            cidr = subnet["cidr"]
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet["gateway_ip"]
            network_id = subnet['network_id']
            tenant_id = subnet['tenant_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug(
                "Allocated cidr (%s) from the pool, network_id(%s)"
                "bnet (%s) vlan (%d) ", gateway_ip_cidr, network_id, bnet,
                int(vlan_id))
            port_filters = {
                'network_id': [network_id],
                'device_owner': [DEVICE_OWNER_ROUTER_INTF]
            }
            port_count = self._core_plugin.get_ports_count(
                context, port_filters)
            LOG.info(
                _LI("BrocadeSVIPlugin.add_router_interface"
                    " ports_count %d"), port_count)
            # port count is checked against 2 since the
            # current port is already added to db
            if port_count == 2:
                # This subnet is already part of some router is not
                # supported
                # in this version of brocadesvi plugin
                LOG.error(
                    _LE("BrocadeSVIPlugin:adding redundent router"
                        "interface is not supported"))
                raise Exception(
                    _("BrocadeSVIPlugin:adding redundent"
                      "router interface is not supported"))
            # res = self._update_ips_for_port(context, port)
            # gateway_ip = res['ip_address']
            # gateway_ip_cidr  = gateway_ip +'/'+str(net_len)
            brocade_db.create_svi(context, router_id, tenant_id, str(vlan_id),
                                  True, gateway_ip, str(net_len))
            self._invoke_nos_driver_api("create_svi", router_id, vlan_id,
                                        gateway_ip_cidr, context, port)
            self._update_firewall(context, vlan_id, tenant_id)

        except Exception:
            LOG.error(
                _LE("Failed to create Brocade resources to add router "
                    "interface. info=%(info)s, router_id=%(router_id)s"), {
                        "info": info,
                        "router_id": router_id
                    })
            with excutils.save_and_reraise_exception():
                self._invoke_nos_driver_api("delete_svi", router_id, vlan_id,
                                            gateway_ip_cidr)
                with context.session.begin(subtransactions=True):
                    info = super(BrocadeSVIPlugin, self).\
                        remove_router_interface(context,
                                                router_id,
                                                interface_info)

        return info
    def add_router_interface(self, context, router_id, interface_info):
        """creates svi on NOS device and assigns ip addres to SVI."""
        LOG.debug("BrocadeSVIPlugin.add_router_interface on VDX: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})

        with context.session.begin(subtransactions=True):

            info = super(BrocadeSVIPlugin, self).add_router_interface(
                context, router_id, interface_info)

            port = db.get_port(context.session, info["port_id"])

            # shutting down neutron port to allow NOS to do Arp/Routing
            port['admin_state_up'] = False
            port['port'] = port
            self._core_plugin.update_port(context, info["port_id"], port)

            interface_info = info
            subnet = self._core_plugin._get_subnet(context,
                                                   interface_info["subnet_id"])
            cidr = subnet["cidr"]
            net_addr, net_len = self.net_addr(cidr)
            gateway_ip = subnet["gateway_ip"]
            network_id = subnet['network_id']
            bnet = brocade_db.get_network(context, network_id)
            vlan_id = bnet['vlan']
            gateway_ip_cidr = gateway_ip + '/' + str(net_len)
            LOG.debug("Allocated cidr %(cidr)s from the pool, "
                      "network_id %(net_id)s "
                      "bnet %(bnet)s "
                      "vlan %(vlan_id)d ", {'cidr': gateway_ip_cidr,
                                            'net_id': network_id,
                                            'bnet': bnet,
                                            'vlan_id': int(vlan_id)})
            port_filters = {'network_id': [network_id],
                            'device_owner': [DEVICE_OWNER_ROUTER_INTF]}
            port_count = self._core_plugin.get_ports_count(context,
                                                           port_filters)
            LOG.info(_LI("BrocadeSVIPlugin.add_router_interface ports_count "
                         "%d"),
                     port_count)

            # port count is checked against 2 since the current port is already
            # added to db
            if port_count == 2:
                # This subnet is already part of some router
                # (this is not supported in this version of brocade svi plugin)
                msg = _("BrocadeSVIPlugin: adding redundant router interface "
                        "is not supported")
                LOG.error(msg)
                raise Exception(msg)

        try:
            switch = self._switch
            self._driver.create_svi(switch['address'],
                                    switch['username'],
                                    switch['password'],
                                    switch['rbridge_id'],
                                    vlan_id,
                                    gateway_ip_cidr,
                                    str(router_id))
        except Exception:
            LOG.error(_LE("Failed to create Brocade resources to add router "
                          "interface. info=%(info)s, router_id=%(router_id)s"),
                      {"info": info, "router_id": router_id})
            with excutils.save_and_reraise_exception():
                with context.session.begin(subtransactions=True):
                    self.remove_router_interface(context, router_id,
                                                 interface_info)
        return info