def test_list_ports(self, tenant_id='test_network'): """ Tests listing of all the Ports. """ LOG.debug("test_list_ports - START") new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) port_dict = self._l2network_plugin.create_port( tenant_id, new_net_dict[const.NET_ID], self.state) port_dict2 = self._l2network_plugin.create_port( tenant_id, new_net_dict[const.NET_ID], self.state) port_list = self._l2network_plugin.get_all_ports( tenant_id, new_net_dict[const.NET_ID]) port_temp_list = [port_dict, port_dict2] network = db.network_get(new_net_dict[const.NET_ID]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = self._make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) ports_on_net.append(new_port) self.assertEqual(len(port_list), 2) self.assertTrue(port_list[0] in port_temp_list) self.assertTrue(port_list[1] in port_temp_list) self.assertTrue(ports_on_net[0] in port_temp_list) self.assertTrue(ports_on_net[1] in port_temp_list) self.tearDownPortOnly(tenant_id, new_net_dict[const.NET_ID], port_dict[const.PORT_ID]) self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID], port_dict2[const.PORT_ID]) LOG.debug("test_list_ports - END")
def delete_network(self, tenant_id, net_id): """ Deletes the network with the specified network identifier belonging to the specified tenant. """ LOG.debug("delete_network() called\n") net = db.network_get(net_id) if net: if len(net[const.NETWORKPORTS]) > 0: ports_on_net = db.port_list(net_id) for port in ports_on_net: if port[const.INTERFACEID]: raise exc.NetworkInUse(net_id=net_id) for port in ports_on_net: self.delete_port(tenant_id, net_id, port[const.UUID]) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id]) net_dict = cutil.make_net_dict(net[const.UUID], net[const.NETWORKNAME], []) self._release_vlan_for_tenant(tenant_id, net_id) cdb.remove_vlan_binding(net_id) db.network_destroy(net_id) return net_dict # Network not found raise exc.NetworkNotFound(net_id=net_id)
def test_list_ports(self, tenant_id='test_network'): """ Tests listing of all the Ports. """ LOG.debug("test_list_ports - START") new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) port_dict = self._l2network_plugin.create_port( tenant_id, new_net_dict[const.NET_ID], self.port_state) port_dict2 = self._l2network_plugin.create_port( tenant_id, new_net_dict[const.NET_ID], self.port_state) port_list = self._l2network_plugin.get_all_ports( tenant_id, new_net_dict[const.NET_ID]) port_temp_list = [port_dict, port_dict2] network = db.network_get(new_net_dict[const.NET_ID]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = self._make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) ports_on_net.append(new_port) self.assertEqual(len(port_list), 2) self.assertTrue(port_list[0] in port_temp_list) self.assertTrue(port_list[1] in port_temp_list) self.assertTrue(ports_on_net[0] in port_temp_list) self.assertTrue(ports_on_net[1] in port_temp_list) self.tearDownPortOnly(tenant_id, new_net_dict[const.NET_ID], port_dict[const.PORT_ID]) self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID], port_dict2[const.PORT_ID]) LOG.debug("test_list_ports - END")
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Provides connectivity to a remote interface to the specified Virtual Network. """ LOG.debug("plug_interface() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if attachment_id == None: raise cexc.InvalidAttach(port_id=port_id, net_id=net_id, att_id=remote_interface_id) attachment_id = attachment_id[:const.UUID_LENGTH] remote_interface_id = remote_interface_id[:const.UUID_LENGTH] if remote_interface_id != attachment_id: LOG.debug("Existing attachment_id:%s, remote_interface_id:%s" % \ (attachment_id, remote_interface_id)) raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id, attachment_id]) db.port_unset_attachment(net_id, port_id) db.port_set_attachment(net_id, port_id, attachment_id)
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Provides connectivity to a remote interface to the specified Virtual Network. """ LOG.debug("plug_interface() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if attachment_id is None: raise cexc.InvalidAttach(port_id=port_id, net_id=net_id, att_id=remote_interface_id) attachment_id = attachment_id[:const.UUID_LENGTH] remote_interface_id = remote_interface_id[:const.UUID_LENGTH] if remote_interface_id != attachment_id: LOG.debug("Existing attachment_id:%s, remote_interface_id:%s" % \ (attachment_id, remote_interface_id)) raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id, attachment_id]) db.port_unset_attachment(net_id, port_id) db.port_set_attachment(net_id, port_id, attachment_id)
def unplug_interface(self, tenant_id, net_id, port_id): """ Detaches a remote interface from the specified port on the specified Virtual Network. """ LOG.debug("unplug_interface() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) db.port_unset_attachment(net_id, port_id)
def update_network(self, tenant_id, net_id, **kwargs): """ Updates the symbolic name belonging to a particular Virtual Network. """ LOG.debug("UCSVICPlugin:update_network() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) network = db.network_get(net_id) net_dict = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], []) return net_dict
def update_port(self, tenant_id, net_id, port_id, **kwargs): """ Updates the state of a port on the specified Virtual Network. """ LOG.debug("update_port() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id, kwargs]) self._validate_port_state(kwargs["state"]) db.port_update(port_id, net_id, **kwargs) new_port_dict = cutil.make_port_dict(port_id, kwargs["state"], net_id, None) return new_port_dict
def _get_network(self, tenant_id, network_id): """ Gets the NETWORK ID """ network = db.network_get(network_id) if not network: raise exc.NetworkNotFound(net_id=network_id) vlan = cdb.get_vlan_binding(network_id) return {const.NET_ID: network_id, const.NET_NAME: network.name, const.NET_PORTS: network.ports, const.NET_VLAN_NAME: vlan.vlan_name, const.NET_VLAN_ID: vlan.vlan_id}
def create_network(self, tenant_id, net_name, net_id, vlan_name, vlan_id, **kwargs): """ Creates a new Virtual Network, and assigns it a symbolic name. """ LOG.debug("UCSVICPlugin:create_network() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) self._driver.create_vlan(vlan_name, str(vlan_id), self._ucsm_ip, self._ucsm_username, self._ucsm_password) network = db.network_get(net_id) ports_on_net = [] new_network_dict = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], ports_on_net) return new_network_dict
def get_network(self, network_id): """Get a network""" net = [] try: for net in db.network_get(network_id): LOG.debug("Getting network: %s" % net.uuid) net_dict = {} net_dict["tenant-id"] = net.tenant_id net_dict["net-id"] = str(net.uuid) net_dict["net-name"] = net.name net.append(net_dict) except Exception, exc: LOG.error("Failed to get network: %s" % str(exc))
def get_port_details(self, tenant_id, net_id, port_id): """ This method allows the user to retrieve a remote interface that is attached to this particular port. """ LOG.debug("get_port_details() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) port = db.port_get(net_id, port_id) new_port_dict = cutil.make_port_dict( port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID] ) return new_port_dict
def delete_network(self, tenant_id, net_id, **kwargs): """ Deletes the network with the specified network identifier belonging to the specified tenant. """ LOG.debug("UCSVICPlugin:delete_network() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) net = db.network_get(net_id) vlan_binding = cdb.get_vlan_binding(net[const.UUID]) vlan_name = vlan_binding[const.VLANNAME] self._driver.delete_vlan(vlan_name, self._ucsm_ip, self._ucsm_username, self._ucsm_password) net_dict = cutil.make_net_dict(net[const.UUID], net[const.NETWORKNAME], []) return net_dict
def delete_service(tenant_id, service_instance_id, *args): """ Removes a service and all the network configuration """ l2db.initialize() print("Terminating Service VM") service_logic = servlogcs.ServicesLogistics() vms_list = [] vms_list.append(servconts.DELETE_VM_CMD) vms_list.append(service_instance_id) if not service_logic.image_exist(service_instance_id): print("Service VM does not exist") sys.exit() result = subprocess.call(vms_list) service_logic.image_shutdown_verification(service_instance_id) client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) service_nets = sdb.get_service_bindings(service_instance_id) print("Terminating Ports and Networks") network_name = db.network_get(service_nets.mngnet_id) port_id_net = db.port_list(service_nets.mngnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.mngnet_id, ports_uuid.uuid) client.delete_network(service_nets.mngnet_id) network_name = db.network_get(service_nets.nbnet_id) port_id_net = db.port_list(service_nets.nbnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.nbnet_id, ports_uuid.uuid) client.delete_network(service_nets.nbnet_id) network_name = db.network_get(service_nets.sbnet_id) port_id_net = db.port_list(service_nets.sbnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.sbnet_id, ports_uuid.uuid) client.delete_network(service_nets.sbnet_id) service_list = sdb.remove_services_binding(service_instance_id) print("Configuration Removed Successfully")
def delete_service(tenant_id, service_instance_id, *args): """ Removes a service and all the network configuration """ l2db.initialize() print ("Terminating Service VM") service_logic = servlogcs.ServicesLogistics() vms_list = [] vms_list.append(servconts.DELETE_VM_CMD) vms_list.append(service_instance_id) if not service_logic.image_exist(service_instance_id): print ("Service VM does not exist") sys.exit() result = subprocess.call(vms_list) service_logic.image_shutdown_verification(service_instance_id) client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) service_nets = sdb.get_service_bindings(service_instance_id) print ("Terminating Ports and Networks") network_name = db.network_get(service_nets.mngnet_id) port_id_net = db.port_list(service_nets.mngnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.mngnet_id, ports_uuid.uuid) client.delete_network(service_nets.mngnet_id) network_name = db.network_get(service_nets.nbnet_id) port_id_net = db.port_list(service_nets.nbnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.nbnet_id, ports_uuid.uuid) client.delete_network(service_nets.nbnet_id) network_name = db.network_get(service_nets.sbnet_id) port_id_net = db.port_list(service_nets.sbnet_id) for ports_uuid in port_id_net: client.delete_port(service_nets.sbnet_id, ports_uuid.uuid) client.delete_network(service_nets.sbnet_id) service_list = sdb.remove_services_binding(service_instance_id) print ("Configuration Removed Successfully")
def get_port_details(self, tenant_id, net_id, port_id): """ This method allows the user to retrieve a remote interface that is attached to this particular port. """ LOG.debug("get_port_details() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) port = db.port_get(net_id, port_id) new_port_dict = cutil.make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) return new_port_dict
def get_all_ports(self, tenant_id, net_id, **kwargs): """ Retrieves all port identifiers belonging to the specified Virtual Network. """ LOG.debug("UCSVICPlugin:get_all_ports() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) network = db.network_get(net_id) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: port_binding = udb.get_portbinding(port[const.UUID]) ports_on_net.append(port_binding) return ports_on_net
def unplug_interface(self, tenant_id, net_id, port_id): """ Removes connectivity of a remote interface to the specified Virtual Network. """ LOG.debug("unplug_interface() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if attachment_id == None: raise exc.InvalidDetach(port_id=port_id, net_id=net_id, att_id=remote_interface_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) attachment_id = attachment_id[: const.UUID_LENGTH] attachment_id = attachment_id + const.UNPLUGGED db.port_unset_attachment(net_id, port_id) db.port_set_attachment(net_id, port_id, attachment_id)
def get_all_ports(self, tenant_id, net_id): """ Retrieves all port identifiers belonging to the specified Virtual Network. """ LOG.debug("get_all_ports() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict( port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID] ) ports_on_net.append(new_port) return ports_on_net
def get_network_details(self, tenant_id, net_id): """ Gets the details of a particular network """ LOG.debug("get_network_details() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict( port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID] ) ports_on_net.append(new_port) new_network = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], ports_on_net) return new_network
def get_all_ports(self, tenant_id, net_id): """ Retrieves all port identifiers belonging to the specified Virtual Network. """ LOG.debug("get_all_ports() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) ports_on_net.append(new_port) return ports_on_net
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): """ Attaches a remote interface to the specified port on the specified Virtual Network. """ LOG.debug("plug_interface() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if attachment_id and remote_interface_id != attachment_id: raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id, remote_interface_id]) if attachment_id == None: db.port_set_attachment(net_id, port_id, remote_interface_id)
def delete_port(self, tenant_id, net_id, port_id): """ Deletes a port on a specified Virtual Network, if the port contains a remote interface attachment, the remote interface should first be un-plugged and then the port can be deleted. """ LOG.debug("delete_port() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if not attachment_id: self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) db.port_destroy(net_id, port_id) new_port_dict = cutil.make_port_dict(port_id, None, None, None) return new_port_dict else: raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id)
def unplug_interface(self, tenant_id, net_id, port_id): """ Removes connectivity of a remote interface to the specified Virtual Network. """ LOG.debug("unplug_interface() called\n") network = db.network_get(net_id) port = db.port_get(net_id, port_id) attachment_id = port[const.INTERFACEID] if attachment_id is None: raise exc.InvalidDetach(port_id=port_id, net_id=net_id, att_id=remote_interface_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id]) attachment_id = attachment_id[:const.UUID_LENGTH] attachment_id = attachment_id + const.UNPLUGGED db.port_unset_attachment(net_id, port_id) db.port_set_attachment(net_id, port_id, attachment_id)
def tearDown(self): """Tear down our tests""" try: port = db.port_get(self.net_id, self.port_id) self._l2network_multiblade.delete_port([tenant_id, self.net_id, self.port_id]) except exc.NetworkNotFound: # We won't always have a port to remove pass except exc.PortNotFound: # We won't always have a port to remove pass try: net = db.network_get(self.net_id) self._l2network_multiblade.delete_network([tenant_id, self.net_id]) except exc.NetworkNotFound: # We won't always have a network to remove pass db.clear_db()
def get_network_details(self, tenant_id, net_id, **kwargs): """ Deletes the Virtual Network belonging to a the spec """ LOG.debug("UCSVICPlugin:get_network_details() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) network = db.network_get(net_id) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict( port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID] ) ports_on_net.append(new_port) new_network = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], ports_on_net) return new_network
def test_rename_network(self, net_tenant_id=None, new_name='new_test_network'): """ Tests rename of a Virtual Network . """ LOG.debug("test_rename_network - START") if net_tenant_id: tenant_id = net_tenant_id else: tenant_id = self.tenant_id new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) rename_net_dict = self._l2network_plugin.rename_network( tenant_id, new_net_dict[const.NET_ID], new_name) net = db.network_get(new_net_dict[const.NET_ID]) self.assertEqual(net[const.NETWORKNAME], new_name) self.assertEqual(new_name, rename_net_dict[const.NET_NAME]) self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_rename_network - END")
def test_show_network(self, net_tenant_id=None): """ Tests display of details of a Virtual Network . """ LOG.debug("test_show_network - START") if net_tenant_id: tenant_id = net_tenant_id else: tenant_id = self.tenant_id new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) result_net_dict = self._l2network_plugin.get_network_details( tenant_id, new_net_dict[const.NET_ID]) net = db.network_get(new_net_dict[const.NET_ID]) self.assertEqual(net[const.UUID], new_net_dict[const.NET_ID]) self.assertEqual(new_net_dict[const.NET_ID], result_net_dict[const.NET_ID]) self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_show_network - END")
def test_show_network(self, net_tenant_id=None): """ Tests display of details of a Virtual Network . """ LOG.debug("test_show_network - START") if net_tenant_id: tenant_id = net_tenant_id else: tenant_id = self.tenant_id new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) result_net_dict = self._l2network_plugin.get_network_details( tenant_id, new_net_dict[const.NET_ID]) net = db.network_get(new_net_dict[const.NET_ID]) self.assertEqual(net[const.UUID], new_net_dict[const.NET_ID]) self.assertEqual( new_net_dict[const.NET_ID], result_net_dict[const.NET_ID]) self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_show_network - END")
def tearDown(self): """Tear down our tests""" try: port = db.port_get(self.net_id, self.port_id) self._l2network_multiblade.delete_port( [tenant_id, self.net_id, self.port_id]) except exc.NetworkNotFound: # We won't always have a port to remove pass except exc.PortNotFound: # We won't always have a port to remove pass try: net = db.network_get(self.net_id) self._l2network_multiblade.delete_network([tenant_id, self.net_id]) except exc.NetworkNotFound: # We won't always have a network to remove pass db.clear_db()
def test_update_network(self, net_tenant_id=None, new_name='new_test_network'): """ Tests rename of a Virtual Network . """ LOG.debug("test_update_network - START") if net_tenant_id: tenant_id = net_tenant_id else: tenant_id = self.tenant_id new_net_dict = self._l2network_plugin.create_network( tenant_id, self.network_name) rename_net_dict = self._l2network_plugin.update_network( tenant_id, new_net_dict[const.NET_ID], name=new_name) net = db.network_get(new_net_dict[const.NET_ID]) self.assertEqual(net[const.NETWORKNAME], new_name) self.assertEqual(new_name, rename_net_dict[const.NET_NAME]) self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_update_network - END")
def test_create_network(self, net_tenant_id=None, net_name=None): """ Tests creation of new Virtual Network. """ LOG.debug("test_create_network - START") if net_tenant_id: tenant_id = net_tenant_id else: tenant_id = self.tenant_id if net_name: network_name = net_name else: network_name = self.network_name new_net_dict = self._l2network_plugin.create_network( tenant_id, network_name) net = db.network_get(new_net_dict[const.NET_ID]) self.assertEqual(net[const.NETWORKNAME], network_name) self.assertEqual(new_net_dict[const.NET_NAME], network_name) self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_create_network - END")
def get_network_details(self, tenant_id, net_id): """ Gets the details of a particular network """ LOG.debug("get_network_details() called\n") network = db.network_get(net_id) self._invoke_device_plugins(self._func_name(), [tenant_id, net_id]) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) ports_on_net.append(new_port) new_network = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], ports_on_net) return new_network
def get_network_details(self, tenant_id, net_id, **kwargs): """ Deletes the Virtual Network belonging to a the spec """ LOG.debug("UCSVICPlugin:get_network_details() called\n") self._set_ucsm(kwargs[const.DEVICE_IP]) network = db.network_get(net_id) ports_list = network[const.NETWORKPORTS] ports_on_net = [] for port in ports_list: new_port = cutil.make_port_dict(port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]) ports_on_net.append(new_port) new_network = cutil.make_net_dict(network[const.UUID], network[const.NETWORKNAME], ports_on_net) return new_network