예제 #1
0
    def _delete_switch_entry(self, vlan_id, device_id, host_id):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)
        for switch_ip, intf_type, nexus_port in host_connections:
            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                      intf_type, nexus_port)

                # if there are no remaining db entries using this vlan on this
                # nexus switch then remove the vlan.
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:
                    self.driver.delete_vlan(switch_ip, vlan_id)
예제 #2
0
    def _delete_switch_entry(self, vlan_id, device_id, host_id):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)
        for switch_ip, intf_type, nexus_port in host_connections:
            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                      intf_type, nexus_port)

                # if there are no remaining db entries using this vlan on this
                # nexus switch then remove the vlan.
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:
                    self.driver.delete_vlan(switch_ip, vlan_id)
    def test_nexusvlanbinding_get(self):
        """Test get of port bindings based on vlan and switch."""
        npb11 = self._npb_test_obj(10, 100)
        npb21 = self._npb_test_obj(20, 100)
        npb22 = self._npb_test_obj(20, 200)
        self._add_bindings_to_db([npb11, npb21, npb22])

        npb_all_v100 = self._get_nexusvlan_binding(npb11)
        self.assertEqual(len(npb_all_v100), 2)
        npb_v200 = self._get_nexusvlan_binding(npb22)
        self.assertEqual(len(npb_v200), 1)
        self._assert_bindings_match(npb_v200[0], npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusvlan_binding(npb21.vlan, "dummySwitch")
예제 #4
0
    def test_nexusvlanbinding_get(self):
        """Test get of port bindings based on vlan and switch."""
        npb11 = self._npb_test_obj(10, 100)
        npb21 = self._npb_test_obj(20, 100)
        npb22 = self._npb_test_obj(20, 200)
        self._add_bindings_to_db([npb11, npb21, npb22])

        npb_all_v100 = self._get_nexusvlan_binding(npb11)
        self.assertEqual(len(npb_all_v100), 2)
        npb_v200 = self._get_nexusvlan_binding(npb22)
        self.assertEqual(len(npb_v200), 1)
        self._assert_bindings_match(npb_v200[0], npb22)

        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.get_nexusvlan_binding(npb21.vlan, "dummySwitch")
예제 #5
0
    def _configure_switch_entry(self, vlan_id, device_id, host_id):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch/port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        vlan_name = cfg.CONF.ml2_cisco.vlan_name_prefix + str(vlan_id)
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan created in this loop.
        vlan_already_created = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # The VLAN needs to be created on the switch if no other
            # instance has been placed in this VLAN on a different host
            # attached to this switch.  Search the existing bindings in the
            # database.  If all the instance_id in the database match the
            # current device_id, then create the VLAN, but only once per
            # switch_ip.  Otherwise, just trunk.
            all_bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            previous_bindings = [row for row in all_bindings
                    if row.instance_id != device_id]
            if previous_bindings or (switch_ip in vlan_already_created):
                LOG.debug("Nexus: trunk vlan %s"), vlan_name
                self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                     intf_type, nexus_port)
            else:
                vlan_already_created.append(switch_ip)
                LOG.debug("Nexus: create & trunk vlan %s"), vlan_name
                self.driver.create_and_trunk_vlan(
                    switch_ip, vlan_id, vlan_name, intf_type, nexus_port)
    def test_nexusbinding_update(self):
        """Tests update of vlan IDs for port bindings."""
        npb11 = self._npb_test_obj(10, 100, switch='1.1.1.1', instance='test')
        npb21 = self._npb_test_obj(20, 100, switch='1.1.1.1', instance='test')
        self._add_bindings_to_db([npb11, npb21])

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 2)

        npb22 = self._npb_test_obj(20, 200, switch='1.1.1.1', instance='test')
        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 200)
        self._assert_bindings_match(npb, npb22)

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 1)
        self._assert_bindings_match(npb_all_v100[0], npb11)

        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 0)
        self.assertIsNone(npb)

        npb33 = self._npb_test_obj(30, 300, switch='1.1.1.1', instance='test')
        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.update_nexusport_binding(npb33.port, 200)
예제 #7
0
    def test_nexusbinding_update(self):
        """Tests update of vlan IDs for port bindings."""
        npb11 = self._npb_test_obj(10, 100, switch='1.1.1.1', instance='test')
        npb21 = self._npb_test_obj(20, 100, switch='1.1.1.1', instance='test')
        self._add_bindings_to_db([npb11, npb21])

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 2)

        npb22 = self._npb_test_obj(20, 200, switch='1.1.1.1', instance='test')
        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 200)
        self._assert_bindings_match(npb, npb22)

        npb_all_v100 = nexus_db_v2.get_nexusvlan_binding(100, '1.1.1.1')
        self.assertEqual(len(npb_all_v100), 1)
        self._assert_bindings_match(npb_all_v100[0], npb11)

        npb = nexus_db_v2.update_nexusport_binding(npb21.port, 0)
        self.assertIsNone(npb)

        npb33 = self._npb_test_obj(30, 300, switch='1.1.1.1', instance='test')
        with testtools.ExpectedException(exceptions.NexusPortBindingNotFound):
            nexus_db_v2.update_nexusport_binding(npb33.port, 200)
예제 #8
0
    def _delete_switch_entry(self, vlan_id, device_id, host_id):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan removed in this loop.
        vlan_already_removed = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                      intf_type, nexus_port)

                # if there are no remaining db entries using this vlan on this
                # nexus switch then remove the vlan.
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:

                    # Do not perform a second time on same switch
                    if switch_ip not in vlan_already_removed:
                        self.driver.delete_vlan(switch_ip, vlan_id)
                        vlan_already_removed.append(switch_ip)
예제 #9
0
    def _delete_switch_entry(self, vlan_id, device_id, host_id):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during update postcommit port event.
        """
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan removed in this loop.
        vlan_already_removed = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = '%s:%s' % (intf_type, nexus_port)
            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                      intf_type, nexus_port)

                # if there are no remaining db entries using this vlan on this
                # nexus switch then remove the vlan.
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:

                    # Do not perform a second time on same switch
                    if switch_ip not in vlan_already_removed:
                        self.driver.delete_vlan(switch_ip, vlan_id)
                        vlan_already_removed.append(switch_ip)
예제 #10
0
    def _configure_switch_entry(self, vlan_id, device_id, host_id):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch/port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        port_id, switch_ip = self._get_switch_info(host_id)
        vlan_name = cfg.CONF.ml2_cisco.vlan_name_prefix + str(vlan_id)

        # Check to see if this is the first binding to use this vlan on the
        # switch/port. Configure switch accordingly.
        bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
        if len(bindings) == 1:
            LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name)
            self.driver.create_and_trunk_vlan(switch_ip, vlan_id, vlan_name,
                                              port_id)
        else:
            LOG.debug(_("Nexus: trunk vlan %s"), vlan_name)
            self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id, port_id)
예제 #11
0
    def _configure_switch_entry(self, vlan_id, device_id, host_id):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch/port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        port_id, switch_ip = self._get_switch_info(host_id)
        vlan_name = cfg.CONF.ml2_cisco.vlan_name_prefix + str(vlan_id)

        # Check to see if this is the first binding to use this vlan on the
        # switch/port. Configure switch accordingly.
        bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
        if len(bindings) == 1:
            LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name)
            self.driver.create_and_trunk_vlan(switch_ip, vlan_id, vlan_name,
                                              port_id)
        else:
            LOG.debug(_("Nexus: trunk vlan %s"), vlan_name)
            self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id, port_id)
예제 #12
0
    def _configure_switch_entry(self, vlan_id, device_id, host_id):
        """Create a nexus switch entry.

        if needed, create a VLAN in the appropriate switch/port and
        configure the appropriate interfaces for this VLAN.

        Called during update postcommit port event.
        """
        vlan_name = cfg.CONF.ml2_cisco.vlan_name_prefix + str(vlan_id)
        host_connections = self._get_switch_info(host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan created in this loop.
        vlan_already_created = []
        for switch_ip, intf_type, nexus_port in host_connections:

            # The VLAN needs to be created on the switch if no other
            # instance has been placed in this VLAN on a different host
            # attached to this switch.  Search the existing bindings in the
            # database.  If all the instance_id in the database match the
            # current device_id, then create the VLAN, but only once per
            # switch_ip.  Otherwise, just trunk.
            all_bindings = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            previous_bindings = [
                row for row in all_bindings if row.instance_id != device_id
            ]
            if previous_bindings or (switch_ip in vlan_already_created):
                LOG.debug("Nexus: trunk vlan %s", vlan_name)
                self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                     intf_type, nexus_port)
            else:
                vlan_already_created.append(switch_ip)
                LOG.debug("Nexus: create & trunk vlan %s", vlan_name)
                self.driver.create_and_trunk_vlan(switch_ip, vlan_id,
                                                  vlan_name, intf_type,
                                                  nexus_port)
 def _get_nexusvlan_binding(self, npb):
     """Gets port bindings based on vlan and switch."""
     return nexus_db_v2.get_nexusvlan_binding(npb.vlan, npb.switch)
예제 #14
0
 def _get_nexusvlan_binding(self, npb):
     """Gets port bindings based on vlan and switch."""
     return nexus_db_v2.get_nexusvlan_binding(npb.vlan, npb.switch)