Add swagger for identity proxy 89/12689/2
authorBin Yang <bin.yang@windriver.com>
Fri, 15 Sep 2017 09:32:41 +0000 (17:32 +0800)
committerBin Yang <bin.yang@windriver.com>
Fri, 15 Sep 2017 09:32:41 +0000 (17:32 +0800)
Change-Id: Ia77b99c9ffc68f897948e2ab7d6e68ca3affba82
Issue-Id: MULTICLOUD-89
Signed-off-by: Bin Yang <bin.yang@windriver.com>
newton/newton/proxy/views/identityV3.py
newton/newton/proxy/views/services.py
newton/newton/swagger/multicloud.identity.swagger.json [new file with mode: 0644]
newton/newton/swagger/views.py
ocata/ocata/swagger/views.py
ocata/vagrant/test/test_multicloud.sh

index 8f14f38..1afe14c 100644 (file)
@@ -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)
index 1143464..6e166f9 100644 (file)
@@ -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 (file)
index 0000000..b802064
--- /dev/null
@@ -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"
+                    }
+                }
+            }
+        }
+    }
+}
index 00d5f3e..10f3c0c 100644 (file)
@@ -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)
 
index 0a90e1e..e2f97e7 100644 (file)
@@ -37,7 +37,7 @@ class SwaggerJsonView(newton_json_view.SwaggerJsonView):
         json_data = resp.data if resp else None
         if json_data:
             json_data["basePath"] = "/api/multicloud-ocata/v0/"
-            json_data["info"]["title"] = "MultiVIM driver of OpenStack Ocata Service NBI"
+            json_data["info"]["title"] = "Service NBI of MultiCloud plugin for OpenStack Newton"
             return Response(data=json_data, status=200)
         else:
             return Response(data={'error':'internal error'}, status=500)
index d5f56de..dc00743 100644 (file)
@@ -8,7 +8,7 @@ sudo docker build -t multicloud-ocata:latest .
 cd /vagrant/test
 sudo docker build -t multicloud-ocata-test:latest .
 sudo docker network create --subnet=172.16.77.0/24 onap
-sudo docker run -d -t  --name ocata-test --network onap --ip 172.16.77.40 -e MSB_ADDR=172.16.77.40:9003 multicloud-ocata-test
+sudo docker run -d -t  --name ocata-test --network onap --ip 172.16.77.40 -e MSB_ADDR=172.16.77.40 -e MSB_PORT=9004 multicloud-ocata-test
 
 while true; do
     sleep 10