X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fhttpserver.py;h=aa23d8963f7935ba4ca2b33e439463bd1a5b9025;hb=caeb224da9840534e46ae0e8f5e194575521c668;hp=c16194251f0315ddc0fcbdfa19b94285ed543cd1;hpb=8afc8a23c55693ea0de002c7b7ffdb9665871a54;p=osm%2Fopenvim.git diff --git a/osm_openvim/httpserver.py b/osm_openvim/httpserver.py index c161942..aa23d89 100644 --- a/osm_openvim/httpserver.py +++ b/osm_openvim/httpserver.py @@ -55,20 +55,20 @@ global my global url_base global config_dic global RADclass_module -RADclass=None #RADclass module is charged only if not in test mode +RADclass_module=None #RADclass module is charged only if not in test mode url_base="/openvim" HTTP_Bad_Request = 400 -HTTP_Unauthorized = 401 -HTTP_Not_Found = 404 +HTTP_Unauthorized = 401 +HTTP_Not_Found = 404 HTTP_Forbidden = 403 -HTTP_Method_Not_Allowed = 405 +HTTP_Method_Not_Allowed = 405 HTTP_Not_Acceptable = 406 HTTP_Request_Timeout = 408 HTTP_Conflict = 409 -HTTP_Service_Unavailable = 503 -HTTP_Internal_Server_Error= 500 +HTTP_Service_Unavailable = 503 +HTTP_Internal_Server_Error= 500 def md5(fname): hash_md5 = hashlib.md5() @@ -150,7 +150,7 @@ def check_extended(extended, allow_net_attach=False): http2db_id={'id':'uuid'} http2db_host={'id':'uuid'} http2db_tenant={'id':'uuid'} -http2db_flavor={'id':'uuid','imageRef':'image_id'} +http2db_flavor={'id':'uuid','imageRef':'image_id', 'size': 'image_size'} http2db_image={'id':'uuid', 'created':'created_at', 'updated':'modified_at', 'public': 'public'} http2db_server={'id':'uuid','hostId':'host_id','flavorRef':'flavor_id','imageRef':'image_id','created':'created_at'} http2db_network={'id':'uuid','provider:vlan':'vlan', 'provider:physical': 'provider'} @@ -524,6 +524,7 @@ def http_get_host_id(host_id): @bottle.route(url_base + '/hosts', method='POST') def http_post_hosts(): '''insert a host into the database. All resources are got and inserted''' + global RADclass_module my = config_dic['http_threads'][ threading.current_thread().name ] #check permissions if not my.admin: @@ -535,17 +536,17 @@ def http_post_hosts(): if r is not None: print "http_post_host_id: Warning: remove extra items ", r change_keys_http2db(http_content['host'], http2db_host) - host = http_content['host'] - warning_text="" - if 'host-data' in http_content: - host.update(http_content['host-data']) - ip_name=http_content['host-data']['ip_name'] - user=http_content['host-data']['user'] - password=http_content['host-data'].get('password', None) + if 'host' in http_content: + host = http_content['host'] + if 'host-data' in http_content: + host.update(http_content['host-data']) else: - ip_name=host['ip_name'] - user=host['user'] - password=host.get('password', None) + host = http_content['host-data'] + warning_text = "" + ip_name = host['ip_name'] + user = host['user'] + password = host.get('password') + if host.get('autodiscover'): if not RADclass_module: try: RADclass_module = imp.find_module("RADclass") @@ -618,10 +619,13 @@ def http_post_hosts(): memory=node['memory']['node_size'] / (1024*1024*1024) #memory=get_next_2pow(node['memory']['hugepage_nr']) host['numas'].append( {'numa_socket': node['id'], 'hugepages': node['memory']['hugepage_nr'], 'memory':memory, 'interfaces': interfaces, 'cores': cores } ) - print json.dumps(host, indent=4) - #return - # - #insert in data base + # print json.dumps(host, indent=4) + # insert in data base + if "created_at" in host: + del host["created_at"] + for numa in host.get("numas", ()): + if "hugepages_consumed" in numa: + del numa["hugepages_consumed"] result, content = my.db.new_host(host) if result >= 0: if content['admin_state_up']: @@ -629,10 +633,13 @@ def http_post_hosts(): host_test_mode = True if config_dic['mode']=='test' or config_dic['mode']=="OF only" else False host_develop_mode = True if config_dic['mode']=='development' else False host_develop_bridge_iface = config_dic.get('development_bridge', None) - thread = ht.host_thread(name=host.get('name',ip_name), user=user, host=ip_name, db=config_dic['db'], db_lock=config_dic['db_lock'], - test=host_test_mode, image_path=config_dic['image_path'], - version=config_dic['version'], host_id=content['uuid'], - develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface ) + thread = ht.host_thread(name=host.get('name',ip_name), user=user, host=ip_name, + password=host.get('password'), + keyfile=host.get('keyfile', config_dic["host_ssh_keyfile"]), + db=config_dic['db'], db_lock=config_dic['db_lock'], + test=host_test_mode, image_path=config_dic['host_image_path'], + version=config_dic['version'], host_id=content['uuid'], + develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface) thread.start() config_dic['host_threads'][ content['uuid'] ] = thread @@ -1642,14 +1649,13 @@ def http_post_server_id(tenant_id): if server_net["network"].get('provider:physical', "")[:3] == 'OVS': vlan = str(server_net['network']['provider:vlan']) dhcp_enable = bool(server_net['network']['enable_dhcp']) + vm_dhcp_ip = c2[0]["ip_address"] + config_dic['host_threads'][server['host_id']].insert_task("create-ovs-bridge-port", vlan) if dhcp_enable: dhcp_firt_ip = str(server_net['network']['dhcp_first_ip']) dhcp_last_ip = str(server_net['network']['dhcp_last_ip']) dhcp_cidr = str(server_net['network']['cidr']) gateway = str(server_net['network']['gateway_ip']) - vm_dhcp_ip = c2[0]["ip_address"] - config_dic['host_threads'][server['host_id']].insert_task("create-ovs-bridge-port", vlan) - set_mac_dhcp(vm_dhcp_ip, vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, c2[0]['mac']) http_controller = config_dic['http_threads'][threading.current_thread().name] http_controller.ovim.launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, gateway)