From 09a21ea186aff5cbee6dcc5573f570f49c251812 Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Thu, 25 Jan 2018 13:14:02 +0800 Subject: Refactor vfc-vnfres swagger function. Change-Id: If403d965ddaf7f6d270ebb490a98025e8506f88b Issue-ID: VFC-679 Signed-off-by: ying.yunlong --- res/res/resources/swagger.json | 633 ----------------------------------------- res/res/resources/tests.py | 4 - res/res/resources/urls.py | 2 - res/res/resources/views.py | 17 +- res/res/swagger/__init__.py | 13 + res/res/swagger/swagger.json | 633 +++++++++++++++++++++++++++++++++++++++++ res/res/swagger/tests.py | 29 ++ res/res/swagger/urls.py | 20 ++ res/res/swagger/views.py | 27 ++ res/res/urls.py | 1 + 10 files changed, 726 insertions(+), 653 deletions(-) delete mode 100644 res/res/resources/swagger.json create mode 100644 res/res/swagger/__init__.py create mode 100644 res/res/swagger/swagger.json create mode 100644 res/res/swagger/tests.py create mode 100644 res/res/swagger/urls.py create mode 100644 res/res/swagger/views.py diff --git a/res/res/resources/swagger.json b/res/res/resources/swagger.json deleted file mode 100644 index 47dccc8..0000000 --- a/res/res/resources/swagger.json +++ /dev/null @@ -1,633 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "ZTE vManager Service rest API" - }, - "host": "10.43.104.27:8000", - "basePath": "/api/vnfres/v1", - "tags": [ - { - "name": "res Resource" - } - ], - "paths": { - "/vnfs/{vnfInstanceId}": { - "get": { - "tags": [ - "vnf Resource" - ], - "summary": "query the single vnf info", - "description": "", - "operationId": "query_single_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/SingleVnfInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/vnfs": { - "get": { - "tags": [ - "vnfs Resource" - ], - "summary": "query the vnfs info", - "description": "", - "operationId": "query_many_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "", - "in": "path", - "description": "no param", - "required": true - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/VnfsInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/vms": { - "get": { - "tags": [ - "vms Resource" - ], - "summary": "query the specified vm info", - "description": "", - "operationId": "query_vms", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/VMInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/flavors": { - "get": { - "tags": [ - "flavors Resource" - ], - "summary": "query the specified flavor info", - "description": "", - "operationId": "query_flavors", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/FlavorInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/networks": { - "get": { - "tags": [ - "networks Resource" - ], - "summary": "query the specified network info", - "description": "", - "operationId": "query_networks", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/NetworkInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/subnets": { - "get": { - "tags": [ - "subnets Resource" - ], - "summary": "query the specified subnet info", - "description": "", - "operationId": "query_subnet", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/SubnetInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/cps": { - "get": { - "tags": [ - "sps Resource" - ], - "summary": "query the specified cp info", - "description": "", - "operationId": "query_cp", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/CpInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfInstanceId}/volumes": { - "get": { - "tags": [ - "sps Resource" - ], - "summary": "query the specified volumes info", - "description": "", - "operationId": "query_volumes", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/VolumesInfo" - } - }, - "404": { - "description": "the vnf instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - } - }, - "definitions": { - "SingleVnfInfo": { - "type": "object", - "properties": { - "vnfInstanceId": { - "type": "string" - }, - "vnfInstanceName": { - "type": "string" - }, - "vnfInstanceDescription": { - "type": "string" - }, - "onboardedVnfPkgInfoId": { - "type": "string" - }, - "vnfdId": { - "type": "string" - }, - "vnfdVersion": { - "type": "string" - }, - "vnfSoftwareVersion": { - "type": "string" - }, - "vnfProvider": { - "type": "string" - }, - "vnfProductName": { - "type": "string" - }, - "vnfConfigurableProperties": { - "type": "object" - }, - "instantiationState": { - "type": "string" - }, - "instantiatedVnfInfo": { - "type": "object", - "properties": { - "flavourId": { - "type": "string" - }, - "vnfState": { - "type": "string" - }, - "scaleStatus": { - "type": "array", - "items": { - "type": "object" - } - }, - "extCpInfo": { - "type": "array", - "items": { - "type": "object" - } - }, - "extVirtualLink": { - "type": "array", - "items": { - "type": "object" - } - }, - "monitoringParameters": { - "type": "object" - }, - "localizationLanguage": { - "type": "string" - }, - "vimInfo": { - "type": "array", - "items": { - "type": "object" - } - }, - "vnfcResourceInfo": { - "type": "array", - "items": { - "type": "object" - } - }, - "virtualLinkResourceInfo": { - "type": "array", - "items": { - "type": "object" - } - }, - "virtualStorageResourceInfo": { - "type": "array", - "items": { - "type": "object" - } - } - } - }, - "metadata": { - "type": "object" - }, - "extensions": { - "type": "object" - } - } - }, - "VnfsInfo": { - "type": "array", - "items": { - "type": "SingleVnfInfo" - } - }, - "VMInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "vmid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "resouceid": { - "type": "string" - }, - "insttype": { - "type": "integer" - }, - "instid": { - "type": "string" - }, - "vmname": { - "type": "string" - }, - "operationalstate": { - "type": "string" - }, - "availability_zone": { - "type": "string" - }, - "tenant": { - "type": "string" - }, - "nodeId": { - "type": "string" - }, - "metadata": { - "type": "string" - }, - "is_predefined": { - "type": "integer" - } - } - } - }, - "FlavorInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "flavourid": { - "type": "string" - }, - "name": { - "type": "string" - }, - "vcpu": { - "type": "integer" - }, - "memory": { - "type": "integer" - }, - "extraspecs": { - "type": "string" - }, - "instid": { - "type": "string" - }, - "tenant": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "create_time": { - "type": "string" - } - } - } - }, - "NetworkInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "networkid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "resouceid": { - "type": "string" - }, - "insttype": { - "type": "integer" - }, - "instid": { - "type": "string" - }, - "name": { - "type": "string" - } - } - } - }, - "SubnetInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "subnetworkid": { - "type": "string" - }, - "networkid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "resouceid": { - "type": "string" - }, - "insttype": { - "type": "integer" - }, - "instid": { - "type": "string" - }, - "name": { - "type": "string" - }, - "cidr": { - "type": "string" - } - } - } - }, - "CpInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "cpinstanceid": { - "type": "string" - }, - "cpdid": { - "type": "string" - }, - "cpinstancename": { - "type": "string" - }, - "vlinstanceid": { - "type": "string" - }, - "ownertype": { - "type": "integer" - }, - "ownerid": { - "type": "string" - }, - "relatedtype": { - "type": "integer" - } - } - } - }, - "VolumesInfo": { - "type": "array", - "items": { - "type": "object", - "properties": { - "storageid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "resouceid": { - "type": "string" - }, - "insttype": { - "type": "integer" - }, - "instid": { - "type": "string" - }, - "storagetype": { - "type": "string" - }, - "size": { - "type": "string" - } - } - } - } - } -} \ No newline at end of file diff --git a/res/res/resources/tests.py b/res/res/resources/tests.py index a6b9ead..7f5026e 100644 --- a/res/res/resources/tests.py +++ b/res/res/resources/tests.py @@ -219,7 +219,3 @@ class ResourceTest(TestCase): response = self.client.get("/api/vnfres/v1/%s/volumes" % self.nf_inst_id) self.assertEqual(self.volumes_data, response.data) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) - - def test_swagger_ok(self): - resp = self.client.get("/api/vnfres/v1/swagger.json", format="json") - self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.content) diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py index 5bcfb9a..e282e86 100644 --- a/res/res/resources/urls.py +++ b/res/res/resources/urls.py @@ -16,7 +16,6 @@ from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns from res.resources import views -from res.resources.views import SwaggerJsonView urlpatterns = [ url(r'^api/vnfres/v1/vnfs/(?P[0-9a-zA-Z\-\_]+)$', views.get_vnf, name='get_vnf'), @@ -27,7 +26,6 @@ urlpatterns = [ url(r'^api/vnfres/v1/(?P[0-9a-zA-Z\-\_]+)/subnets$', views.get_subnets, name='get_subnets'), url(r'^api/vnfres/v1/(?P[0-9a-zA-Z\-\_]+)/cps$', views.getCps.as_view(), name='get_cps'), url(r'^api/vnfres/v1/(?P[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'), - url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()), ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/res/res/resources/views.py b/res/res/resources/views.py index 049f584..70c38b3 100644 --- a/res/res/resources/views.py +++ b/res/res/resources/views.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import logging -import os import traceback from drf_yasg.utils import swagger_auto_schema @@ -23,11 +21,11 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework.views import APIView -from res.pub.exceptions import VNFRESException -from res.pub.utils.values import ignore_case_get -from res.pub.utils.syscomm import fun_name from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \ VNFCInstModel, VmInstModel, FlavourInstModel, SubNetworkInstModel, CPInstModel +from res.pub.exceptions import VNFRESException +from res.pub.utils.syscomm import fun_name +from res.pub.utils.values import ignore_case_get from res.resources.serializers import VolumeInfoSerializer, NoneSerializer, CpsInfoSerializer logger = logging.getLogger(__name__) @@ -388,12 +386,3 @@ def fill_volumes_data(v): "size": v.size } return volumes_data - - -class SwaggerJsonView(APIView): - def get(self, request): - json_file = os.path.join(os.path.dirname(__file__), 'swagger.json') - f = open(json_file) - json_data = json.JSONDecoder().decode(f.read()) - f.close() - return Response(json_data) diff --git a/res/res/swagger/__init__.py b/res/res/swagger/__init__.py new file mode 100644 index 0000000..342c2a8 --- /dev/null +++ b/res/res/swagger/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/res/res/swagger/swagger.json b/res/res/swagger/swagger.json new file mode 100644 index 0000000..47dccc8 --- /dev/null +++ b/res/res/swagger/swagger.json @@ -0,0 +1,633 @@ +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "ZTE vManager Service rest API" + }, + "host": "10.43.104.27:8000", + "basePath": "/api/vnfres/v1", + "tags": [ + { + "name": "res Resource" + } + ], + "paths": { + "/vnfs/{vnfInstanceId}": { + "get": { + "tags": [ + "vnf Resource" + ], + "summary": "query the single vnf info", + "description": "", + "operationId": "query_single_vnf", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/SingleVnfInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/vnfs": { + "get": { + "tags": [ + "vnfs Resource" + ], + "summary": "query the vnfs info", + "description": "", + "operationId": "query_many_vnf", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "", + "in": "path", + "description": "no param", + "required": true + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/VnfsInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/vms": { + "get": { + "tags": [ + "vms Resource" + ], + "summary": "query the specified vm info", + "description": "", + "operationId": "query_vms", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/VMInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/flavors": { + "get": { + "tags": [ + "flavors Resource" + ], + "summary": "query the specified flavor info", + "description": "", + "operationId": "query_flavors", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/FlavorInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/networks": { + "get": { + "tags": [ + "networks Resource" + ], + "summary": "query the specified network info", + "description": "", + "operationId": "query_networks", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/NetworkInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/subnets": { + "get": { + "tags": [ + "subnets Resource" + ], + "summary": "query the specified subnet info", + "description": "", + "operationId": "query_subnet", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/SubnetInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/cps": { + "get": { + "tags": [ + "sps Resource" + ], + "summary": "query the specified cp info", + "description": "", + "operationId": "query_cp", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/CpInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + }, + "/{vnfInstanceId}/volumes": { + "get": { + "tags": [ + "sps Resource" + ], + "summary": "query the specified volumes info", + "description": "", + "operationId": "query_volumes", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnf instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "$ref": "#/definitions/VolumesInfo" + } + }, + "404": { + "description": "the vnf instance id is wrong" + }, + "500": { + "description": "the url is invalid" + } + } + } + } + }, + "definitions": { + "SingleVnfInfo": { + "type": "object", + "properties": { + "vnfInstanceId": { + "type": "string" + }, + "vnfInstanceName": { + "type": "string" + }, + "vnfInstanceDescription": { + "type": "string" + }, + "onboardedVnfPkgInfoId": { + "type": "string" + }, + "vnfdId": { + "type": "string" + }, + "vnfdVersion": { + "type": "string" + }, + "vnfSoftwareVersion": { + "type": "string" + }, + "vnfProvider": { + "type": "string" + }, + "vnfProductName": { + "type": "string" + }, + "vnfConfigurableProperties": { + "type": "object" + }, + "instantiationState": { + "type": "string" + }, + "instantiatedVnfInfo": { + "type": "object", + "properties": { + "flavourId": { + "type": "string" + }, + "vnfState": { + "type": "string" + }, + "scaleStatus": { + "type": "array", + "items": { + "type": "object" + } + }, + "extCpInfo": { + "type": "array", + "items": { + "type": "object" + } + }, + "extVirtualLink": { + "type": "array", + "items": { + "type": "object" + } + }, + "monitoringParameters": { + "type": "object" + }, + "localizationLanguage": { + "type": "string" + }, + "vimInfo": { + "type": "array", + "items": { + "type": "object" + } + }, + "vnfcResourceInfo": { + "type": "array", + "items": { + "type": "object" + } + }, + "virtualLinkResourceInfo": { + "type": "array", + "items": { + "type": "object" + } + }, + "virtualStorageResourceInfo": { + "type": "array", + "items": { + "type": "object" + } + } + } + }, + "metadata": { + "type": "object" + }, + "extensions": { + "type": "object" + } + } + }, + "VnfsInfo": { + "type": "array", + "items": { + "type": "SingleVnfInfo" + } + }, + "VMInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "vmid": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "resouceid": { + "type": "string" + }, + "insttype": { + "type": "integer" + }, + "instid": { + "type": "string" + }, + "vmname": { + "type": "string" + }, + "operationalstate": { + "type": "string" + }, + "availability_zone": { + "type": "string" + }, + "tenant": { + "type": "string" + }, + "nodeId": { + "type": "string" + }, + "metadata": { + "type": "string" + }, + "is_predefined": { + "type": "integer" + } + } + } + }, + "FlavorInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "flavourid": { + "type": "string" + }, + "name": { + "type": "string" + }, + "vcpu": { + "type": "integer" + }, + "memory": { + "type": "integer" + }, + "extraspecs": { + "type": "string" + }, + "instid": { + "type": "string" + }, + "tenant": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "create_time": { + "type": "string" + } + } + } + }, + "NetworkInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "networkid": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "resouceid": { + "type": "string" + }, + "insttype": { + "type": "integer" + }, + "instid": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + }, + "SubnetInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "subnetworkid": { + "type": "string" + }, + "networkid": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "resouceid": { + "type": "string" + }, + "insttype": { + "type": "integer" + }, + "instid": { + "type": "string" + }, + "name": { + "type": "string" + }, + "cidr": { + "type": "string" + } + } + } + }, + "CpInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "cpinstanceid": { + "type": "string" + }, + "cpdid": { + "type": "string" + }, + "cpinstancename": { + "type": "string" + }, + "vlinstanceid": { + "type": "string" + }, + "ownertype": { + "type": "integer" + }, + "ownerid": { + "type": "string" + }, + "relatedtype": { + "type": "integer" + } + } + } + }, + "VolumesInfo": { + "type": "array", + "items": { + "type": "object", + "properties": { + "storageid": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "resouceid": { + "type": "string" + }, + "insttype": { + "type": "integer" + }, + "instid": { + "type": "string" + }, + "storagetype": { + "type": "string" + }, + "size": { + "type": "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/res/res/swagger/tests.py b/res/res/swagger/tests.py new file mode 100644 index 0000000..03bb77f --- /dev/null +++ b/res/res/swagger/tests.py @@ -0,0 +1,29 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest + +from rest_framework import status +from rest_framework.test import APIClient + + +class SwaggerViewTest(unittest.TestCase): + def setUp(self): + self.client = APIClient() + + def tearDown(self): + pass + + def test_swagger_ok(self): + resp = self.client.get("/api/vnfres/v1/swagger.json", format="json") + self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.content) diff --git a/res/res/swagger/urls.py b/res/res/swagger/urls.py new file mode 100644 index 0000000..3cfa7a6 --- /dev/null +++ b/res/res/swagger/urls.py @@ -0,0 +1,20 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from django.conf.urls import url + +from res.swagger.views import SwaggerJsonView + +urlpatterns = [ + url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()), +] diff --git a/res/res/swagger/views.py b/res/res/swagger/views.py new file mode 100644 index 0000000..cc5a4a3 --- /dev/null +++ b/res/res/swagger/views.py @@ -0,0 +1,27 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import json +import os + +from rest_framework.response import Response +from rest_framework.views import APIView + + +class SwaggerJsonView(APIView): + def get(self, request): + json_file = os.path.join(os.path.dirname(__file__), 'swagger.json') + f = open(json_file) + json_data = json.JSONDecoder().decode(f.read()) + f.close() + return Response(json_data) diff --git a/res/res/urls.py b/res/res/urls.py index b9c08ca..83bbdaf 100644 --- a/res/res/urls.py +++ b/res/res/urls.py @@ -37,6 +37,7 @@ SchemaView = get_schema_view( urlpatterns = [ url(r'^', include('res.samples.urls')), + url(r'^', include('res.swagger.urls')), url(r'^', include('res.resources.urls')), url(r'^swagger(?P.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'), url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), -- cgit 1.2.3-korg