def delete_network(self, tenant_id, net_id, **kwargs): """ Deletes a VLAN in the switch, and removes the VLAN configuration from the relevant interfaces """ LOG.debug("NexusPlugin:delete_network() called\n") vlan_id = None for key in kwargs: if key == const.CONTEXT: context = kwargs[const.CONTEXT] elif key == const.BASE_PLUGIN_REF: base_plugin_ref = kwargs[const.BASE_PLUGIN_REF] elif key == 'vlan_id': vlan_id = kwargs['vlan_id'] if vlan_id is None: vlan_id = self._get_vlan_id_for_network(tenant_id, net_id, context, base_plugin_ref) ports_id = nxos_db.get_nexusport_binding(vlan_id) LOG.debug("NexusPlugin: Interfaces to be disassociated: %s" % ports_id) nxos_db.remove_nexusport_binding(vlan_id) if net_id: self._client.delete_vlan( str(vlan_id), self._nexus_ip, self._nexus_username, self._nexus_password, self._nexus_ports, self._nexus_ssh_port) return net_id # Network not found raise exc.NetworkNotFound(net_id=net_id)
def delete_port(self, device_id, vlan_id): """ Delete port bindings from the database and scan whether the network is still required on the interfaces trunked """ LOG.debug("NexusPlugin:delete_port() called\n") # Delete DB row for this port row = nxos_db.get_nexusvm_binding(vlan_id, device_id) if row: 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 bindings = nxos_db.get_nexusvlan_binding( row['vlan_id'], row['switch_ip']) if not bindings: # Delete this vlan from this switch _nexus_ip = row['switch_ip'] _nexus_ports = (row['port_id'],) _nexus_ssh_port = \ self._nexus_switches[_nexus_ip]['ssh_port']['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) return row['instance_id']
def delete_port(self, device_id, vlan_id): """ 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 row = nxos_db.get_nexusvm_binding(vlan_id, device_id) if row: 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 bindings = nxos_db.get_nexusvlan_binding( row['vlan_id'], row['switch_ip']) if not bindings: # Delete this vlan from this switch _nexus_ip = row['switch_ip'] _nexus_ports = (row['port_id'],) _nexus_ssh_port = \ self._nexus_switches[_nexus_ip]['ssh_port']['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) return row['instance_id']
def delete_network(self, tenant_id, net_id, **kwargs): """ Deletes a VLAN in the switch, and removes the VLAN configuration from the relevant interfaces """ LOG.debug("NexusPlugin:delete_network() called\n") vlan_id = None for key in kwargs: if key == const.CONTEXT: context = kwargs[const.CONTEXT] elif key == const.BASE_PLUGIN_REF: base_plugin_ref = kwargs[const.BASE_PLUGIN_REF] elif key == 'vlan_id': vlan_id = kwargs['vlan_id'] if vlan_id is None: vlan_id = self._get_vlan_id_for_network(tenant_id, net_id, context, base_plugin_ref) ports_id = nxos_db.get_nexusport_binding(vlan_id) LOG.debug("NexusPlugin: Interfaces to be disassociated: %s" % ports_id) nxos_db.remove_nexusport_binding(vlan_id) if net_id: self._client.delete_vlan( str(vlan_id), self._nexus_ip, self._nexus_username, self._nexus_password, self._nexus_ports, self._nexus_ssh_port) return net_id # Network not found raise exc.NetworkNotFound(net_id=net_id)
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']
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']
def delete_nexusportbinding(self, vlan_id): """delete nexus port binding.""" bindings = [] try: bind = nexus_db.remove_nexusport_binding(vlan_id) for res in bind: LOG.debug("Deleted nexus port binding: %s" % res.vlan_id) bind_dict = {} bind_dict["port-id"] = res.port_id bindings.append(bind_dict) return bindings except Exception, exc: raise Exception("Failed to delete nexus port binding: %s" % str(exc))
def delete_nexusportbinding(self, vlan_id): """Delete nexus port binding.""" bindings = [] try: bind = nexus_db.remove_nexusport_binding(vlan_id) for res in bind: LOG.debug("Deleted nexus port binding: %s" % res.vlan_id) bind_dict = {} bind_dict["port-id"] = res.port_id bindings.append(bind_dict) return bindings except Exception as exc: raise Exception("Failed to delete nexus port binding: %s" % str(exc))