diff options
-rw-r--r-- | newton/newton/requests/tests/test_flavor.py | 4 | ||||
-rw-r--r-- | ocata/ocata/urls.py | 6 | ||||
-rw-r--r-- | pike/pike/urls.py | 6 | ||||
-rw-r--r-- | share/newton_base/openoapi/flavor.py | 2 | ||||
-rw-r--r-- | share/newton_base/openoapi/server.py | 117 | ||||
-rw-r--r-- | share/newton_base/openoapi/tenants.py | 4 | ||||
-rw-r--r-- | share/newton_base/registration/registration.py | 2 |
7 files changed, 75 insertions, 66 deletions
diff --git a/newton/newton/requests/tests/test_flavor.py b/newton/newton/requests/tests/test_flavor.py index 4a9df9c5..ef7ec86a 100644 --- a/newton/newton/requests/tests/test_flavor.py +++ b/newton/newton/requests/tests/test_flavor.py @@ -174,7 +174,7 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): "content": self.MOCK_GET_RESOURCES_RESPONSE}, "post": { "content": self.MOCK_POST_RESOURCE_RESPONSE, - "status_code": status.HTTP_202_ACCEPTED, + "status_code": status.HTTP_200_OK, } } ), @@ -190,7 +190,7 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertIsNotNone(context['id']) self.assertEqual(1, context['returnCode']) diff --git a/ocata/ocata/urls.py b/ocata/ocata/urls.py index d1601d6c..a055af4a 100644 --- a/ocata/ocata/urls.py +++ b/ocata/ocata/urls.py @@ -46,11 +46,11 @@ urlpatterns = [ vesagent_ctrl.VesAgentCtrl.as_view()), # API upgrading - url(r'^api/multicloud-ocata/v1/(?P<vimid>[0-9a-zA-Z_-]+)/registry$', + url(r'^api/multicloud-ocata/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/registry$', registration.RegistryV1.as_view()), - url(r'^api/multicloud-ocata/v1/(?P<vimid>[0-9a-zA-Z_-]+)$', + url(r'^api/multicloud-ocata/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)$', registration.RegistryV1.as_view()), - url(r'^api/multicloud-ocata/v1/(?P<vimid>[0-9a-zA-Z_-]+)/exten', + url(r'^api/multicloud-ocata/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/exten', include('ocata.extensions.urlsV1')), url(r'^api/multicloud-ocata/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/', include('ocata.proxy.urlsV1')), diff --git a/pike/pike/urls.py b/pike/pike/urls.py index 264b4a77..8b8eb3be 100644 --- a/pike/pike/urls.py +++ b/pike/pike/urls.py @@ -39,11 +39,11 @@ urlpatterns = [ url(r'^api/multicloud-pike/v0/(?P<vimid>[0-9a-zA-Z_-]+)/infra_workload/(?P<requri>[0-9a-zA-Z_-]*)/?$', infra_workload.InfraWorkload.as_view()), # API upgrading - url(r'^api/multicloud-pike/v1/(?P<vimid>[0-9a-zA-Z_-]+)/registry$', + url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/registry$', registration.RegistryV1.as_view()), - url(r'^api/multicloud-pike/v1/(?P<vimid>[0-9a-zA-Z_-]+)$', + url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)$', registration.RegistryV1.as_view()), - url(r'^api/multicloud-pike/v1/(?P<vimid>[0-9a-zA-Z_-]+)/exten', + url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/exten', include('pike.extensions.urlsV1')), url(r'^api/multicloud-pike/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/', include('pike.proxy.urlsV1')), 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) |