Пример #1
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       **kwargs):
        """
        Create a VLAN in the switch, and configure the appropriate interfaces
        for this VLAN
        """
        LOG.debug("NexusPlugin:create_network() called\n")
        vlan_ids = ''
        for key in kwargs:
            if key == 'vlan_ids':
                vlan_ids = kwargs['vlan_ids']
        self._client.create_vlan(
            vlan_name, str(vlan_id), self._nexus_ip,
            self._nexus_username, self._nexus_password,
            self._nexus_ports, self._nexus_ssh_port, vlan_ids)
        for ports in self._nexus_ports:
            try:
                nxos_db.add_nexusport_binding(ports, str(vlan_id))
            except:
                raise excep.NexusPortBindingAlreadyExists(port_id=ports)

        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict
Пример #2
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       **kwargs):
        """
        Create a VLAN in the switch, and configure the appropriate interfaces
        for this VLAN
        """
        LOG.debug("NexusPlugin:create_network() called\n")
        vlan_ids = ''
        for key in kwargs:
            if key == 'vlan_ids':
                vlan_ids = kwargs['vlan_ids']
        self._client.create_vlan(
            vlan_name, str(vlan_id), self._nexus_ip,
            self._nexus_username, self._nexus_password,
            self._nexus_ports, self._nexus_ssh_port, vlan_ids)
        for ports in self._nexus_ports:
            try:
                nxos_db.add_nexusport_binding(ports, str(vlan_id))
            except:
                raise excep.NexusPortBindingAlreadyExists(port_id=ports)

        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict
Пример #3
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       host, instance):
        """
        Create a VLAN in the appropriate switch/port,
        and configure the appropriate interfaces
        for this VLAN
        """
        LOG.debug("NexusPlugin:create_network() called\n")
        # Grab the switch IP and port for this host
        switch_ip = ''
        port_id = ''
        for switch in self._nexus_switches.keys():
            for hostname in self._nexus_switches[switch].keys():
                if str(hostname) == str(host):
                    switch_ip = switch
                    port_id = self._nexus_switches[switch][hostname]['ports']
        # Check if this network is already in the DB
        binding = nxos_db.get_port_vlan_switch_binding(
            port_id, vlan_id, switch_ip)
        if not binding:
            _nexus_ip = switch_ip
            _nexus_ports = (port_id,)
            _nexus_ssh_port = \
                self._nexus_switches[switch_ip]['ssh_port']['ssh_port']
            _nexus_creds = self.get_credential(_nexus_ip)
            _nexus_username = _nexus_creds['username']
            _nexus_password = _nexus_creds['password']
            # Check for vlan/switch binding
            vbinding = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            if not vbinding:
                # Create vlan and trunk vlan on the port
                self._client.create_vlan(
                    vlan_name, str(vlan_id), _nexus_ip,
                    _nexus_username, _nexus_password,
                    _nexus_ports, _nexus_ssh_port, vlan_id)
            else:
                # Only trunk vlan on the port
                man = self._client.nxos_connect(_nexus_ip,
                                                int(_nexus_ssh_port),
                                                _nexus_username,
                                                _nexus_password)
                self._client.enable_vlan_on_trunk_int(man,
                                                      port_id,
                                                      vlan_id)

        nxos_db.add_nexusport_binding(port_id, str(vlan_id),
                                      switch_ip, instance)
        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       host, instance):
        """
        Create a VLAN in the appropriate switch/port,
        and configure the appropriate interfaces
        for this VLAN
        """
        LOG.debug(_("NexusPlugin:create_network() called"))
        # Grab the switch IP and port for this host
        switch_ip = ''
        port_id = ''
        for switch in self._nexus_switches.keys():
            for hostname in self._nexus_switches[switch].keys():
                if str(hostname) == str(host):
                    switch_ip = switch
                    port_id = self._nexus_switches[switch][hostname]['ports']
        # Check if this network is already in the DB
        binding = nxos_db.get_port_vlan_switch_binding(
            port_id, vlan_id, switch_ip)
        if not binding:
            _nexus_ip = switch_ip
            _nexus_ports = (port_id,)
            _nexus_ssh_port = \
                self._nexus_switches[switch_ip]['ssh_port']['ssh_port']
            _nexus_creds = self.get_credential(_nexus_ip)
            _nexus_username = _nexus_creds['username']
            _nexus_password = _nexus_creds['password']
            # Check for vlan/switch binding
            vbinding = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            if not vbinding:
                # Create vlan and trunk vlan on the port
                self._client.create_vlan(
                    vlan_name, str(vlan_id), _nexus_ip,
                    _nexus_username, _nexus_password,
                    _nexus_ports, _nexus_ssh_port, vlan_id)
            else:
                # Only trunk vlan on the port
                man = self._client.nxos_connect(_nexus_ip,
                                                int(_nexus_ssh_port),
                                                _nexus_username,
                                                _nexus_password)
                self._client.enable_vlan_on_trunk_int(man,
                                                      port_id,
                                                      vlan_id)

        nxos_db.add_nexusport_binding(port_id, str(vlan_id),
                                      switch_ip, instance)
        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict
Пример #5
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 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 as e:
                # 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.
                try:
                    nxos_db.add_nexusport_binding(row['port_id'],
                                                  row['vlan_id'],
                                                  row['switch_ip'],
                                                  row['instance_id'])
                finally:
                    # Raise the original exception
                    raise e

        return row['instance_id']
Пример #6
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 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 as e:
                # 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.
                try:
                    nxos_db.add_nexusport_binding(row['port_id'],
                                                  row['vlan_id'],
                                                  row['switch_ip'],
                                                  row['instance_id'])
                finally:
                    # Raise the original exception
                    raise e

        return row['instance_id']
Пример #7
0
 def create_nexusportbinding(self, port_id, vlan_id):
     """create nexus port binding."""
     bind_dict = {}
     try:
         res = nexus_db.add_nexusport_binding(port_id, vlan_id)
         LOG.debug("Created nexus port binding : %s" % res.port_id)
         bind_dict["port-id"] = str(res.port_id)
         bind_dict["vlan-id"] = str(res.vlan_id)
         return bind_dict
     except Exception, exc:
         LOG.error("Failed to create nexus binding: %s" % str(exc))
Пример #8
0
 def create_nexusportbinding(self, port_id, vlan_id):
     """Create nexus port binding."""
     bind_dict = {}
     try:
         res = nexus_db.add_nexusport_binding(port_id, vlan_id)
         LOG.debug("Created nexus port binding : %s" % res.port_id)
         bind_dict["port-id"] = str(res.port_id)
         bind_dict["vlan-id"] = str(res.vlan_id)
         return bind_dict
     except Exception as exc:
         LOG.error("Failed to create nexus binding: %s" % str(exc))
Пример #9
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       **kwargs):
        """
        Create a VLAN in the switch, and configure the appropriate interfaces
        for this VLAN
        """
        LOG.debug("NexusPlugin:create_network() called\n")
        self._client.create_vlan(
            vlan_name, str(vlan_id), self._nexus_ip,
            self._nexus_username, self._nexus_password,
            self._nexus_first_port, self._nexus_second_port,
            self._nexus_ssh_port)
        nxos_db.add_nexusport_binding(self._nexus_first_port, str(vlan_id))
        nxos_db.add_nexusport_binding(self._nexus_second_port, str(vlan_id))

        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict
Пример #10
0
    def add_router_interface(self, vlan_name, vlan_id, subnet_id,
                             gateway_ip, router_id):
        """Create VLAN SVI on the Nexus switch."""
        # Find a switch to create the SVI on
        switch_ip = self._find_switch_for_svi()
        if not switch_ip:
            raise cisco_exc.NoNexusSwitch()

        _nexus_ip = switch_ip
        _nexus_ssh_port = self._nexus_switches[switch_ip, 'ssh_port']
        _nexus_creds = self.get_credential(_nexus_ip)
        _nexus_username = _nexus_creds['username']
        _nexus_password = _nexus_creds['password']

        # Check if this vlan exists on the switch already
        try:
            nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
        except cisco_exc.NexusPortBindingNotFound:
            # Create vlan and trunk vlan on the port
            self._client.create_vlan(
                vlan_name, str(vlan_id), _nexus_ip,
                _nexus_username, _nexus_password,
                [], _nexus_ssh_port, vlan_id)

        # Check if a router interface has already been created
        try:
            nxos_db.get_nexusvm_binding(vlan_id, router_id)
            raise cisco_exc.SubnetInterfacePresent(subnet_id=subnet_id,
                                                   router_id=router_id)
        except cisco_exc.NexusPortBindingNotFound:
            self._client.create_vlan_svi(vlan_id, _nexus_ip, _nexus_username,
                                         _nexus_password, _nexus_ssh_port,
                                         gateway_ip)
            nxos_db.add_nexusport_binding('router', str(vlan_id),
                                          switch_ip, router_id)

            return True
Пример #11
0
    def add_router_interface(self, vlan_name, vlan_id, subnet_id, gateway_ip,
                             router_id):
        """Create VLAN SVI on the Nexus switch."""
        # Find a switch to create the SVI on
        switch_ip = self._find_switch_for_svi()
        if not switch_ip:
            raise cisco_exc.NoNexusSwitch()

        _nexus_ip = switch_ip
        _nexus_ssh_port = self._nexus_switches[switch_ip, 'ssh_port']
        _nexus_creds = self.get_credential(_nexus_ip)
        _nexus_username = _nexus_creds['username']
        _nexus_password = _nexus_creds['password']

        # Check if this vlan exists on the switch already
        try:
            nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
        except cisco_exc.NexusPortBindingNotFound:
            # Create vlan and trunk vlan on the port
            self._client.create_vlan(vlan_name, str(vlan_id), _nexus_ip,
                                     _nexus_username, _nexus_password, [],
                                     _nexus_ssh_port, vlan_id)

        # Check if a router interface has already been created
        try:
            nxos_db.get_nexusvm_binding(vlan_id, router_id)
            raise cisco_exc.SubnetInterfacePresent(subnet_id=subnet_id,
                                                   router_id=router_id)
        except cisco_exc.NexusPortBindingNotFound:
            self._client.create_vlan_svi(vlan_id, _nexus_ip, _nexus_username,
                                         _nexus_password, _nexus_ssh_port,
                                         gateway_ip)
            nxos_db.add_nexusport_binding('router', str(vlan_id), switch_ip,
                                          router_id)

            return True
Пример #12
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       host, instance):
        """Create network.

        Create a VLAN in the appropriate switch/port, and configure the
        appropriate interfaces for this VLAN.
        """
        LOG.debug(_("NexusPlugin:create_network() called"))
        # 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 cisco_exc.NexusComputeHostNotConfigured(host=host)

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

        try:
            nxos_db.get_port_vlan_switch_binding(port_id, vlan_id, switch_ip)
        except cisco_exc.NexusPortBindingNotFound:
            _nexus_ip = switch_ip
            _nexus_ports = (port_id, )
            _nexus_ssh_port = \
                self._nexus_switches[switch_ip, 'ssh_port']
            _nexus_creds = self.get_credential(_nexus_ip)
            _nexus_username = _nexus_creds['username']
            _nexus_password = _nexus_creds['password']
            # Check for vlan/switch binding
            try:
                nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            except cisco_exc.NexusPortBindingNotFound:
                # Create vlan and trunk vlan on the port
                self._client.create_vlan(vlan_name, str(vlan_id), _nexus_ip,
                                         _nexus_username, _nexus_password,
                                         _nexus_ports, _nexus_ssh_port,
                                         vlan_id)
                vlan_created = True
            else:
                # Only trunk vlan on the port
                man = self._client.nxos_connect(_nexus_ip,
                                                int(_nexus_ssh_port),
                                                _nexus_username,
                                                _nexus_password)
                self._client.enable_vlan_on_trunk_int(man, _nexus_ip, port_id,
                                                      vlan_id)
                vlan_enabled = True

        try:
            nxos_db.add_nexusport_binding(port_id, str(vlan_id), switch_ip,
                                          instance)
        except Exception as e:
            try:
                # Add binding failed, roll back any vlan creation/enabling
                if vlan_created:
                    self._client.delete_vlan(str(vlan_id), _nexus_ip,
                                             _nexus_username, _nexus_password,
                                             _nexus_ports, _nexus_ssh_port)
                if vlan_enabled:
                    self._client.disable_vlan_on_trunk_int(
                        man, port_id, vlan_id)
            finally:
                # Raise the original exception
                raise e

        new_net_dict = {
            const.NET_ID: net_id,
            const.NET_NAME: net_name,
            const.NET_PORTS: {},
            const.NET_VLAN_NAME: vlan_name,
            const.NET_VLAN_ID: vlan_id
        }
        self._networks[net_id] = new_net_dict
        return new_net_dict
Пример #13
0
    def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id,
                       host, instance):
        """Create network.

        Create a VLAN in the appropriate switch/port, and configure the
        appropriate interfaces for this VLAN.
        """
        LOG.debug(_("NexusPlugin:create_network() called"))
        # 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 cisco_exc.NexusComputeHostNotConfigured(host=host)

        # Check if this network is already in the DB
        binding = nxos_db.get_port_vlan_switch_binding(
            port_id, vlan_id, switch_ip)
        vlan_created = False
        vlan_enabled = False
        if not binding:
            _nexus_ip = switch_ip
            _nexus_ports = (port_id,)
            _nexus_ssh_port = \
                self._nexus_switches[switch_ip, 'ssh_port']
            _nexus_creds = self.get_credential(_nexus_ip)
            _nexus_username = _nexus_creds['username']
            _nexus_password = _nexus_creds['password']
            # Check for vlan/switch binding
            vbinding = nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
            if not vbinding:
                # Create vlan and trunk vlan on the port
                self._client.create_vlan(
                    vlan_name, str(vlan_id), _nexus_ip,
                    _nexus_username, _nexus_password,
                    _nexus_ports, _nexus_ssh_port, vlan_id)
                vlan_created = True
            else:
                # Only trunk vlan on the port
                man = self._client.nxos_connect(_nexus_ip,
                                                int(_nexus_ssh_port),
                                                _nexus_username,
                                                _nexus_password)
                self._client.enable_vlan_on_trunk_int(man,
                                                      port_id,
                                                      vlan_id)
                vlan_enabled = True

        try:
            nxos_db.add_nexusport_binding(port_id, str(vlan_id),
                                          switch_ip, instance)
        except Exception as e:
            try:
                # Add binding failed, roll back any vlan creation/enabling
                if vlan_created:
                    self._client.delete_vlan(
                        str(vlan_id), _nexus_ip,
                        _nexus_username, _nexus_password,
                        _nexus_ports, _nexus_ssh_port)
                if vlan_enabled:
                    self._client.disable_vlan_on_trunk_int(man,
                                                           port_id,
                                                           vlan_id)
            finally:
                # Raise the original exception
                raise e

        new_net_dict = {const.NET_ID: net_id,
                        const.NET_NAME: net_name,
                        const.NET_PORTS: {},
                        const.NET_VLAN_NAME: vlan_name,
                        const.NET_VLAN_ID: vlan_id}
        self._networks[net_id] = new_net_dict
        return new_net_dict