def http_post_instance_scenario_action(tenant_id, instance_id): '''take an action over a scenario instance''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_instance_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #parse input data http_content,_ = format_in( instance_scenario_action_schema ) r = af.remove_extra_items(http_content, instance_scenario_action_schema) if r is not None: print "http_post_instance_scenario_action: Warning: remove extra items ", r print "http_post_instance_scenario_action input: ", http_content #obtain data result, data = mydb.get_instance_scenario(instance_id, tenant_id) if result < 0: print "http_get_instance_id error %d %s" % (-result, data) bottle.abort(-result, data) instance_id = data["uuid"] result, data = nfvo.instance_action(mydb, tenant_id, instance_id, http_content) if result < 0: print "http_post_scenario_action error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data)
def http_post_instance_scenario_action(tenant_id, instance_id): """take an action over a scenario instance""" # check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print "httpserver.http_post_instance_scenario_action() tenant %s not found" % tenant_id bottle.abort(HTTP_Not_Found, "Tenant %s not found" % tenant_id) return # parse input data http_content = format_in(instance_scenario_action_schema) r = af.remove_extra_items(http_content, instance_scenario_action_schema) if r is not None: print "http_post_instance_scenario_action: Warning: remove extra items ", r print "http_post_instance_scenario_action input: ", http_content # obtain data result, data = mydb.get_instance_scenario(instance_id, tenant_id) if result < 0: print "http_get_instance_id error %d %s" % (-result, data) bottle.abort(-result, data) result, data = nfvo.instance_action(mydb, tenant_id, instance_id, http_content) if result < 0: print "http_post_scenario_action error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data)
def http_post_scenario_action(tenant_id, scenario_id): '''take an action over a scenario''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #parse input data http_content = format_in( scenario_action_schema ) r = af.remove_extra_items(http_content, scenario_action_schema) if r is not None: print "http_post_scenario_action: Warning: remove extra items ", r if "start" in http_content: result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \ http_content['start'].get('description',http_content['start']['instance_name']), http_content['start'].get('datacenter') ) if result < 0: print "http_post_scenario_action start error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "deploy" in http_content: #Equivalent to start result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['deploy']['instance_name'], http_content['deploy'].get('description',http_content['deploy']['instance_name']), http_content['deploy'].get('datacenter') ) if result < 0: print "http_post_scenario_action deploy error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "reserve" in http_content: #Reserve resources result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['reserve']['instance_name'], http_content['reserve'].get('description',http_content['reserve']['instance_name']), http_content['reserve'].get('datacenter'), startvms=False ) if result < 0: print "http_post_scenario_action reserve error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "verify" in http_content: #Equivalent to start and then delete result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['verify']['instance_name'], http_content['verify'].get('description',http_content['verify']['instance_name']), http_content['verify'].get('datacenter'), startvms=False ) if result < 0 or result!=1: print "http_post_scenario_action verify error during start %d: %s" % (-result, data) bottle.abort(-result, data) instance_id = data['uuid'] result, message = nfvo.delete_instance(mydb, tenant_id,instance_id) if result < 0: print "http_post_scenario_action verify error during start delete_instance_id %d %s" % (-result, message) bottle.abort(-result, message) else: #print json.dumps(data, indent=4) return format_out({"result":"Verify OK"})
def http_post_scenario_action(tenant_id, scenario_id): '''take an action over a scenario''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #parse input data http_content,_ = format_in( scenario_action_schema ) r = af.remove_extra_items(http_content, scenario_action_schema) if r is not None: print "http_post_scenario_action: Warning: remove extra items ", r if "start" in http_content: result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \ http_content['start'].get('description',http_content['start']['instance_name']), http_content['start'].get('datacenter') ) if result < 0: print "http_post_scenario_action start error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "deploy" in http_content: #Equivalent to start result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['deploy']['instance_name'], http_content['deploy'].get('description',http_content['deploy']['instance_name']), http_content['deploy'].get('datacenter') ) if result < 0: print "http_post_scenario_action deploy error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "reserve" in http_content: #Reserve resources result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['reserve']['instance_name'], http_content['reserve'].get('description',http_content['reserve']['instance_name']), http_content['reserve'].get('datacenter'), startvms=False ) if result < 0: print "http_post_scenario_action reserve error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data) elif "verify" in http_content: #Equivalent to start and then delete result, data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['verify']['instance_name'], http_content['verify'].get('description',http_content['verify']['instance_name']), http_content['verify'].get('datacenter'), startvms=False ) if result < 0 or result!=1: print "http_post_scenario_action verify error during start %d: %s" % (-result, data) bottle.abort(-result, data) instance_id = data['uuid'] result, message = nfvo.delete_instance(mydb, tenant_id,instance_id) if result < 0: print "http_post_scenario_action verify error during start delete_instance_id %d %s" % (-result, message) bottle.abort(-result, message) else: #print json.dumps(data, indent=4) return format_out({"result":"Verify OK"})
def http_post_datacenters(): '''insert a tenant into the catalogue. ''' #parse input data http_content = format_in( datacenter_schema ) r = af.remove_extra_items(http_content, datacenter_schema) if r is not None: print "http_post_tenants: Warning: remove extra items ", r result, data = nfvo.new_datacenter(mydb, http_content['datacenter']) if result < 0: print "http_post_datacenters error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_datacenter_id('any', data)
def http_post_datacenters(): '''insert a tenant into the catalogue. ''' #parse input data http_content,_ = format_in( datacenter_schema ) r = af.remove_extra_items(http_content, datacenter_schema) if r is not None: print "http_post_tenants: Warning: remove extra items ", r result, data = nfvo.new_datacenter(mydb, http_content['datacenter']) if result < 0: print "http_post_datacenters error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_datacenter_id('any', data)
def http_post_tenants(): """insert a tenant into the catalogue. """ # parse input data http_content = format_in(tenant_schema) r = af.remove_extra_items(http_content, tenant_schema) if r is not None: print "http_post_tenants: Warning: remove extra items ", r result, data = nfvo.new_tenant(mydb, http_content["tenant"]) if result < 0: print "http_post_tenants error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_tenant_id(data)
def http_post_vnfs(tenant_id): '''insert a vnf into the catalogue. Creates the flavor and images in the VIM, and creates the VNF and its internal structure in the OPENMANO DB''' print "Parsing the YAML file of the VNF" #parse input data http_content = format_in( vnfd_schema ) r = af.remove_extra_items(http_content, vnfd_schema) if r is not None: print "http_post_vnfs: Warning: remove extra items ", r result, data = nfvo.new_vnf(mydb,tenant_id,http_content) if result < 0: print "http_post_vnfs error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_vnf_id(tenant_id,data)
def http_post_vnfs(tenant_id): '''insert a vnf into the catalogue. Creates the flavor and images in the VIM, and creates the VNF and its internal structure in the OPENMANO DB''' print "Parsing the YAML file of the VNF" #parse input data http_content, used_schema = format_in( vnfd_schema_v01, ("version",), {"v0.2": vnfd_schema_v02}) r = af.remove_extra_items(http_content, used_schema) if r is not None: print "http_post_vnfs: Warning: remove extra items ", r result, data = nfvo.new_vnf(mydb,tenant_id,http_content) if result < 0: print "http_post_vnfs error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_vnf_id(tenant_id,data)
def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id): '''edit a netmap''' #parse input data http_content,_ = format_in( netmap_edit_schema ) r = af.remove_extra_items(http_content, netmap_edit_schema) if r is not None: print "http_putnettmap_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = nfvo.datacenter_edit_netmap(mydb, tenant_id, datacenter_id, netmap_id, http_content) if result < 0: print "http_putnettmap_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) else: return http_getnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id)
def http_edit_datacenter_id(datacenter_id): '''edit datacenter details, can use both uuid or name''' #parse input data http_content,_ = format_in( datacenter_edit_schema ) r = af.remove_extra_items(http_content, datacenter_edit_schema) if r is not None: print "http_edit_datacenter_id: Warning: remove extra items ", r result, data = nfvo.edit_datacenter(mydb, datacenter_id, http_content['datacenter']) if result < 0: print "http_edit_datacenter_id error %d %s" % (-result, data) bottle.abort(-result, data) else: return http_get_datacenter_id('any', datacenter_id)
def http_edit_network_id(network_id_name): '''edit network details, can use both uuid or name''' #parse input data http_content,_ = format_in( network_edit_schema ) r = af.remove_extra_items(http_content, network_edit_schema) if r is not None: print "http_edit_network_id: Warning: remove extra items ", r result, network_id = nfvo.edit_network(mydb, network_id_name, http_content['network']) if result < 0: print "http_edit_network_id error %d %s" % (-result, network_id) bottle.abort(-result, network_id) else: return http_get_network_id('any', network_id)
def http_ssociate_datacenters(tenant_id, datacenter_id): '''associate an existing datacenter to a this tenant. ''' #parse input data http_content = format_in( datacenter_associate_schema ) r = af.remove_extra_items(http_content, datacenter_associate_schema) if r != None: print "http_associate_datacenters: Warning: remove extra items ", r result, data = nfvo.associate_datacenter_to_tenant(mydb, tenant_id, datacenter_id, http_content['datacenter'].get('vim_tenant'), http_content['datacenter'].get('vim_tenant_name') ) if result < 0: print "http_associate_datacenters error %d %s" % (-result, data) bottle.abort(-result, data) else: print "http_associate_datacenters data" , data return http_get_datacenter_id(tenant_id, data)
def http_action_datacenter_id(datacenter_id): '''perform an action over datacenter, can use both uuid or name''' #parse input data http_content = format_in( datacenter_action_schema ) r = af.remove_extra_items(http_content, datacenter_action_schema) if r is not None: print "http_action_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = nfvo.datacenter_action(mydb, datacenter_id, http_content) if result < 0: print "http_action_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) if 'net-update' in http_content: return http_getnetwork_datacenter_id(datacenter_id) else: return format_out(content)
def http_action_datacenter_id(tenant_id, datacenter_id): '''perform an action over datacenter, can use both uuid or name''' #parse input data http_content,_ = format_in( datacenter_action_schema ) r = af.remove_extra_items(http_content, datacenter_action_schema) if r is not None: print "http_action_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = nfvo.datacenter_action(mydb, tenant_id, datacenter_id, http_content) if result < 0: print "http_action_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) if 'net-update' in http_content: return http_getnetwork_datacenter_id(datacenter_id) else: return format_out(content)
def http_post_instances(tenant_id): '''take an action over a scenario''' #check valid tenant_id if not nfvo.check_tenant(mydb, tenant_id): print 'httpserver.http_post_scenario_action() tenant %s not found' % tenant_id bottle.abort(HTTP_Not_Found, 'Tenant %s not found' % tenant_id) return #parse input data http_content,used_schema = format_in( instance_scenario_create_schema) r = af.remove_extra_items(http_content, used_schema) if r is not None: print "http_post_instances: Warning: remove extra items ", r result, data = nfvo.create_instance(mydb, tenant_id, http_content["instance"]) if result < 0: print "http_post_instances start error %d: %s" % (-result, data) bottle.abort(-result, data) else: return format_out(data)
def http_postnetmap_datacenter_id(tenant_id, datacenter_id): '''creates a new netmap''' #parse input data http_content,_ = format_in( netmap_new_schema ) r = af.remove_extra_items(http_content, netmap_new_schema) if r is not None: print "http_action_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = nfvo.datacenter_new_netmap(mydb, tenant_id, datacenter_id, http_content) if result < 0: print "http_postnetmap_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) convert_datetime2str(content) af.convert_str2boolean(content, ('shared', 'multipoint') ) print content data={'netmaps' : content} return format_out(data)
def http_associate_networks(tenant_id, network_id): '''associate an existing network to a this tenant. ''' #parse input data http_content,_ = format_in( network_associate_schema ) r = af.remove_extra_items(http_content, network_associate_schema) if r != None: print "http_associate_networks: Warning: remove extra items ", r result, data = nfvo.associate_network_to_tenant(mydb, tenant_id, network_id, http_content['network'].get('vim_tenant'), http_content['network'].get('vim_tenant_name'), http_content['network'].get('vim_username'), http_content['network'].get('vim_password') ) if result < 0: print "http_associate_networks error %d %s" % (-result, data) bottle.abort(-result, data) else: print "http_associate_networks data" , data return http_get_network_id(tenant_id, data)
def http_edit_datacenter_id(datacenter_id): '''edit datacenter details, can use both uuid or name''' #parse input data http_content = format_in( datacenter_edit_schema ) r = af.remove_extra_items(http_content, datacenter_edit_schema) if r is not None: print "http_edit_datacenter_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = mydb.get_table_by_uuid_name('datacenters', datacenter_id) if result < 0: print "http_edit_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) #edit data datacenter_id = content['uuid'] where={'uuid': content['uuid']} result, content = mydb.update_rows('datacenters', http_content['datacenter'], where) if result < 0: print "http_edit_datacenter_id error %d %s" % (result, content) bottle.abort(-result, content) return http_get_datacenter_id('any', datacenter_id)
class vimconnector(): def new_host(self, vimURIadmin, host_data): '''Adds a new host to VIM''' '''Returns status code of the VIM response''' print "VIMConnector: Adding a new host" headers_req = {'content-type': 'application/json'} payload_req = host_data try: vim_response = requests.post(vimURIadmin + '/hosts', headers=headers_req, data=payload_req) except requests.exceptions.RequestException, e: print "new_host Exception: ", e.args return -HTTP_Not_Found, str(e.args[0]) print vim_response #print vim_response.status_code if vim_response.status_code == 200: #print vim_response.json() #print json.dumps(vim_response.json(), indent=4) res, http_content = af.format_in( vim_response, openmano_schemas.new_host_response_schema) #print http_content if res: r = af.remove_extra_items( http_content, openmano_schemas.new_host_response_schema) if r is not None: print "Warning: remove extra items ", r #print http_content host_id = http_content['host']['id'] #print "Host id: ",host_id return vim_response.status_code, host_id else: return -HTTP_Bad_Request, http_content else: #print vim_response.text jsonerror = af.format_jsonerror(vim_response) text = 'Error in VIM "%s": not possible to add new host. HTTP Response: %d. Error: %s' % ( vimURIadmin, vim_response.status_code, jsonerror) #print text return -vim_response.status_code, text
def http_edit_tenant_id(tenant_id): '''edit tenant details, can use both uuid or name''' #parse input data http_content,_ = format_in( tenant_edit_schema ) r = af.remove_extra_items(http_content, tenant_edit_schema) if r is not None: print "http_edit_tenant_id: Warning: remove extra items ", r #obtain data, check that only one exist result, content = mydb.get_table_by_uuid_name('nfvo_tenants', tenant_id) if result < 0: print "http_edit_tenant_id error %d %s" % (result, content) bottle.abort(-result, content) #edit data tenant_id = content['uuid'] where={'uuid': content['uuid']} result, content = mydb.update_rows('nfvo_tenants', http_content['tenant'], where) if result < 0: print "http_edit_tenant_id error %d %s" % (result, content) bottle.abort(-result, content) return http_get_tenant_id(tenant_id)
vim_response = requests.post(vimURIadmin + '/ports', headers=headers_req, data=payload_req) except requests.exceptions.RequestException, e: print "new_external_port Exception: ", e.args return -HTTP_Not_Found, str(e.args[0]) print vim_response #print vim_response.status_code if vim_response.status_code == 200: #print vim_response.json() #print json.dumps(vim_response.json(), indent=4) res, http_content = af.format_in( vim_response, openmano_schemas.new_port_response_schema) #print http_content if res: r = af.remove_extra_items( http_content, openmano_schemas.new_port_response_schema) if r is not None: print "Warning: remove extra items ", r #print http_content port_id = http_content['port']['id'] print "Port id: ", port_id return vim_response.status_code, port_id else: return -HTTP_Bad_Request, http_content else: #print vim_response.text jsonerror = af.format_jsonerror(vim_response) text = 'Error in VIM "%s": not possible to add new external port. HTTP Response: %d. Error: %s' % ( vimURIadmin, vim_response.status_code, jsonerror) #print text return -vim_response.status_code, text
headers_req = {'content-type': 'application/json'} payload_req = port_data try: vim_response = requests.post(self.url_admin+'/ports', headers = headers_req, data=payload_req) except requests.exceptions.RequestException, e: print "new_external_port Exception: ", e.args return -HTTP_Not_Found, str(e.args[0]) print vim_response #print vim_response.status_code if vim_response.status_code == 200: #print vim_response.json() #print json.dumps(vim_response.json(), indent=4) res, http_content = af.format_in(vim_response, openmano_schemas.new_port_response_schema) #print http_content if res: r = af.remove_extra_items(http_content, openmano_schemas.new_port_response_schema) if r is not None: print "Warning: remove extra items ", r #print http_content port_id = http_content['port']['id'] print "Port id: ",port_id return vim_response.status_code,port_id else: return -HTTP_Bad_Request,http_content else: #print vim_response.text jsonerror = af.format_jsonerror(vim_response) text = 'Error in VIM "%s": not possible to add new external port. HTTP Response: %d. Error: %s' % (self.url_admin, vim_response.status_code, jsonerror) #print text return -vim_response.status_code,text def new_external_network(self,net_name,net_type): '''Adds a external network to VIM (shared)'''