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 = utils.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_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 = utils.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 = utils.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_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 = utils.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 = utils.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_name): '''edit datacenter details, can use both uuid or name''' #parse input data http_content,_ = format_in( datacenter_edit_schema ) r = utils.remove_extra_items(http_content, datacenter_edit_schema) if r is not None: print "http_edit_datacenter_id: Warning: remove extra items ", r result, datacenter_id = nfvo.edit_datacenter(mydb, datacenter_id_name, http_content['datacenter']) if result < 0: print "http_edit_datacenter_id error %d %s" % (-result, datacenter_id) bottle.abort(-result, datacenter_id) else: return http_get_datacenter_id('any', datacenter_id)
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 = utils.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_getnetmap_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 = utils.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 = utils.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) utils.convert_str2boolean(content, ('shared', 'multipoint') ) print content data={'netmaps' : content} return format_out(data)
def http_associate_datacenters(tenant_id, datacenter_id): '''associate an existing datacenter to a this tenant. ''' #parse input data http_content,_ = format_in( datacenter_associate_schema ) r = utils.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'), http_content['datacenter'].get('vim_username'), http_content['datacenter'].get('vim_password') ) 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_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 = utils.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)