VDU parser for create vm data 99/42999/1
authorHuang Haibin <haibin.huang@intel.com>
Mon, 16 Apr 2018 17:49:31 +0000 (01:49 +0800)
committerHuang Haibin <haibin.huang@intel.com>
Mon, 16 Apr 2018 17:56:04 +0000 (01:56 +0800)
Change-Id: Ieeca932c098635e24659dd121eef741c88e50c9e
Issue-ID: VFC-657
Signed-off-by: Huang Haibin <haibin.huang@intel.com>
lcm/lcm/pub/vimapi/adaptor.py
lcm/lcm/samples/tests.py

index b7e9a34..3b845dc 100644 (file)
@@ -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
 
index 01c87de..f834e7c 100644 (file)
@@ -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"
         }
     ]