Example #1
0
    def _manage_port(self, vlan_name, vlan_id, host, instance):
        """Called during create and update port events.

        Create a VLAN in the appropriate switch/port and configure the
        appropriate interfaces for this VLAN.
        """

        # Grab the switch IP and port for this host
        for switch_ip, attr in self._nexus_switches:
            if str(attr) == str(host):
                port_id = self._nexus_switches[switch_ip, attr]
                break
        else:
            raise excep.NexusComputeHostNotConfigured(host=host)

        # Check if this network is already in the DB
        vlan_created = False
        vlan_trunked = False

        try:
            nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip)
        except excep.NexusPortBindingNotFound:
            # Check for vlan/switch binding
            try:
                nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            except excep.NexusPortBindingNotFound:
                # Create vlan and trunk vlan on the port
                LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name)
                self.driver.create_and_trunk_vlan(switch_ip, vlan_id,
                                                  vlan_name, port_id)
                vlan_created = True
                vlan_trunked = True
            else:
                # Only trunk vlan on the port
                LOG.debug(_("Nexus: trunk vlan %s"), vlan_name)
                self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                     port_id)
                vlan_trunked = True

        try:
            nxos_db.add_nexusport_binding(port_id, str(vlan_id),
                                          switch_ip, instance)
        except Exception:
            with excutils.save_and_reraise_exception():
                # Add binding failed, roll back any vlan creation/enabling
                if vlan_created and vlan_trunked:
                    LOG.debug(_("Nexus: delete & untrunk vlan %s"), vlan_name)
                    self.driver.delete_and_untrunk_vlan(switch_ip, vlan_id,
                                                        port_id)
                elif vlan_created:
                    LOG.debug(_("Nexus: delete vlan %s"), vlan_name)
                    self.driver.delete_vlan(switch_ip, vlan_id)
                elif vlan_trunked:
                    LOG.debug(_("Nexus: untrunk vlan %s"), vlan_name)
                    self.driver.disable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                          port_id)
Example #2
0
    def _manage_port(self, vlan_name, vlan_id, host, instance):
        """Called during create and update port events.

        Create a VLAN in the appropriate switch/port and configure the
        appropriate interfaces for this VLAN.
        """

        # Grab the switch IP and port for this host
        for switch_ip, attr in self._nexus_switches:
            if str(attr) == str(host):
                port_id = self._nexus_switches[switch_ip, attr]
                break
        else:
            raise excep.NexusComputeHostNotConfigured(host=host)

        # Check if this network is already in the DB
        vlan_created = False
        vlan_trunked = False

        try:
            nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip)
        except excep.NexusPortBindingNotFound:
            # Check for vlan/switch binding
            try:
                nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            except excep.NexusPortBindingNotFound:
                # Create vlan and trunk vlan on the port
                LOG.debug(_("Nexus: create & trunk vlan %s"), vlan_name)
                self.driver.create_and_trunk_vlan(switch_ip, vlan_id,
                                                  vlan_name, port_id)
                vlan_created = True
                vlan_trunked = True
            else:
                # Only trunk vlan on the port
                LOG.debug(_("Nexus: trunk vlan %s"), vlan_name)
                self.driver.enable_vlan_on_trunk_int(switch_ip, vlan_id,
                                                     port_id)
                vlan_trunked = True

        try:
            nxos_db.add_nexusport_binding(port_id, str(vlan_id), switch_ip,
                                          instance)
        except Exception:
            with excutils.save_and_reraise_exception():
                # Add binding failed, roll back any vlan creation/enabling
                if vlan_created and vlan_trunked:
                    LOG.debug(_("Nexus: delete & untrunk vlan %s"), vlan_name)
                    self.driver.delete_and_untrunk_vlan(
                        switch_ip, vlan_id, port_id)
                elif vlan_created:
                    LOG.debug(_("Nexus: delete vlan %s"), vlan_name)
                    self.driver.delete_vlan(switch_ip, vlan_id)
                elif vlan_trunked:
                    LOG.debug(_("Nexus: untrunk vlan %s"), vlan_name)
                    self.driver.disable_vlan_on_trunk_int(
                        switch_ip, vlan_id, port_id)
Example #3
0
    def delete_port_precommit(self, context):
        """Delete port pre-database commit event.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """

        if not self._is_deviceowner_compute(context.current):
            return

        port = context.current
        device_id = port['device_id']
        vlan_id = self._get_vlanid(context)

        if not vlan_id or not device_id:
            return

        # Delete DB row for this port
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
        except excep.NexusPortBindingNotFound:
            return

        switch_ip = row.switch_ip
        nexus_port = None
        if row.port_id != 'router':
            nexus_port = row.port_id

        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 excep.NexusPortBindingNotFound:
            try:
                # Delete this vlan from this switch
                if nexus_port:
                    self.driver.disable_vlan_on_trunk_int(switch_ip,
                                                          row.vlan_id,
                                                          nexus_port)
                self.driver.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)
Example #4
0
    def delete_port_precommit(self, context):
        """Delete port pre-database commit event.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """

        if not self._is_deviceowner_compute(context.current):
            return

        port = context.current
        device_id = port['device_id']
        vlan_id = self._get_vlanid(context)

        if not vlan_id or not device_id:
            return

        # Delete DB row for this port
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
        except excep.NexusPortBindingNotFound:
            return

        switch_ip = row.switch_ip
        nexus_port = None
        if row.port_id != 'router':
            nexus_port = row.port_id

        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 excep.NexusPortBindingNotFound:
            try:
                # Delete this vlan from this switch
                if nexus_port:
                    self.driver.disable_vlan_on_trunk_int(
                        switch_ip, row.vlan_id, nexus_port)
                self.driver.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)
Example #5
0
 def _add_bindings_to_db(self, npbs):
     """Adds a list of port bindings to the Nexus database."""
     for npb in npbs:
         nexus_db_v2.add_nexusport_binding(
             npb.port, npb.vlan, npb.switch, npb.instance)
Example #6
0
 def _add_binding_to_db(self, npb):
     """Adds a port binding to the Nexus database."""
     return nexus_db_v2.add_nexusport_binding(
         npb.port, npb.vlan, npb.switch, npb.instance)