diff options
author | Haibin Huang <haibin.huang@intel.com> | 2018-11-15 09:26:42 +0000 |
---|---|---|
committer | Haibin Huang <haibin.huang@intel.com> | 2018-11-16 11:07:41 +0000 |
commit | d17138507974a8bd8bfcda71f1b34b37f336aa2e (patch) | |
tree | 8ef1b0f5ad2b27624287e7e48c59e87c9538a4e8 /share/newton_base | |
parent | 1145afaa62e04b8fc31f83f35897d0d121786c00 (diff) |
Fix Openstack user data import issue
Change-Id: Iedfa7b4c5389b7993630680d6efa4ed4ce734607
Issue-ID: MULTICLOUD-407
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
Diffstat (limited to 'share/newton_base')
-rw-r--r-- | share/newton_base/openoapi/server.py | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py index cdc7e4fa..be79c466 100644 --- a/share/newton_base/openoapi/server.py +++ b/share/newton_base/openoapi/server.py @@ -335,6 +335,7 @@ class Servers(APIView): servername = request.data["name"] query = "name=%s" % servername content, status_code = self._get_servers(query, vimid, tenantid) + logger.info("content %s" % content) existed = False if status_code == status.HTTP_200_OK: for server in content["servers"]: @@ -381,44 +382,52 @@ class Servers(APIView): #metadata_vfc = server.pop("metadata", None) #if metadata_vfc: # metadata_openstack = {} - # self._convert_metadata(metadata_vfc, metadata_openstack, False) + # self._convert_metadata(metadata_vfc, metadata_openstack, True) # server["metadata"] = metadata_openstack contextarray = server.pop("contextArray", None) volumearray = server.pop("volumeArray", None) - userdata = server.pop("userdata", None) - if contextarray: - user_data = [] - strUserData = '' - source_content = "" - dest_path = "" - user_data.append("#cloud-config\n") - for context in contextarray: - user_data.append("write_files:\n") - user_data.append("- encoding: b64\n") - user_data.append(" content: " + context["source_data_base64"] + "\n") - user_data.append(" owner: root:root\n") - user_data.append(" path: " + context["dest_path"] + "\n") - user_data.append(" permissions: '0644'\n") - user_data.append("\n") - if userdata: - user_data.append("runcmd:\n") - user_data.append("- " + userdata + "\n") - - strUserData.join(user_data) - server["user_data"] = strUserData + + # inject files + logger.info("Start inject files contextarray %s" % contextarray) + if contextarray is not None: + if isinstance(contextarray, list): + personalities = [] + for context in contextarray: + personality = {} + personality["path"] = context["dest_path"] + personality["contents"] = context["source_data_base64"] + personalities.append(personality) + + if len(personalities) > 0: + server["personality"] = personalities + logger.info("List personalities %s" % personalities) + elif isinstance(contextarray, dict): + personalities = [] + personality = {} + context = contextarray + personality["path"] = context["dest_path"] + personality["contents"] = context["source_data_base64"] + personalities.append(personality) + + if len(personalities) > 0: + server["personality"] = personalities + logger.info("Personalities %s" % personalities) + else: + logger.error("contextarray %s format is not right.", contextarray) + return Response(data={'error': str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) VimDriverUtils.replace_key_by_mapping(server, self.keys_mapping, True) req_body = json.JSONEncoder().encode({"server": server}) - + logger.info("-server %s, json_server %s" % (server, req_body)) vim = VimDriverUtils.get_vim_info(vimid) sess = VimDriverUtils.get_session(vim, tenantid) self.service['region_name'] = vim['openstack_region_id'] \ if vim.get('openstack_region_id') \ else vim['cloud_region_id'] - logger.info("making request with URI:%s" % req_resouce) resp = sess.post(req_resouce, data=req_body, endpoint_filter=self.service, |