Ejemplo n.º 1
0
    def delete_port(self, device_id, vlan_id):
        """Delete port.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """
        LOG.debug(_("NexusPlugin:delete_port() called"))
        # Delete DB row(s) for this port
        try:
            rows = nxos_db.get_nexusvm_bindings(vlan_id, device_id)
        except cisco_exc.NexusPortBindingNotFound:
            return

        auto_delete = True
        auto_untrunk = True
        if cdb.is_provider_vlan(vlan_id):
            auto_delete = conf.CISCO.provider_vlan_auto_create
            auto_untrunk = conf.CISCO.provider_vlan_auto_trunk
            LOG.debug(_("delete_network(): provider vlan %s"), vlan_id)

        instance_id = False
        for row in rows:
            instance_id = row["instance_id"]
            switch_ip = row.switch_ip
            etype, nexus_port = "", ""
            if row["port_id"] == "router":
                etype, nexus_port = "vlan", row["port_id"]
                auto_untrunk = False
            else:
                etype, nexus_port = row["port_id"].split(":")

            nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id)
            # Check whether there are any remaining instances using this
            # vlan on this Nexus port.
            try:
                nxos_db.get_port_vlan_switch_binding(row.port_id, row.vlan_id, row.switch_ip)
            except cisco_exc.NexusPortBindingNotFound:
                try:
                    if nexus_port and auto_untrunk:
                        # Untrunk the vlan from this Nexus interface
                        self._client.disable_vlan_on_trunk_int(switch_ip, row.vlan_id, etype, nexus_port)

                    # Check whether there are any remaining instances
                    # using this vlan on the Nexus switch.
                    if auto_delete:
                        try:
                            nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip)
                        except cisco_exc.NexusPortBindingNotFound:
                            # Delete this vlan from this switch
                            self._client.delete_vlan(switch_ip, row.vlan_id)
                except Exception:
                    # The delete vlan operation on the Nexus failed,
                    # so this delete_port request has failed. For
                    # consistency, roll back the Nexus database to what
                    # it was before this request.
                    with excutils.save_and_reraise_exception():
                        nxos_db.add_nexusport_binding(row.port_id, row.vlan_id, row.switch_ip, row.instance_id)

        return instance_id
Ejemplo n.º 2
0
 def test_nexusportbinding_add_remove(self):
     npb11 = self._npb_test_obj(10, 100)
     npb = nxdb.add_nexusport_binding(npb11.port, npb11.vlan, npb11.switch, npb11.instance)
     self._assert_equal(npb, npb11)
     npb = nxdb.remove_nexusport_binding(npb11.port, npb11.vlan, npb11.switch, npb11.instance)
     self.assertEqual(len(npb), 1)
     self._assert_equal(npb[0], npb11)
     with testtools.ExpectedException(c_exc.NexusPortBindingNotFound):
         nxdb.remove_nexusport_binding(npb11.port, npb11.vlan, npb11.switch, npb11.instance)
Ejemplo n.º 3
0
    def delete_port(self, device_id, vlan_id):
        """Delete port.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """
        LOG.debug(_("NexusPlugin:delete_port() called"))
        # Delete DB row(s) for this port
        try:
            rows = nxos_db.get_nexusvm_bindings(vlan_id, device_id)
        except cisco_exc.NexusPortBindingNotFound:
            return

        auto_delete = True
        auto_untrunk = True
        if cdb.is_provider_vlan(vlan_id):
            auto_delete = conf.CISCO.provider_vlan_auto_create
            auto_untrunk = conf.CISCO.provider_vlan_auto_trunk
            LOG.debug("delete_network(): provider vlan %s" % vlan_id)

        instance_id = False
        for row in rows:
            instance_id = row['instance_id']
            switch_ip = row.switch_ip
            etype, nexus_port = '', ''
            if row['port_id'] == 'router':
                etype, nexus_port = 'vlan', row['port_id']
            else:
                etype, nexus_port = row['port_id'].split(':')

            nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                             row.switch_ip,
                                             row.instance_id)
            # Check for any other bindings with the same vlan_id and switch_ip
            try:
                nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip)
            except cisco_exc.NexusPortBindingNotFound:
                try:
                    # Delete this vlan from this switch
                    if nexus_port and auto_untrunk:
                        self._client.disable_vlan_on_trunk_int(
                            switch_ip, row.vlan_id, etype, nexus_port)
                    if auto_delete:
                        self._client.delete_vlan(switch_ip, row.vlan_id)
                except Exception:
                    # The delete vlan operation on the Nexus failed,
                    # so this delete_port request has failed. For
                    # consistency, roll back the Nexus database to what
                    # it was before this request.
                    with excutils.save_and_reraise_exception():
                        nxos_db.add_nexusport_binding(row.port_id,
                                                      row.vlan_id,
                                                      row.switch_ip,
                                                      row.instance_id)

        return instance_id
Ejemplo n.º 4
0
    def delete_port(self, device_id, vlan_id):
        """Delete port.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """
        LOG.debug(_("NexusPlugin:delete_port() called"))
        # Delete DB row(s) for this port
        try:
            rows = nxos_db.get_nexusvm_bindings(vlan_id, device_id)
        except cisco_exc.NexusPortBindingNotFound:
            return

        auto_delete = True
        auto_untrunk = True
        if cdb.is_provider_vlan(vlan_id):
            auto_delete = conf.CISCO.provider_vlan_auto_create
            auto_untrunk = conf.CISCO.provider_vlan_auto_trunk
            LOG.debug(_("delete_network(): provider vlan %s"), vlan_id)

        instance_id = False
        for row in rows:
            instance_id = row['instance_id']
            switch_ip = row.switch_ip
            etype, nexus_port = '', ''
            if row['port_id'] == 'router':
                etype, nexus_port = 'vlan', row['port_id']
                auto_untrunk = False
            else:
                etype, nexus_port = row['port_id'].split(':')

            nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                             row.switch_ip, row.instance_id)
            # Check for any other bindings with the same vlan_id and switch_ip
            try:
                nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip)
            except cisco_exc.NexusPortBindingNotFound:
                try:
                    # Delete this vlan from this switch
                    if nexus_port and auto_untrunk:
                        self._client.disable_vlan_on_trunk_int(
                            switch_ip, row.vlan_id, etype, nexus_port)
                    if auto_delete:
                        self._client.delete_vlan(switch_ip, row.vlan_id)
                except Exception:
                    # The delete vlan operation on the Nexus failed,
                    # so this delete_port request has failed. For
                    # consistency, roll back the Nexus database to what
                    # it was before this request.
                    with excutils.save_and_reraise_exception():
                        nxos_db.add_nexusport_binding(row.port_id, row.vlan_id,
                                                      row.switch_ip,
                                                      row.instance_id)

        return instance_id
Ejemplo n.º 5
0
 def test_nexusportbinding_add_remove(self):
     npb11 = self._npb_test_obj(10, 100)
     npb = nxdb.add_nexusport_binding(npb11.port, npb11.vlan, npb11.switch,
                                      npb11.instance)
     self._assert_equal(npb, npb11)
     npb = nxdb.remove_nexusport_binding(npb11.port, npb11.vlan,
                                         npb11.switch, npb11.instance)
     self.assertEqual(len(npb), 1)
     self._assert_equal(npb[0], npb11)
     with testtools.ExpectedException(c_exc.NexusPortBindingNotFound):
         nxdb.remove_nexusport_binding(npb11.port, npb11.vlan, npb11.switch,
                                       npb11.instance)
    def delete_port(self, device_id, vlan_id):
        """Delete port.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """
        LOG.debug(_("NexusPlugin:delete_port() called"))
        # Delete DB row for this port
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
        except cisco_exc.NexusPortBindingNotFound:
            return

        nxos_db.remove_nexusport_binding(row['port_id'], row['vlan_id'],
                                         row['switch_ip'],
                                         row['instance_id'])
        # Check for any other bindings with the same vlan_id and switch_ip
        try:
            nxos_db.get_nexusvlan_binding(row['vlan_id'], row['switch_ip'])
        except cisco_exc.NexusPortBindingNotFound:
            try:
                # Delete this vlan from this switch
                _nexus_ip = row['switch_ip']
                _nexus_ports = ()
                if row['port_id'] != 'router':
                    _nexus_ports = (row['port_id'],)
                _nexus_ssh_port = (self._nexus_switches[_nexus_ip,
                                                        'ssh_port'])
                _nexus_creds = self.get_credential(_nexus_ip)
                _nexus_username = _nexus_creds['username']
                _nexus_password = _nexus_creds['password']
                self._client.delete_vlan(
                    str(row['vlan_id']), _nexus_ip,
                    _nexus_username, _nexus_password,
                    _nexus_ports, _nexus_ssh_port)
            except Exception:
                # The delete vlan operation on the Nexus failed,
                # so this delete_port request has failed. For
                # consistency, roll back the Nexus database to what
                # it was before this request.
                with excutils.save_and_reraise_exception():
                    nxos_db.add_nexusport_binding(row['port_id'],
                                                  row['vlan_id'],
                                                  row['switch_ip'],
                                                  row['instance_id'])

        return row['instance_id']