X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=httpserver.py;h=a4e7fb9bf2bbb9fd19d2b9d852369859d98c8475;hb=4dba7abed342277b08ebe1e903a9a87284c433ab;hp=680fddf7d20b4a21186807a586ef934ef4b1b485;hpb=f97fd27f5902c7be87d888c095ffb0acc156e126;p=osm%2FRO.git diff --git a/httpserver.py b/httpserver.py index 680fddf7..a4e7fb9b 100644 --- a/httpserver.py +++ b/httpserver.py @@ -38,8 +38,8 @@ import logging from jsonschema import validate as js_v, exceptions as js_e from openmano_schemas import vnfd_schema_v01, vnfd_schema_v02, \ - nsd_schema_v01, nsd_schema_v02, scenario_edit_schema, \ - scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema, \ + nsd_schema_v01, nsd_schema_v02, nsd_schema_v03, scenario_edit_schema, \ + scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema_v01, \ tenant_schema, tenant_edit_schema,\ datacenter_schema, datacenter_edit_schema, datacenter_action_schema, datacenter_associate_schema,\ object_schema, netmap_new_schema, netmap_edit_schema @@ -52,6 +52,7 @@ global mydb global url_base global logger url_base="/openmano" +logger = None HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -112,7 +113,8 @@ class httpserver(threading.Thread): global mydb global logger #initialization - logger = logging.getLogger('openmano.http') + if not logger: + logger = logging.getLogger('openmano.http') threading.Thread.__init__(self) self.host = host self.port = port #Port where the listen service must be started @@ -212,6 +214,7 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None): # bottle.abort(HTTP_Bad_Request, "Content error, empty") # return + #logger.debug('client-data: %s', client_data) #look for the client provider version error_text = "Invalid content " client_version = None @@ -741,11 +744,17 @@ def http_post_vnfs(tenant_id): #print "Parsing the YAML file of the VNF" #parse input data logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) - http_content, used_schema = format_in( vnfd_schema_v01, ("version",), {"v0.2": vnfd_schema_v02}) + http_content, used_schema = format_in( vnfd_schema_v01, ("schema_version",), {"0.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 try: - vnf_id = nfvo.new_vnf(mydb,tenant_id,http_content) + if used_schema == vnfd_schema_v01: + vnf_id = nfvo.new_vnf(mydb,tenant_id,http_content) + elif used_schema == vnfd_schema_v02: + vnf_id = nfvo.new_vnf_v02(mydb,tenant_id,http_content) + else: + logger.warning('Unexpected schema_version: %s', http_content.get("schema_version")) + bottle.abort(HTTP_Bad_Request, "Invalid schema version") return http_get_vnf_id(tenant_id, vnf_id) except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_vnfs error {}: {}".format(e.http_code, str(e))) @@ -779,14 +788,14 @@ def http_get_hosts(tenant_id, datacenter): result, data = nfvo.get_hosts_info(mydb, tenant_id) #, datacenter) if result < 0: - print "http_post_vnfs error %d %s" % (-result, data) + print "http_get_hosts error %d %s" % (-result, data) bottle.abort(-result, data) else: convert_datetime2str(data) print json.dumps(data, indent=4) return format_out(data) except (nfvo.NfvoException, db_base_Exception) as e: - logger.error("http_post_vnfs error {}: {}".format(e.http_code, str(e))) + logger.error("http_get_hosts error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) @@ -837,15 +846,20 @@ def http_post_verify(tenant_id): def http_post_scenarios(tenant_id): '''add a scenario into the catalogue. Creates the scenario and its internal structure in the OPENMANO DB''' logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) - http_content, used_schema = format_in( nsd_schema_v01, ("schema_version",), {2: nsd_schema_v02}) + http_content, used_schema = format_in( nsd_schema_v01, ("schema_version",), {2: nsd_schema_v02, "0.3": nsd_schema_v03}) #r = utils.remove_extra_items(http_content, used_schema) #if r is not None: print "http_post_scenarios: Warning: remove extra items ", r #print "http_post_scenarios input: ", http_content try: - if http_content.get("schema_version") == None: + if used_schema == nsd_schema_v01: scenario_id = nfvo.new_scenario(mydb, tenant_id, http_content) - else: + elif used_schema == nsd_schema_v02: scenario_id = nfvo.new_scenario_v02(mydb, tenant_id, http_content) + elif used_schema == nsd_schema_v03: + scenario_id = nfvo.new_scenario_v03(mydb, tenant_id, http_content) + else: + logger.warning('Unexpected schema_version: %s', http_content.get("schema_version")) + bottle.abort(HTTP_Bad_Request, "Invalid schema version") #print json.dumps(data, indent=4) #return format_out(data) return http_get_scenario_id(tenant_id, scenario_id) @@ -973,9 +987,10 @@ def http_post_instances(tenant_id): if tenant_id != "any": nfvo.check_tenant(mydb, tenant_id) #parse input data - http_content,used_schema = format_in( instance_scenario_create_schema) + http_content,used_schema = format_in( instance_scenario_create_schema_v01) r = utils.remove_extra_items(http_content, used_schema) - if r is not None: print "http_post_instances: Warning: remove extra items ", r + if r is not None: + logger.warning("http_post_instances: Warning: remove extra items %s", str(r)) data = nfvo.create_instance(mydb, tenant_id, http_content["instance"]) return format_out(data) except (nfvo.NfvoException, db_base_Exception) as e: