diff options
author | Huang Haibin <haibin.huang@intel.com> | 2018-04-17 01:49:31 +0800 |
---|---|---|
committer | Huang Haibin <haibin.huang@intel.com> | 2018-04-17 01:56:04 +0800 |
commit | 76aa6cb99671fe222837b45e2564c6244da63262 (patch) | |
tree | 87db1e6dbb764f9bd7874f6aea61ba07a74b68f1 /lcm | |
parent | eb2b62f063e14a85a66cc8dfe54cf404b9099ef8 (diff) |
VDU parser for create vm data
Change-Id: Ieeca932c098635e24659dd121eef741c88e50c9e
Issue-ID: VFC-657
Signed-off-by: Huang Haibin <haibin.huang@intel.com>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/pub/vimapi/adaptor.py | 29 | ||||
-rw-r--r-- | lcm/lcm/samples/tests.py | 28 |
2 files changed, 29 insertions, 28 deletions
diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index b7e9a34f..3b845dc5 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -289,22 +289,23 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): "volumeArray": [] } # set boot param - if "image_file" in vm and vm["image_file"]: + if "artifacts" in vm and vm["artifacts"]: param["boot"]["type"] = BOOT_FROM_IMAGE img_name = "" - for img in ignore_case_get(data, "image_files"): - if vm["image_file"] == img["image_file_id"]: - img_name = img["properties"]["name"] + for artifact in vm["artifacts"]: + if artifact["artifact_name"] == "sw_image": + # TODO: after DM define + img_name = artifact["file"] break if not img_name: - raise VimException("Undefined image(%s)" % vm["image_file"], ERR_CODE) + raise VimException("Undefined image(%s)" % vm["artifacts"], ERR_CODE) images = api.list_image(vim_id, tenant_id) for image in images["images"]: if img_name == image["name"]: param["boot"]["imageId"] = image["id"] break if "imageId" not in param["boot"]: - raise VimException("Image(%s) not found in Vim(%s)" % (img_name, vim_id), ERR_CODE) + raise VimException("Undefined artifacts image(%s)" % vm["artifacts"], ERR_CODE) elif vm["volume_storages"]: param["boot"]["type"] = BOOT_FROM_VOLUME vol_id = vm["volume_storages"][0]["volume_storage_id"] @@ -316,11 +317,13 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): param["nicArray"].append({ "portId": get_res_id(res_cache, RES_PORT, cp_id) }) - for inject_data in ignore_case_get(vm["properties"], "inject_data_list"): - param["contextArray"].append({ - "fileName": inject_data["file_name"], - "fileData": inject_data["file_data"] - }) + # TODO: use config drive + for inject_data in ignore_case_get(vm["properties"], "inject_files"): + for key, value in inject_data.items(): + param["contextArray"].append({ + "fileName": key, + "fileData": value + }) for vol_data in ignore_case_get(vm, "volume_storages"): vol_id = vol_data["volume_storage_id"] param["volumeArray"].append({ @@ -328,8 +331,8 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): }) set_opt_val(param, "availabilityZone", ignore_case_get(location_info, "availability_zone")) - set_opt_val(param, "userdata", "") # TODO Configuration information or scripts to use upon launch - set_opt_val(param, "metadata", "") # TODO [{"keyName": "foo", "value": "foo value"}] + set_opt_val(param, "userdata", ignore_case_get(vm["properties"], "user_data")) + set_opt_val(param, "metadata", ignore_case_get(vm["properties"], "meta_data")) set_opt_val(param, "securityGroups", "") # TODO List of names of security group set_opt_val(param, "serverGroup", "") # TODO the ServerGroup for anti-affinity and affinity diff --git a/lcm/lcm/samples/tests.py b/lcm/lcm/samples/tests.py index 01c87deb..f834e7ca 100644 --- a/lcm/lcm/samples/tests.py +++ b/lcm/lcm/samples/tests.py @@ -46,21 +46,17 @@ inst_res_data = { }, "artifacts": [ { - "artifact_name": "cirros.img", + "artifact_name": "sw_image", + "deploy_path": "", "type": "tosca.artifacts.nfv.SwImage", - "properties": { - "operating_system": "unbant", - "sw_image": "/swimages/xenial-snat.qcow2", - "name": "cirros.img", - "checksum": "5000", - "min_ram": "1 GB", - "disk_format": "qcow2", - "version": "1.0", - "container_format": "bare", - "min_disk": "10 GB", - "size": "10 GB" - }, - "file": "/swimages/xenial-snat.qcow2" + "repository": "", + "file": "ubuntu_16.04" + }, + ], + "inject_files": [ + { + "source_path": "artifacts/keys/authorized_keys", + "dest_path": "/home/ubuntu/.ssh/authorized_keys" } ], "image_file": "cirros.img", @@ -76,6 +72,8 @@ inst_res_data = { "cp_vNat" ], "properties": { + "user_data": "just test user data", + "meta_data": "just test meta data", "configurable_properties": { "test": { "additional_vnfc_configurable_properties": { @@ -330,7 +328,7 @@ c5_data_get_flavor = [{ c6_data_list_image = { "images": [ { - "name": "cirros.img", + "name": "ubuntu_16.04", "id": "678" } ] |