diff options
author | Yun Huang <yun.huang@windriver.com> | 2018-05-17 10:35:15 +0800 |
---|---|---|
committer | Yun Huang <yun.huang@windriver.com> | 2018-05-17 10:35:15 +0800 |
commit | 11796cf79d6801c175aaad5cd258f8c0c27eff03 (patch) | |
tree | ec6fcd297c11d36ce9e807f883610ad3012f346d /share/newton_base/openoapi | |
parent | 64129eb405270b02e33bc178e95bf2cc39193daa (diff) |
Fix bug of list server api
fix the bug to convert metadata
Change-Id: I5a18780314ae0da16d3307dde3fdc30870666abe
Issue-ID: MULTICLOUD-233
Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'share/newton_base/openoapi')
-rw-r--r-- | share/newton_base/openoapi/flavor.py | 45 | ||||
-rw-r--r-- | share/newton_base/openoapi/server.py | 52 |
2 files changed, 49 insertions, 48 deletions
diff --git a/share/newton_base/openoapi/flavor.py b/share/newton_base/openoapi/flavor.py index 1124aec4..4b3c5977 100644 --- a/share/newton_base/openoapi/flavor.py +++ b/share/newton_base/openoapi/flavor.py @@ -38,17 +38,17 @@ class Flavors(APIView): ("extra_specs", "extraSpecs"), ] - def _convert_extra_specs(self, extraSpecs, extra_specs, reverse=False): + def _convert_extra_specs(self, extra_specs_vfc, extra_specs_openstack, reverse=False): if reverse == False: #from extraSpecs to extra_specs - for spec in extraSpecs: - extra_specs[spec['keyName']] = spec['value'] + for spec in extra_specs_vfc: + extra_specs_openstack[spec['keyName']] = spec['value'] else: - for k,v in extra_specs.items(): + for k,v in extra_specs_openstack.items(): spec={} spec['keyName']=k spec['value']=v - extraSpecs.append(spec) + extra_specs_vfc.append(spec) def get(self, request, vimid="", tenantid="", flavorid=""): logger.info("vimid, tenantid, flavorid = %s,%s,%s" % (vimid, tenantid, flavorid)) @@ -70,9 +70,10 @@ class Flavors(APIView): extraResp = self._get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() if extraContent["extra_specs"]: - extraSpecs = [] - self._convert_extra_specs(extraSpecs, extraContent["extra_specs"], True) - flavor["extraSpecs"] = extraSpecs + extra_specs_vfc = [] + self._convert_extra_specs(extra_specs_vfc, extraContent["extra_specs"], True) + flavor["extraSpecs"] = extra_specs_vfc + VimDriverUtils.replace_key_by_mapping(flavor, self.keys_mapping) content.update(flavor) @@ -99,9 +100,9 @@ class Flavors(APIView): extraResp = self._get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() if extraContent["extra_specs"]: - extraSpecs = [] - self._convert_extra_specs(extraSpecs, extraContent["extra_specs"], True) - flavor["extraSpecs"] = extraSpecs + extra_specs_vfc = [] + self._convert_extra_specs(extra_specs_vfc, extraContent["extra_specs"], True) + flavor["extraSpecs"] = extra_specs_vfc VimDriverUtils.replace_key_by_mapping(flavor, self.keys_mapping) @@ -200,9 +201,9 @@ class Flavors(APIView): extraResp = self._get_flavor_extra_specs(sess, flavor["id"]) extraContent = extraResp.json() if extraContent["extra_specs"]: - extraSpecs = [] - self._convert_extra_specs(extraSpecs, extraContent["extra_specs"], True) - flavor["extraSpecs"] = extraSpecs + extra_specs_vfc = [] + self._convert_extra_specs(extra_specs_vfc, extraContent["extra_specs"], True) + flavor["extraSpecs"] = extra_specs_vfc VimDriverUtils.replace_key_by_mapping(flavor, self.keys_mapping) vim_dict = { @@ -214,7 +215,7 @@ class Flavors(APIView): flavor.update(vim_dict) return Response(data=flavor, status=tmpresp.status_code) - extraSpecs = request.data.pop("extraSpecs", None) + extra_specs_vfc = request.data.pop("extraSpecs", None) #create flavor first resp = self._create_flavor(sess, request) if resp.status_code == 202: @@ -224,18 +225,18 @@ class Flavors(APIView): flavorid = resp_body['id'] - if extraSpecs: - extra_specs={} - self._convert_extra_specs(extraSpecs, extra_specs, False) + if extra_specs_vfc: + extra_specs_openstack={} + self._convert_extra_specs(extra_specs_vfc, extra_specs_openstack, False) - extraResp = self._create_flavor_extra_specs(sess, extra_specs, flavorid) + extraResp = self._create_flavor_extra_specs(sess, extra_specs_openstack, flavorid) if extraResp.status_code == 200: #combine the response body and return - tmpSpecs = [] + tmp_specs_vfc = [] tmpRespBody = extraResp.json() - self._convert_extra_specs(tmpSpecs, tmpRespBody['extra_specs'], True) + self._convert_extra_specs(tmp_specs_vfc, tmpRespBody['extra_specs'], True) - resp_body.update({"extraSpecs":tmpSpecs}) + resp_body.update({"extraSpecs":tmp_specs_vfc}) else: #rollback self._delete_flavor(self, request, vimid, tenantid, flavorid) diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py index ba77dc55..cf2fffef 100644 --- a/share/newton_base/openoapi/server.py +++ b/share/newton_base/openoapi/server.py @@ -169,17 +169,17 @@ class Servers(APIView): logger.info("request returns with status %s" % resp.status_code) logger.debug("Servers--dettachVolume resp status::>%s" % resp.status_code) - def _convert_metadata(self, metadata, metadata_output, reverse=True): + def _convert_metadata(self, metadata_vfc, metadata_openstack, reverse=True): if not reverse: - # from extraSpecs to extra_specs - for spec in metadata: - metadata_output[spec['keyName']] = spec['value'] + # from vfc format to openstack format + for spec in metadata_vfc: + metadata_openstack[spec['keyName']] = spec['value'] else: - for k, v in metadata_output.items(): + for k, v in metadata_openstack.items(): spec = {} spec['keyName'] = k spec['value'] = v - metadata.append(spec) + metadata_vfc.append(spec) def _convert_resp(self, server): #convert volumeArray @@ -274,11 +274,11 @@ class Servers(APIView): if not serverid: # convert the key naming in servers for server in content["servers"]: - metadata = server.pop("metadata", None) - if metadata: - meta_data = [] - self._convert_metadata(metadata, meta_data, False) - server["metadata"] = meta_data + metadata_openstack = server.pop("metadata", None) + if metadata_openstack: + metadata_vfc = [] + self._convert_metadata(metadata_vfc, metadata_openstack, True) + server["metadata"] = metadata_vfc VimDriverUtils.replace_key_by_mapping(server, self.keys_mapping) self._convert_resp(server) @@ -287,11 +287,11 @@ class Servers(APIView): else: # convert the key naming in the server specified by id server = content.pop("server", None) - metadata = server.pop("metadata", None) - if metadata: - meta_data = [] - self._convert_metadata(metadata, meta_data) - server["metadata"] = meta_data + metadata_openstack = server.pop("metadata", None) + if metadata_openstack: + metadata_vfc = [] + self._convert_metadata(metadata_vfc, metadata_openstack, True) + server["metadata"] = metadata_vfc VimDriverUtils.replace_key_by_mapping(server, self.keys_mapping) self._convert_resp(server) @@ -353,11 +353,11 @@ class Servers(APIView): if len(networks) > 0: server["networks"] = networks - meta_data = server.pop("metadata", None) - if meta_data: - metadata = {} - self._convert_metadata(metadata, meta_data, False) - server["metadata"] = metadata + metadata_vfc = server.pop("metadata", None) + if metadata_vfc: + metadata_openstack = {} + self._convert_metadata(metadata_vfc, metadata_openstack, False) + server["metadata"] = metadata_openstack contextarray = server.pop("contextArray", None) volumearray = server.pop("volumeArray", None) @@ -404,11 +404,11 @@ class Servers(APIView): volumeIds = [extraVolume["volumeId"] for extraVolume in volumearray] self._attachVolume(vimid, tenantid, resp_body["id"], *volumeIds) - metadata = resp_body.pop("metadata", None) - if metadata: - meta_data = [] - self._convert_metadata(metadata, meta_data) - resp_body["metadata"] = meta_data + metadata_openstack = resp_body.pop("metadata", None) + if metadata_openstack: + metadata_vfc = [] + self._convert_metadata(metadata_vfc, metadata_openstack, True) + resp_body["metadata"] = metadata_vfc VimDriverUtils.replace_key_by_mapping(resp_body, self.keys_mapping) vim_dict = { |