summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/newton_base/openoapi/flavor.py2
-rw-r--r--share/newton_base/openoapi/server.py117
-rw-r--r--share/newton_base/openoapi/tenants.py4
-rw-r--r--share/newton_base/registration/registration.py2
4 files changed, 67 insertions, 58 deletions
diff --git a/share/newton_base/openoapi/flavor.py b/share/newton_base/openoapi/flavor.py
index b0a6bf6c..8dcd10f6 100644
--- a/share/newton_base/openoapi/flavor.py
+++ b/share/newton_base/openoapi/flavor.py
@@ -232,7 +232,7 @@ class Flavors(APIView):
extra_specs_vfc = request.data.pop("extraSpecs", None)
#create flavor first
resp = self._create_flavor(sess, request)
- if resp.status_code == 202:
+ if resp.status_code == 200:
resp_body = resp.json()["flavor"]
else:
return resp
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py
index 57f76196..be79c466 100644
--- a/share/newton_base/openoapi/server.py
+++ b/share/newton_base/openoapi/server.py
@@ -182,17 +182,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_vfc, metadata_openstack, reverse=True):
- if not reverse:
- # from vfc format to openstack format
- for spec in metadata_vfc:
- metadata_openstack[spec['keyName']] = spec['value']
- else:
- for k, v in metadata_openstack.items():
- spec = {}
- spec['keyName'] = k
- spec['value'] = v
- metadata_vfc.append(spec)
+ #def _convert_metadata(self, metadata_vfc, metadata_openstack, reverse=True):
+ # if not reverse:
+ # # from vfc format to openstack format
+ # for spec in metadata_vfc:
+ # metadata_openstack[spec['keyName']] = spec['value']
+ # else:
+ # for k, v in metadata_openstack.items():
+ # spec = {}
+ # spec['keyName'] = k
+ # spec['value'] = v
+ # metadata_vfc.append(spec)
def _convert_resp(self, server):
#convert volumeArray
@@ -299,11 +299,11 @@ class Servers(APIView):
if not serverid:
# convert the key naming in servers
for server in content["servers"]:
- metadata_openstack = server.pop("metadata", None)
- if metadata_openstack:
- metadata_vfc = []
- self._convert_metadata(metadata_vfc, metadata_openstack, True)
- server["metadata"] = metadata_vfc
+ #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)
@@ -312,11 +312,11 @@ class Servers(APIView):
else:
# convert the key naming in the server specified by id
server = content.pop("server", None)
- metadata_openstack = server.pop("metadata", None)
- if metadata_openstack:
- metadata_vfc = []
- self._convert_metadata(metadata_vfc, metadata_openstack, True)
- server["metadata"] = metadata_vfc
+ #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)
@@ -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"]:
@@ -378,47 +379,55 @@ class Servers(APIView):
if len(networks) > 0:
server["networks"] = networks
- metadata_vfc = server.pop("metadata", None)
- if metadata_vfc:
- metadata_openstack = {}
- self._convert_metadata(metadata_vfc, metadata_openstack, False)
- server["metadata"] = metadata_openstack
+ #metadata_vfc = server.pop("metadata", None)
+ #if metadata_vfc:
+ # metadata_openstack = {}
+ # 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,
@@ -434,11 +443,11 @@ class Servers(APIView):
volumeIds = [extraVolume["volumeId"] for extraVolume in volumearray]
self._attachVolume(vimid, tenantid, resp_body["id"], *volumeIds)
- 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
+ #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 = {
diff --git a/share/newton_base/openoapi/tenants.py b/share/newton_base/openoapi/tenants.py
index 71439411..a048a36e 100644
--- a/share/newton_base/openoapi/tenants.py
+++ b/share/newton_base/openoapi/tenants.py
@@ -48,8 +48,8 @@ class Tenants(APIView):
vim = VimDriverUtils.get_vim_info(vimid)
req_resouce = "/projects"
- if '/v2' in vim["url"]:
- req_resouce = "/v2.0/tenants"
+ if '/v2.0' in vim["url"]:
+ req_resouce = "/tenants"
sess = VimDriverUtils.get_session(vim)
diff --git a/share/newton_base/registration/registration.py b/share/newton_base/registration/registration.py
index 54b1d48c..35f3b982 100644
--- a/share/newton_base/registration/registration.py
+++ b/share/newton_base/registration/registration.py
@@ -1007,7 +1007,7 @@ class Registry(APIView):
#self._discover_volumegroups(vimid, sess, viminfo)
# discover all snapshots
- self._discover_snapshots(vimid, sess, viminfo)
+ #self._discover_snapshots(vimid, sess, viminfo)
# discover all server groups
#self.discover_servergroups(request, vimid, sess, viminfo)