summaryrefslogtreecommitdiffstats
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
parent8d0fd7d9733ab8c1072aa728d46f08674f7194d5 (diff)
Add swagger for identity proxy
Change-Id: Ia77b99c9ffc68f897948e2ab7d6e68ca3affba82 Issue-Id: MULTICLOUD-89 Signed-off-by: Bin Yang <bin.yang@windriver.com>
-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
-rw-r--r--ocata/ocata/swagger/views.py2
-rw-r--r--ocata/vagrant/test/test_multicloud.sh2
6 files changed, 99 insertions, 10 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)
diff --git a/ocata/ocata/swagger/views.py b/ocata/ocata/swagger/views.py
index 0a90e1e6..e2f97e73 100644
--- a/ocata/ocata/swagger/views.py
+++ b/ocata/ocata/swagger/views.py
@@ -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)
diff --git a/ocata/vagrant/test/test_multicloud.sh b/ocata/vagrant/test/test_multicloud.sh
index d5f56dea..dc007431 100644
--- a/ocata/vagrant/test/test_multicloud.sh
+++ b/ocata/vagrant/test/test_multicloud.sh
@@ -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