summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2017-09-15 17:32:41 +0800
committerBin Yang <bin.yang@windriver.com>2017-09-15 17:32:41 +0800
commit2d2d9bed8b1990da7e0e763578684b0c1084c036 (patch)
treee8162cecf0531ccb0474293f41e68cd568345e68 /newton
parent8d0fd7d9733ab8c1072aa728d46f08674f7194d5 (diff)
Add swagger for identity proxy
Change-Id: Ia77b99c9ffc68f897948e2ab7d6e68ca3affba82 Issue-Id: MULTICLOUD-89 Signed-off-by: Bin Yang <bin.yang@windriver.com>
Diffstat (limited to 'newton')
-rw-r--r--newton/newton/proxy/views/identityV3.py4
-rw-r--r--newton/newton/proxy/views/services.py33
-rw-r--r--newton/newton/swagger/multicloud.identity.swagger.json59
-rw-r--r--newton/newton/swagger/views.py9
4 files changed, 97 insertions, 8 deletions
diff --git a/newton/newton/proxy/views/identityV3.py b/newton/newton/proxy/views/identityV3.py
index 8f14f389..1afe14cf 100644
--- a/newton/newton/proxy/views/identityV3.py
+++ b/newton/newton/proxy/views/identityV3.py
@@ -49,9 +49,11 @@ class Tokens(APIView):
resp = None
resp_body = None
try:
+ tenant_name = request.data.get("tenant_name")
+
# prepare request resource to vim instance
vim = VimDriverUtils.get_vim_info(vimid)
- sess = VimDriverUtils.get_session(vim)
+ sess = VimDriverUtils.get_session(vim, tenantname = tenant_name)
tmp_auth_state = VimDriverUtils.get_auth_state(vim, sess)
tmp_auth_info = json.loads(tmp_auth_state)
diff --git a/newton/newton/proxy/views/services.py b/newton/newton/proxy/views/services.py
index 1143464c..6e166f95 100644
--- a/newton/newton/proxy/views/services.py
+++ b/newton/newton/proxy/views/services.py
@@ -70,10 +70,13 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service head request uri %s" % (req_resource))
+
resp = sess.head(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
content = resp.json() if resp.content else None
+ self._logger.debug("service head response: %s, %s" % (resp.status_code, content))
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
@@ -141,10 +144,14 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service get request uri %s" % (req_resource))
+
resp = sess.get(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
content = resp.json() if resp.content else None
+ self._logger.debug("service get response: %s, %s" % (resp.status_code, content))
+
content = ProxyUtils.update_prefix(metadata_catalog, content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
@@ -213,10 +220,14 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service post request uri %s" % (req_resource))
+
resp = sess.post(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
content = resp.json() if resp.content else None
+ self._logger.debug("service post response: %s, %s" % (resp.status_code, content))
+
content = ProxyUtils.update_prefix(metadata_catalog, content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -285,10 +296,14 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service put request uri %s" % (req_resource))
+
resp = sess.put(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
content = resp.json() if resp.content else None
+ self._logger.debug("service put response: %s, %s" % (resp.status_code, content))
+
content = ProxyUtils.update_prefix(metadata_catalog, content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -358,10 +373,14 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service patch request uri %s" % (req_resource))
+
resp = sess.patch(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
content = resp.json() if resp.content else None
+ self._logger.debug("service patch response: %s, %s" % (resp.status_code, content))
+
content = ProxyUtils.update_prefix(metadata_catalog, content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -430,9 +449,11 @@ class Services(APIView):
'interface': interface,
'region_id': regionid}
+ self._logger.debug("service delete request uri %s" % (req_resource))
+
resp = sess.delete(req_resource, endpoint_filter=service)
# update token cache in case the token was required during the requests
- tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
+ #tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
return Response(headers={'X-Subject-Token': tmp_auth_token}, status=resp.status_code)
diff --git a/newton/newton/swagger/multicloud.identity.swagger.json b/newton/newton/swagger/multicloud.identity.swagger.json
new file mode 100644
index 00000000..b8020648
--- /dev/null
+++ b/newton/newton/swagger/multicloud.identity.swagger.json
@@ -0,0 +1,59 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "version": "1.0.0",
+ "title": "MultiCloud Identity Proxy rest API"
+ },
+ "basePath": "/api/multicloud-newton/v0/",
+ "tags": [
+ {
+ "name": "MultiCloud services"
+ }
+ ],
+ "paths": {
+ "/{vimid}/identity/v3/auth/tokens": {
+ "post": {
+ "tags": [
+ "MultiCloud Identity Proxy"
+ ],
+ "summary": "Authenticate and get Catalog of endpoints",
+ "description": "Authenticate to get token and catalog of service endpoints",
+ "operationId": "authenticate",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "vimid",
+ "in": "path",
+ "description": "vim instance id, composed by {cloud-owner}_{cloud-region-id}",
+ "required": true,
+ "type": "string"
+ },
+ {
+ "name": "tenant_name",
+ "in": "body",
+ "description": "tenant name",
+ "required": false,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "type": "string"
+ },
+ "404": {
+ "description": "the vim id or tenant name is wrong"
+ },
+ "500": {
+ "description": "the vim instance is not accessable"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/newton/newton/swagger/views.py b/newton/newton/swagger/views.py
index 00d5f3ed..10f3c0cc 100644
--- a/newton/newton/swagger/views.py
+++ b/newton/newton/swagger/views.py
@@ -83,7 +83,14 @@ class SwaggerJsonView(APIView):
f.close()
json_data["paths"].update(json_data_temp["paths"])
json_data["definitions"].update(json_data_temp["definitions"])
+
+ json_file = os.path.join(os.path.dirname(__file__), 'multicloud.identity.swagger.json')
+ f = open(json_file)
+ json_data_temp = json.JSONDecoder().decode(f.read())
+ f.close()
+ json_data["paths"].update(json_data_temp["paths"])
+
json_data["basePath"] = "/api/multicloud-newton/v0/"
- json_data["info"]["title"] = "MultiVIM driver of OpenStack Newton Service NBI"
+ json_data["info"]["title"] = "Service NBI of MultiCloud plugin for OpenStack Newton"
return Response(json_data)