X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fpub%2Fvimapi%2Fadaptor.py;h=c13f332bd06de6dfe218fc9a9071527c91331c76;hb=44282da523cb50cb1d1b08081c1da1b9a7f2e0d1;hp=4b156708d0b672586c093985f955f8c321d0d8c7;hpb=f74e80669eb2ea45755fd7b111bfa7852c4a03f2;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index 4b156708..c13f332b 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -83,7 +83,8 @@ def delete_vim_res(data, do_notify): for res_type, res_del_fun in zip(res_types, res_del_funs): for res in ignore_case_get(data, res_type): try: - res_del_fun(res["vim_id"], res["tenant_id"], res["res_id"]) + if 1 == res["is_predefined"]: + res_del_fun(res["vim_id"], res["tenant_id"], res["res_id"]) except VimException as e: logger.error("Failed to delete %s(%s)", res_type, res["res_id"]) logger.error("%s:%s", e.http_code, e.message) @@ -101,6 +102,7 @@ def create_volume(vim_cache, res_cache, vol, do_notify, res_type): vim_id, tenant_name = location_info["vimid"], location_info["tenant"] tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) ret = api.create_volume(vim_id, tenant_id, param) + ret["nodeId"] = vol["volume_storage_id"] do_notify(res_type, ret) vol_id, vol_name, return_code = ret["id"], ret["name"], ret["returnCode"] set_res_cache(res_cache, res_type, vol["volume_storage_id"], vol_id) @@ -128,6 +130,7 @@ def create_network(vim_cache, res_cache, network, do_notify, res_type): vim_id, tenant_name = location_info["vimid"], location_info["tenant"] tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) ret = api.create_network(vim_id, tenant_id, param) + ret["nodeId"] = network["vl_id"] do_notify(res_type, ret) set_res_cache(res_cache, res_type, network["vl_id"], ret["id"]) @@ -161,24 +164,30 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type): for vdu in ignore_case_get(data, "vdus"): if vdu["vdu_id"] == port_ref_vdu_id: location_info = vdu["properties"]["location_info"] + if port["cp_id"] not in vdu["cps"]: + vdu["cps"].append(port["cp_id"]) break if not location_info: err_msg = "vdu_id(%s) for cp(%s) is not defined" raise VimException(err_msg % (port_ref_vdu_id, port["cp_id"]), ERR_CODE) - network_id = get_res_id(res_cache, RES_NETWORK, port["vl_id"]) - subnet_id = get_res_id(res_cache, RES_SUBNET, port["vl_id"]) + network_id = ignore_case_get(port, "networkId") + subnet_id = ignore_case_get(port, "subnetId") + if not network_id: + network_id = get_res_id(res_cache, RES_NETWORK, port["vl_id"]) + subnet_id = get_res_id(res_cache, RES_SUBNET, port["vl_id"]) param = { "networkId": network_id, - "subnetId": subnet_id, - "name": port["properties"]["name"] + "name": port["properties"].get("name","undefined") } + set_opt_val(param, "subnetId", subnet_id) set_opt_val(param, "macAddress", ignore_case_get(port["properties"], "mac_address")) set_opt_val(param, "ip", ignore_case_get(port["properties"], "ip_address")) set_opt_val(param, "vnicType", ignore_case_get(port["properties"], "vnic_type")) set_opt_val(param, "securityGroups", "") # TODO vim_id, tenant_name = location_info["vimid"], location_info["tenant"] tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) - ret = api.create_subnet(vim_id, tenant_id, param) + ret = api.create_port(vim_id, tenant_id, param) + ret["nodeId"] = port["cp_id"] do_notify(res_type, ret) set_res_cache(res_cache, res_type, port["cp_id"], ret["id"]) @@ -188,7 +197,7 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type): param = { "name": "Flavor_%s" % flavor["vdu_id"], "vcpu": int(flavor["nfv_compute"]["num_cpus"]), - "memory": int(flavor["nfv_compute"]["mem_size"].replace('MB', '').strip()), + "memory": int(flavor["nfv_compute"]["mem_size"].replace('GB', '').strip()), "isPublic": True } for local_storage_id in ignore_case_get(flavor, "local_storages"): @@ -219,7 +228,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): vim_id, tenant_name = location_info["vimid"], location_info["tenant"] tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) param = { - "name": vm["properties"]["name"], + "name": vm["properties"].get("name","undefined"), "flavorId": get_res_id(res_cache, RES_FLAVOR, vm["vdu_id"]), "boot": {}, "nicArray": [], @@ -237,7 +246,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): if not img_name: raise VimException("Undefined image(%s)" % vm["image_file"], ERR_CODE) images = api.list_image(vim_id, tenant_id) - for image in images["imageList"]: + for image in images["images"]: if img_name == image["name"]: param["boot"]["imageId"] = image["id"] break @@ -259,7 +268,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): "fileName": inject_data["file_name"], "fileData": inject_data["file_data"] }) - for vol_data in vm["volume_storages"]: + for vol_data in ignore_case_get(vm, "volume_storages"): vol_id = vol_data["volume_storage_id"] param["volumeArray"].append({ "volumeId": get_res_id(res_cache, RES_VOLUME, vol_id) @@ -273,7 +282,11 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): ret = api.create_vm(vim_id, tenant_id, param) do_notify(res_type, ret) - vm_id, vm_name, return_code = ret["id"], ret["name"], ret["returnCode"] + #vm_id, vm_name, return_code = ret["id"], ret["name"], ret["returnCode"] + vm_id, return_code = ret["id"], ret["returnCode"] + if ignore_case_get(ret, "name"): + vm_name = vm["properties"].get("name", "undefined") + logger.debug("vm_name:%s" % vm_name) opt_vm_status = "Timeout" retry_count, max_retry_count = 0, 100 while retry_count < max_retry_count: