def _schedule(self, context, topic, request_spec, **kwargs): """Gets the host name from the Quantum service""" LOG.debug("Cisco Quantum Port-aware Scheduler is scheduling...") instance_id = request_spec['instance_properties']['uuid'] user_id = request_spec['instance_properties']['user_id'] project_id = request_spec['instance_properties']['project_id'] instance_data_dict = {'novatenant': {'instance_id': instance_id, 'instance_desc': {'user_id': user_id, 'project_id': project_id}}} client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix=URI_PREFIX_CSCO, tenant=TENANT_ID, logger=LOG) request_url = "/novatenants/" + project_id + ACTION data = client.do_request('PUT', request_url, body=instance_data_dict) hostname = data["host_list"]["host_1"] if not hostname: raise excp.NoValidHost(_("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?")) LOG.debug(_("Quantum service returned host: %s") % hostname) return hostname
def schedule_host(tenant_id, instance_id, user_id=None): """Gets the host name from the Quantum service""" project_id = tenant_id instance_data_dict = { 'novatenant': { 'instance_id': instance_id, 'instance_desc': { 'user_id': user_id, 'project_id': project_id, }, }, } request_url = "/novatenants/" + project_id + "/schedule_host" client = Client(HOST, PORT, USE_SSL, format='json', tenant=TENANT_ID, version=VERSION, uri_prefix=URI_PREFIX_CSCO) data = client.do_request('PUT', request_url, body=instance_data_dict) hostname = data["host_list"]["host_1"] if not hostname: print("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?") print("Quantum service returned host: %s" % hostname)
def __init__(self): # We have to send a dummy tenant name here since the client # needs some tenant name, but the tenant name will not be used # since the extensions URL does not require it LOG.debug("Initializing Cisco Quantum VIF driver...") client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix="", tenant="dummy", logger=LOG) request_url = "/extensions" data = client.do_request('GET', request_url) LOG.debug("Obtained supported extensions from Quantum: %s" % data) for ext in data['extensions']: name = ext['name'] if name == CSCO_EXT_NAME: LOG.debug("Quantum plugin supports required \"%s\" extension" "for the VIF driver." % name) return LOG.error("Quantum plugin does not support required \"%s\" extension" " for the VIF driver. nova-compute will quit." % CSCO_EXT_NAME) raise excp.ServiceUnavailable()
def schedule_host(tenant_id, instance_id, user_id=None): """Gets the host name from the Quantum service""" project_id = tenant_id instance_data_dict = { 'novatenant': { 'instance_id': instance_id, 'instance_desc': { 'user_id': user_id, 'project_id': project_id, }, }, } request_url = "/novatenants/" + project_id + "/schedule_host" client = Client(HOST, PORT, USE_SSL, format='json', tenant=TENANT_ID, version=VERSION, uri_prefix=URI_PREFIX_CSCO) data = client.do_request('PUT', request_url, body=instance_data_dict) hostname = data["host_list"]["host_1"] if not hostname: print( "Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?") print("Quantum service returned host: %s" % hostname)
def list_extensions(*args): """Invoking the action to get the supported extensions""" request_url = "/extensions" client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix=URI_PREFIX_EXT, tenant="dummy") data = client.do_request('GET', request_url) print("Obtained supported extensions from Quantum: %s" % data)
def create_multiport(tenant_id, net_id_list, *args): """Creates ports on a single host""" net_list = net_id_list.split(",") ports_info = {"multiport": {"status": "ACTIVE", "net_id_list": net_list, "ports_desc": {"key": "value"}}} request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format="json", tenant=tenant_id, version=VERSION, uri_prefix=URI_PREFIX_CSCO) data = client.do_request("POST", request_url, body=ports_info) print ("Created ports: %s" % data)
def create_multiport(tenant_id, networks_list, *args): """Creates ports on a single host""" ports_info = {'multiport': {'status': constants.PORT_STATUS_ACTIVE, 'net_id_list': networks_list, 'ports_desc': {'key': 'value'}}} request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id, action_prefix=servconts.ACTION_PREFIX_CSCO) data = client.do_request('POST', request_url, body=ports_info) return data
def create_multiport(tenant_id, networks_list, *args): """Creates ports on a single host""" ports_info = { "multiport": { "status": constants.PORT_STATUS_ACTIVE, "net_id_list": networks_list, "ports_desc": {"key": "value"}, } } request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format="json", tenant=tenant_id, action_prefix=servconts.ACTION_PREFIX_CSCO) data = client.do_request("POST", request_url, body=ports_info) return data
def create_multiport(tenant_id, net_id_list, *args): """Creates ports on a single host""" net_list = net_id_list.split(",") ports_info = {'multiport': {'status': 'ACTIVE', 'net_id_list': net_list, 'ports_desc': {'key': 'value'}}} request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id, version=VERSION, uri_prefix=URI_PREFIX_CSCO) data = client.do_request('POST', request_url, body=ports_info) print("Created ports: %s" % data)
def setUp(self): """ Setups a test environment for the API client """ HOST = '127.0.0.1' PORT = 9696 USE_SSL = False self.client = Client(HOST, PORT, USE_SSL, TENANT_1, 'json', ServerStub)
def _update_configurations(self, instance, network, mapping, action): """Gets the device name and the profile name from Quantum""" LOG.debug("Cisco Quantum VIF driver performing: %s" % (action)) instance_id = instance['uuid'] user_id = instance['user_id'] project_id = instance['project_id'] vif_id = mapping['vif_uuid'] instance_data_dict = { 'novatenant': { 'instance_id': instance_id, 'instance_desc': { 'user_id': user_id, 'project_id': project_id, 'vif_id': vif_id } } } client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix=URI_PREFIX_CSCO, tenant=TENANT_ID, logger=LOG) request_url = "/novatenants/" + project_id + action data = client.do_request('PUT', request_url, body=instance_data_dict) if action == ASSOCIATE_ACTION: device = data['vif_desc']['device'] portprofile = data['vif_desc']['portprofile'] LOG.debug(_("Quantum provided the device: %s") % device) LOG.debug(_("Quantum provided the portprofile: %s") % portprofile) mac_id = mapping['mac'].replace(':', '') result = { 'id': mac_id, 'mac_address': mapping['mac'], 'device_name': device, 'profile_name': portprofile, } return result else: return data
def test_connection_retry_failure(self): self.client = Client(port=55555, tenant=TENANT_1, retries=1, retry_interval=0) try: self.client.list_networks() except exceptions.ConnectionFailed as exc: self.assertTrue('Maximum attempts reached' in str(exc)) else: self.fail('ConnectionFailed not raised')
def __init__(self): # We have to send a dummy tenant name here since the client # needs some tenant name, but the tenant name will not be used # since the extensions URL does not require it LOG.debug("Initializing Cisco Quantum Port-aware Scheduler...") client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix="", tenant="dummy", logger=LOG) request_url = "/extensions" data = client.do_request('GET', request_url) LOG.debug("Obtained supported extensions from Quantum: %s" % data) for ext in data['extensions']: name = ext['name'] if name == CSCO_EXT_NAME: LOG.debug("Quantum plugin supports required \"%s\" extension" "for the scheduler." % name) return LOG.error("Quantum plugin does not support required \"%s\" extension" " for the scheduler. Scheduler will quit." % CSCO_EXT_NAME) raise excp.ServiceUnavailable()
def create_multiport(tenant_id, networks_list, *args): """Creates ports on a single host""" ports_info = { 'multiport': { 'status': 'ACTIVE', 'net_id_list': networks_list, 'ports_desc': { 'key': 'value' } } } request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id, action_prefix=servconts.ACTION_PREFIX_CSCO) data = client.do_request('POST', request_url, body=ports_info) return data
def connect_vm(tenant_id, vm_image_id, service_instance_id, *args): """ Starts a VMs and is connected to southbound network """ l2db.initialize() client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) print("Connecting %s to Service %s " % (vm_image_id, service_instance_id)) service_logic = servlogcs.ServicesLogistics() service_nets = sdb.get_service_bindings(service_instance_id) client.create_port(service_nets.mngnet_id) client.create_port(service_nets.nbnet_id) sb_port_id = client.create_port(service_nets.sbnet_id) LOG.debug("Operation 'create_port' executed.") new_port_id = sb_port_id[servconts.PORT][servconts.ID] try: create_vm_args = [] create_vm_args.append(servconts.CREATE_VM_CMD) create_vm_args.append(vm_image_id) print("Creating VM with image: %s" % (vm_image_id)) process = utils.subprocess_popen(create_vm_args, stdout=subprocess.PIPE) result = process.stdout.readlines() tokens = re.search("i-[a-f0-9]*", str(result[1])) vm_name = tokens.group(0) print("Image: %s instantiated successfully" % (vm_name)) except Exception as exc: print exc service_logic.image_status(vm_name) print "Completed" print "Attaching Ports To VM Service interfaces" south_net = service_nets.sbnet_id attachment = client.show_port_attachment(south_net, new_port_id) attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36] LOG.debug(("Plugging virtual interface: %s of VM %s " "into port: %s on network: %s") % (attachment, vm_name, new_port_id, service_nets.sbnet_id)) attach_data = {servconts.ATTACHMENT: {servconts.ID: '%s' % attachment}} client.attach_resource(service_nets.sbnet_id, new_port_id, attach_data) print("Connect VM Ended")
def _update_configurations(self, instance, network, mapping, action): """Gets the device name and the profile name from Quantum""" LOG.debug("Cisco Quantum VIF driver performing: %s" % (action)) instance_id = instance['uuid'] user_id = instance['user_id'] project_id = instance['project_id'] vif_id = mapping['vif_uuid'] instance_data_dict = \ {'novatenant': \ {'instance_id': instance_id, 'instance_desc': \ {'user_id': user_id, 'project_id': project_id, 'vif_id': vif_id}}} client = Client(HOST, PORT, USE_SSL, format='json', version=VERSION, uri_prefix=URI_PREFIX_CSCO, tenant=TENANT_ID, logger=LOG) request_url = "/novatenants/" + project_id + action data = client.do_request('PUT', request_url, body=instance_data_dict) if action == ASSOCIATE_ACTION: device = data['vif_desc']['device'] portprofile = data['vif_desc']['portprofile'] LOG.debug(_("Quantum provided the device: %s") % device) LOG.debug(_("Quantum provided the portprofile: %s") % portprofile) mac_id = mapping['mac'].replace(':', '') result = { 'id': mac_id, 'mac_address': mapping['mac'], 'device_name': device, 'profile_name': portprofile, } return result else: return data
def connect_vm(tenant_id, vm_image_id, service_instance_id, *args): """ Starts a VMs and is connected to southbound network """ l2db.initialize() client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) print (_("Connecting %(vm_image_id)s to Service " "%(service_instance_id)s") % locals()) service_logic = servlogcs.ServicesLogistics() service_nets = sdb.get_service_bindings(service_instance_id) client.create_port(service_nets.mngnet_id) client.create_port(service_nets.nbnet_id) sb_port_id = client.create_port(service_nets.sbnet_id) LOG.debug(_("Operation 'create_port' executed.")) new_port_id = sb_port_id[servconts.PORT][servconts.ID] try: create_vm_args = [] create_vm_args.append(servconts.CREATE_VM_CMD) create_vm_args.append(vm_image_id) print _("Creating VM with image: %s") % (vm_image_id) process = utils.subprocess_popen(create_vm_args, stdout=subprocess.PIPE) result = process.stdout.readlines() tokens = re.search("i-[a-f0-9]*", str(result[1])) vm_name = tokens.group(0) print _("Image: %s instantiated successfully") % (vm_name) except Exception as exc: print exc service_logic.image_status(vm_name) print _("Completed") print _("Attaching Ports To VM Service interfaces") south_net = service_nets.sbnet_id attachment = client.show_port_attachment(south_net, new_port_id) attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36] LOG.debug(_("Plugging virtual interface: %(attachment)s of VM " "%(vm_name)s into port: %(new_port_id)s on network: " "%(sbnet_id)s"), {'attachment': attachment, 'vm_name': vm_name, 'new_port_id': new_port_id, 'sbnet_id': service_nets.sbnet_id}) attach_data = {servconts.ATTACHMENT: {servconts.ID: '%s' % attachment}} client.attach_resource(service_nets.sbnet_id, new_port_id, attach_data) print _("Connect VM Ended")
def create_multiport(tenant_id, net_id_list, *args): """Creates ports on a single host""" net_list = net_id_list.split(",") ports_info = { 'multiport': { 'status': 'ACTIVE', 'net_id_list': net_list, 'ports_desc': { 'key': 'value' } } } request_url = "/multiport" client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id, version=VERSION, uri_prefix=URI_PREFIX_CSCO) data = client.do_request('POST', request_url, body=ports_info) print("Created ports: %s" % data)
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")
class APITest(unittest.TestCase): def setUp(self): """ Setups a test environment for the API client """ HOST = '127.0.0.1' PORT = 9696 USE_SSL = False self.client = Client(HOST, PORT, USE_SSL, TENANT_1, 'json', ServerStub) def _assert_sanity(self, call, status, method, path, data=[], params={}): """ Perform common assertions to test the sanity of client requests """ # Handle an error case first if status != 200: (self.client.host, self.client.port) = ("10.0.0.1", status) self.assertRaises(Exception, call, *data, **params) return # Make the call, then get the data from the root node and assert it data = call(*data, **params)['data'] self.assertEqual(data['method'], method) self.assertEqual(data['format'], params['format']) self.assertEqual(data['tenant'], params['tenant']) self.assertEqual(data['path'], path) return data def _test_list_networks(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_list_networks - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.list_networks, status, "GET", "networks", data=[], params={'tenant': tenant, 'format': format}) LOG.debug("_test_list_networks - tenant:%s - format:%s - END", format, tenant) def _test_list_networks_details(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_list_networks_details - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.list_networks_details, status, "GET", "networks/detail", data=[], params={'tenant': tenant, 'format': format}) LOG.debug("_test_list_networks_details - tenant:%s " "- format:%s - END", format, tenant) def _test_show_network(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_show_network - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.show_network, status, "GET", "networks/001", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_show_network - tenant:%s " "- format:%s - END", format, tenant) def _test_show_network_details(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_show_network_details - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.show_network_details, status, "GET", "networks/001/detail", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_show_network_details - tenant:%s " "- format:%s - END", format, tenant) def _test_create_network(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_create_network - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.create_network, status, "POST", "networks", data=[{'network': {'net-name': 'testNetwork'}}], params={'tenant': tenant, 'format': format}) LOG.debug("_test_create_network - tenant:%s " "- format:%s - END", format, tenant) def _test_update_network(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_update_network - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.update_network, status, "PUT", "networks/001", data=["001", {'network': {'net-name': 'newName'}}], params={'tenant': tenant, 'format': format}) LOG.debug("_test_update_network - tenant:%s " "- format:%s - END", format, tenant) def _test_delete_network(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_delete_network - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.delete_network, status, "DELETE", "networks/001", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_delete_network - tenant:%s " "- format:%s - END", format, tenant) def _test_list_ports(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_list_ports - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.list_ports, status, "GET", "networks/001/ports", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_list_ports - tenant:%s " "- format:%s - END", format, tenant) def _test_list_ports_details(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_list_ports_details - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.list_ports_details, status, "GET", "networks/001/ports/detail", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_list_ports_details - tenant:%s " "- format:%s - END", format, tenant) def _test_show_port(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_show_port - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.show_port, status, "GET", "networks/001/ports/001", data=["001", "001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_show_port - tenant:%s " "- format:%s - END", format, tenant) def _test_show_port_details(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_show_port_details - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.show_port_details, status, "GET", "networks/001/ports/001/detail", data=["001", "001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_show_port_details - tenant:%s " "- format:%s - END", format, tenant) def _test_create_port(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_create_port - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.create_port, status, "POST", "networks/001/ports", data=["001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_create_port - tenant:%s " "- format:%s - END", format, tenant) def _test_delete_port(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_delete_port - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.delete_port, status, "DELETE", "networks/001/ports/001", data=["001", "001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_delete_port - tenant:%s " "- format:%s - END", format, tenant) def _test_update_port(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_update_port - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.update_port, status, "PUT", "networks/001/ports/001", data=["001", "001", {'port': {'state': 'ACTIVE'}}], params={'tenant': tenant, 'format': format}) LOG.debug("_test_update_port - tenant:%s " "- format:%s - END", format, tenant) def _test_show_port_attachment(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_show_port_attachment - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.show_port_attachment, status, "GET", "networks/001/ports/001/attachment", data=["001", "001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_show_port_attachment - tenant:%s " "- format:%s - END", format, tenant) def _test_attach_resource(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_attach_resource - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.attach_resource, status, "PUT", "networks/001/ports/001/attachment", data=["001", "001", {'resource': {'id': '1234'}}], params={'tenant': tenant, 'format': format}) LOG.debug("_test_attach_resource - tenant:%s " "- format:%s - END", format, tenant) def _test_detach_resource(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_detach_resource - tenant:%s " "- format:%s - START", format, tenant) self._assert_sanity(self.client.detach_resource, status, "DELETE", "networks/001/ports/001/attachment", data=["001", "001"], params={'tenant': tenant, 'format': format}) LOG.debug("_test_detach_resource - tenant:%s " "- format:%s - END", format, tenant) def _test_ssl_certificates(self, tenant=TENANT_1, format='json', status=200): LOG.debug("_test_ssl_certificates - tenant:%s " "- format:%s - START", format, tenant) # Set SSL, and our cert file self.client.use_ssl = True cert_file = "/fake.cert" self.client.key_file = self.client.cert_file = cert_file data = self._assert_sanity(self.client.list_networks, status, "GET", "networks", data=[], params={'tenant': tenant, 'format': format}) self.assertEquals(data["key_file"], cert_file) self.assertEquals(data["cert_file"], cert_file) LOG.debug("_test_ssl_certificates - tenant:%s " "- format:%s - END", format, tenant) def test_list_networks_json(self): self._test_list_networks(format='json') def test_list_networks_xml(self): self._test_list_networks(format='xml') def test_list_networks_alt_tenant(self): self._test_list_networks(tenant=TENANT_2) def test_list_networks_error_470(self): self._test_list_networks(status=470) def test_list_networks_error_401(self): self._test_list_networks(status=401) def test_list_networks_details_json(self): self._test_list_networks_details(format='json') def test_list_networks_details_xml(self): self._test_list_networks_details(format='xml') def test_list_networks_details_alt_tenant(self): self._test_list_networks_details(tenant=TENANT_2) def test_list_networks_details_error_470(self): self._test_list_networks_details(status=470) def test_list_networks_details_error_401(self): self._test_list_networks_details(status=401) def test_show_network_json(self): self._test_show_network(format='json') def test_show_network__xml(self): self._test_show_network(format='xml') def test_show_network_alt_tenant(self): self._test_show_network(tenant=TENANT_2) def test_show_network_error_470(self): self._test_show_network(status=470) def test_show_network_error_401(self): self._test_show_network(status=401) def test_show_network_error_420(self): self._test_show_network(status=420) def test_show_network_details_json(self): self._test_show_network_details(format='json') def test_show_network_details_xml(self): self._test_show_network_details(format='xml') def test_show_network_details_alt_tenant(self): self._test_show_network_details(tenant=TENANT_2) def test_show_network_details_error_470(self): self._test_show_network_details(status=470) def test_show_network_details_error_401(self): self._test_show_network_details(status=401) def test_show_network_details_error_420(self): self._test_show_network_details(status=420) def test_create_network_json(self): self._test_create_network(format='json') def test_create_network_xml(self): self._test_create_network(format='xml') def test_create_network_alt_tenant(self): self._test_create_network(tenant=TENANT_2) def test_create_network_error_470(self): self._test_create_network(status=470) def test_create_network_error_401(self): self._test_create_network(status=401) def test_create_network_error_400(self): self._test_create_network(status=400) def test_create_network_error_422(self): self._test_create_network(status=422) def test_update_network_json(self): self._test_update_network(format='json') def test_update_network_xml(self): self._test_update_network(format='xml') def test_update_network_alt_tenant(self): self._test_update_network(tenant=TENANT_2) def test_update_network_error_470(self): self._test_update_network(status=470) def test_update_network_error_401(self): self._test_update_network(status=401) def test_update_network_error_400(self): self._test_update_network(status=400) def test_update_network_error_420(self): self._test_update_network(status=420) def test_update_network_error_422(self): self._test_update_network(status=422) def test_delete_network_json(self): self._test_delete_network(format='json') def test_delete_network_xml(self): self._test_delete_network(format='xml') def test_delete_network_alt_tenant(self): self._test_delete_network(tenant=TENANT_2) def test_delete_network_error_470(self): self._test_delete_network(status=470) def test_delete_network_error_401(self): self._test_delete_network(status=401) def test_delete_network_error_420(self): self._test_delete_network(status=420) def test_delete_network_error_421(self): self._test_delete_network(status=421) def test_list_ports_json(self): self._test_list_ports(format='json') def test_list_ports_xml(self): self._test_list_ports(format='xml') def test_list_ports_alt_tenant(self): self._test_list_ports(tenant=TENANT_2) def test_list_ports_error_470(self): self._test_list_ports(status=470) def test_list_ports_error_401(self): self._test_list_ports(status=401) def test_list_ports_error_420(self): self._test_list_ports(status=420) def test_list_ports_details_json(self): self._test_list_ports_details(format='json') def test_list_ports_details_xml(self): self._test_list_ports_details(format='xml') def test_list_ports_details_alt_tenant(self): self._test_list_ports_details(tenant=TENANT_2) def test_list_ports_details_error_470(self): self._test_list_ports_details(status=470) def test_list_ports_details_error_401(self): self._test_list_ports_details(status=401) def test_list_ports_details_error_420(self): self._test_list_ports_details(status=420) def test_show_port_json(self): self._test_show_port(format='json') def test_show_port_xml(self): self._test_show_port(format='xml') def test_show_port_alt_tenant(self): self._test_show_port(tenant=TENANT_2) def test_show_port_error_470(self): self._test_show_port(status=470) def test_show_port_error_401(self): self._test_show_port(status=401) def test_show_port_error_420(self): self._test_show_port(status=420) def test_show_port_error_430(self): self._test_show_port(status=430) def test_show_port_details_json(self): self._test_show_port_details(format='json') def test_show_port_details_xml(self): self._test_show_port_details(format='xml') def test_show_port_details_alt_tenant(self): self._test_show_port_details(tenant=TENANT_2) def test_show_port_details_error_470(self): self._test_show_port_details(status=470) def test_show_port_details_error_401(self): self._test_show_port_details(status=401) def test_show_port_details_error_420(self): self._test_show_port_details(status=420) def test_show_port_details_error_430(self): self._test_show_port_details(status=430) def test_create_port_json(self): self._test_create_port(format='json') def test_create_port_xml(self): self._test_create_port(format='xml') def test_create_port_alt_tenant(self): self._test_create_port(tenant=TENANT_2) def test_create_port_error_470(self): self._test_create_port(status=470) def test_create_port_error_401(self): self._test_create_port(status=401) def test_create_port_error_400(self): self._test_create_port(status=400) def test_create_port_error_420(self): self._test_create_port(status=420) def test_create_port_error_430(self): self._test_create_port(status=430) def test_create_port_error_431(self): self._test_create_port(status=431) def test_delete_port_json(self): self._test_delete_port(format='json') def test_delete_port_xml(self): self._test_delete_port(format='xml') def test_delete_port_alt_tenant(self): self._test_delete_port(tenant=TENANT_2) def test_delete_port_error_470(self): self._test_delete_port(status=470) def test_delete_port_error_401(self): self._test_delete_port(status=401) def test_delete_port_error_420(self): self._test_delete_port(status=420) def test_delete_port_error_430(self): self._test_delete_port(status=430) def test_delete_port_error_432(self): self._test_delete_port(status=432) def test_update_port_json(self): self._test_update_port(format='json') def test_update_port_xml(self): self._test_update_port(format='xml') def test_update_port_alt_tenant(self): self._test_update_port(tenant=TENANT_2) def test_update_port_error_470(self): self._test_update_port(status=470) def test_update_port_error_401(self): self._test_update_port(status=401) def test_update_port_error_400(self): self._test_update_port(status=400) def test_update_port_error_420(self): self._test_update_port(status=420) def test_update_port_error_430(self): self._test_update_port(status=430) def test_update_port_error_431(self): self._test_update_port(status=431) def test_show_port_attachment_json(self): self._test_show_port_attachment(format='json') def test_show_port_attachment_xml(self): self._test_show_port_attachment(format='xml') def test_show_port_attachment_alt_tenant(self): self._test_show_port_attachment(tenant=TENANT_2) def test_show_port_attachment_error_470(self): self._test_show_port_attachment(status=470) def test_show_port_attachment_error_401(self): self._test_show_port_attachment(status=401) def test_show_port_attachment_error_400(self): self._test_show_port_attachment(status=400) def test_show_port_attachment_error_420(self): self._test_show_port_attachment(status=420) def test_show_port_attachment_error_430(self): self._test_show_port_attachment(status=430) def test_attach_resource_json(self): self._test_attach_resource(format='json') def test_attach_resource_xml(self): self._test_attach_resource(format='xml') def test_attach_resource_alt_tenant(self): self._test_attach_resource(tenant=TENANT_2) def test_attach_resource_error_470(self): self._test_attach_resource(status=470) def test_attach_resource_error_401(self): self._test_attach_resource(status=401) def test_attach_resource_error_400(self): self._test_attach_resource(status=400) def test_attach_resource_error_420(self): self._test_attach_resource(status=420) def test_attach_resource_error_430(self): self._test_attach_resource(status=430) def test_attach_resource_error_432(self): self._test_attach_resource(status=432) def test_attach_resource_error_440(self): self._test_attach_resource(status=440) def test_detach_resource_json(self): self._test_detach_resource(format='json') def test_detach_resource_xml(self): self._test_detach_resource(format='xml') def test_detach_resource_alt_tenant(self): self._test_detach_resource(tenant=TENANT_2) def test_detach_resource_error_470(self): self._test_detach_resource(status=470) def test_detach_resource_error_401(self): self._test_detach_resource(status=401) def test_detach_resource_error_420(self): self._test_detach_resource(status=420) def test_detach_resource_error_430(self): self._test_detach_resource(status=430) def test_ssl_certificates(self): self._test_ssl_certificates() def test_connection_retry_failure(self): self.client = Client(port=55555, tenant=TENANT_1, retries=1, retry_interval=0) try: self.client.list_networks() except exceptions.ConnectionFailed as exc: self.assertTrue('Maximum attempts reached' in str(exc)) else: self.fail('ConnectionFailed not raised')
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 insert_inpath_service(tenant_id, service_image_id, management_net_name, northbound_net_name, southbound_net_name, *args): """Inserting a network service between two networks""" print("Creating Network for Services and Servers") service_logic = servlogcs.ServicesLogistics() net_list = {} multiport_net_list = [] networks_name_list = [ management_net_name, northbound_net_name, southbound_net_name ] client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) for net in networks_name_list: data = {servconts.NETWORK: {servconts.NAME: net}} net_list[net] = client.create_network(data) net_list[net][servconts.PORTS] = [] LOG.debug("Network %s Created with ID: %s " % (net, net_list[net][servconts.NETWORK][servconts.ID])) print "Completed" print("Creating Ports on Services and Server Networks") LOG.debug("Operation 'create_port' executed.") if not service_logic.verify_plugin(const.UCS_PLUGIN): for net in networks_name_list: net_list[net][servconts.PORTS].append (client.create_port( net_list[net][servconts.NETWORK][servconts.ID])) LOG.debug("Operation 'create_port' executed.") else: for net in networks_name_list: nets = net_list[net][servconts.NETWORK][servconts.ID] multiport_net_list.append(nets) data = create_multiport(tenant_id, multiport_net_list) net_idx = 0 for net in networks_name_list: port_id = data[servconts.PORTS][net_idx][servconts.ID] net_list[net][servconts.PORTS].append(port_id) LOG.debug("Port UUID: %s on network: %s" % (data[servconts.PORTS][net_idx][servconts.ID], net)) net_idx = net_idx + 1 print "Completed" try: create_vm_args = [] create_vm_args.append(servconts.CREATE_VM_CMD) create_vm_args.append(service_image_id) print("Creating VM with image: %s" % (service_image_id)) process = subprocess.Popen(create_vm_args, stdout=subprocess.PIPE) result = process.stdout.readlines() tokens = re.search("i-[a-f0-9]*", str(result[1])) service_vm_name = tokens.group(0) print("Image: %s instantiated successfully" % (service_vm_name)) except Exception as exc: print exc service_logic.image_status(service_vm_name) print "Completed" print "Attaching Ports To VM Service interfaces" try: idx = 0 for net in networks_name_list: network_id = net_list[net][servconts.NETWORK][servconts.ID] port_id = net_list[net][servconts.PORTS][idx] attachment = client.show_port_attachment(network_id, port_id) attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36] LOG.debug(("Plugging virtual interface: %s of VM %s" "into port: %s on network: %s") % (attachment, service_vm_name, port_id, net)) attach_data = { servconts.ATTACHMENT: { servconts.ID: '%s' % attachment } } client.attach_resource(network_id, port_id, attach_data) except Exception as exc: print exc print "Completed" try: LOG.debug("Registering Service in DB") l2db.initialize() for uuid_net in db.network_id(networks_name_list[0]): mngnet_id = str(uuid_net.uuid) for uuid_net in db.network_id(networks_name_list[1]): nbnet_id = str(uuid_net.uuid) for uuid_net in db.network_id(networks_name_list[2]): sbnet_id = str(uuid_net.uuid) sdb.add_services_binding(service_vm_name, mngnet_id, nbnet_id, sbnet_id) except Exception as exc: print exc
def insert_inpath_service(tenant_id, service_image_id, management_net_name, northbound_net_name, southbound_net_name, *args): """Inserting a network service between two networks""" print ("Creating Network for Services and Servers") service_logic = servlogcs.ServicesLogistics() net_list = {} multiport_net_list = [] networks_name_list = [management_net_name, northbound_net_name, southbound_net_name] client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id) for net in networks_name_list: data = {servconts.NETWORK: {servconts.NAME: net}} net_list[net] = client.create_network(data) net_list[net][servconts.PORTS] = [] LOG.debug("Network %s Created with ID: %s " % ( net, net_list[net][servconts.NETWORK][servconts.ID])) print "Completed" print ("Creating Ports on Services and Server Networks") LOG.debug("Operation 'create_port' executed.") if not service_logic.verify_plugin(const.UCS_PLUGIN): for net in networks_name_list: net_list[net][servconts.PORTS].append (client.create_port (net_list[net][servconts.NETWORK][servconts.ID])) LOG.debug("Operation 'create_port' executed.") else: for net in networks_name_list: nets = net_list[net][servconts.NETWORK][servconts.ID] multiport_net_list.append(nets) data = create_multiport(tenant_id, multiport_net_list) net_idx = 0 for net in networks_name_list: port_id = data[servconts.PORTS][net_idx][servconts.ID] net_list[net][servconts.PORTS].append(port_id) LOG.debug("Port UUID: %s on network: %s" % (data[servconts.PORTS][net_idx][servconts.ID], net)) net_idx = net_idx + 1 print "Completed" try: create_vm_args = [] create_vm_args.append(servconts.CREATE_VM_CMD) create_vm_args.append(service_image_id) print ("Creating VM with image: %s" % (service_image_id)) process = utils.subprocess_popen(create_vm_args, stdout=subprocess.PIPE) result = process.stdout.readlines() tokens = re.search("i-[a-f0-9]*", str(result[1])) service_vm_name = tokens.group(0) print ("Image: %s instantiated successfully" % (service_vm_name)) except Exception as exc: print exc service_logic.image_status(service_vm_name) print "Completed" print "Attaching Ports To VM Service interfaces" try: idx = 0 for net in networks_name_list: network_id = net_list[net][servconts.NETWORK][servconts.ID] port_id = net_list[net][servconts.PORTS][idx] attachment = client.show_port_attachment(network_id, port_id) attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36] LOG.debug(("Plugging virtual interface: %s of VM %s" "into port: %s on network: %s") % (attachment, service_vm_name, port_id, net)) attach_data = {servconts.ATTACHMENT: {servconts.ID: '%s' % attachment}} client.attach_resource(network_id, port_id, attach_data) except Exception as exc: print exc print "Completed" try: LOG.debug("Registering Service in DB") l2db.initialize() for uuid_net in db.network_id(networks_name_list[0]): mngnet_id = str(uuid_net.uuid) for uuid_net in db.network_id(networks_name_list[1]): nbnet_id = str(uuid_net.uuid) for uuid_net in db.network_id(networks_name_list[2]): sbnet_id = str(uuid_net.uuid) sdb.add_services_binding(service_vm_name, mngnet_id, nbnet_id, sbnet_id) except Exception as exc: print exc