Encode base64 for user data
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / vimapi / adaptor.py
index 8542e11..3b959c4 100644 (file)
@@ -15,6 +15,8 @@
 import logging
 import time
 import json
+import os
+import base64
 
 from lcm.pub.utils.values import ignore_case_get, set_opt_val
 from lcm.pub.msapi.aai import get_flavor_info
@@ -250,7 +252,7 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type):
         subnet_id = get_res_id(res_cache, RES_SUBNET, port["vl_id"])
     param = {
         "networkId": network_id,
-        "name": port["properties"].get("name", "undefined")
+        "name": port["properties"].get("name", "")
     }
     set_opt_val(param, "subnetId", subnet_id)
     set_opt_val(param, "macAddress", ignore_case_get(port["properties"], "mac_address"))
@@ -261,7 +263,7 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type):
         ip_address.extend(fixed_ip_address)
     for one_virtual_network_interface in port["properties"].get("virtual_network_interface_requirements", []):
         interfaceTypeString = one_virtual_network_interface["network_interface_requirements"]["interfaceType"]
-        interfaceType = json.loads(interfaceTypeString)["configuration-value"]
+        interfaceType = json.loads(interfaceTypeString)["configurationValue"]
         vnic_type = ignore_case_get(port["properties"], "vnic_type")
         if vnic_type == "":
             if interfaceType == "SR-IOV":
@@ -369,7 +371,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type):
         for artifact in vm["artifacts"]:
             if artifact["artifact_name"] == "sw_image":
                 # TODO: after DM define
-                img_name = artifact["file"]
+                img_name = os.path.basename(artifact["file"])
                 break
         if not img_name:
             raise VimException("Undefined image(%s)" % vm["artifacts"], ERR_CODE)
@@ -399,8 +401,9 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type):
             "volumeId": get_res_id(res_cache, RES_VOLUME, vol_id)
         })
 
+    user_data = base64.encodestring(ignore_case_get(vm["properties"], "user_data"))
     set_opt_val(param, "availabilityZone", ignore_case_get(location_info, "availability_zone"))
-    set_opt_val(param, "userdata", ignore_case_get(vm["properties"], "user_data"))
+    set_opt_val(param, "userdata", 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