diff options
Diffstat (limited to 'zte')
-rw-r--r-- | zte/vmanager/docker/Dockerfile | 3 | ||||
-rw-r--r-- | zte/vmanager/driver/settings.py | 71 | ||||
-rw-r--r-- | zte/vmanager/driver/swagger/management/__init__.py (renamed from zte/vmanager/driver/swagger/views.py) | 15 | ||||
-rw-r--r-- | zte/vmanager/driver/swagger/management/commands/__init__.py (renamed from zte/vmanager/driver/swagger/tests.py) | 19 | ||||
-rw-r--r-- | zte/vmanager/driver/swagger/management/commands/export_swagger.py | 36 | ||||
-rw-r--r-- | zte/vmanager/driver/swagger/swagger.json | 545 | ||||
-rw-r--r-- | zte/vmanager/driver/swagger/urls.py | 1 |
7 files changed, 78 insertions, 612 deletions
diff --git a/zte/vmanager/docker/Dockerfile b/zte/vmanager/docker/Dockerfile index 71d66bd5..a9414d79 100644 --- a/zte/vmanager/docker/Dockerfile +++ b/zte/vmanager/docker/Dockerfile @@ -6,6 +6,9 @@ ARG HTTPS_PROXY=${HTTPS_PROXY} ENV http_proxy $HTTP_PROXY ENV https_proxy $HTTPS_PROXY +RUN sed -i "s|set compatible|set nocompatible|" /etc/vim/vimrc.tiny +RUN echo "set backspace=2" >> /etc/vim/vimrc.tiny + RUN apt-get update && \ apt-get install -y python-virtualenv && \ apt-get install -y python-setuptools && \ diff --git a/zte/vmanager/driver/settings.py b/zte/vmanager/driver/settings.py index e708020c..c2f6c971 100644 --- a/zte/vmanager/driver/settings.py +++ b/zte/vmanager/driver/settings.py @@ -14,6 +14,7 @@ import os import sys +import platform from logging import config from onaplogging import monkey monkey.patch_all() @@ -46,6 +47,7 @@ INSTALLED_APPS = [ 'rest_framework', 'driver.pub.database', 'driver.interfaces', + 'driver.swagger', 'drf_yasg', ] @@ -114,47 +116,48 @@ TIME_ZONE = 'UTC' # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_URL = '/static/' -# -# LOGGING = { -# 'version': 1, -# 'disable_existing_loggers': True, -# 'formatters': { -# 'standard': { -# 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', -# }, -# }, -# 'filters': { -# }, -# 'handlers': { -# 'driver_handler': { -# 'level': 'DEBUG', -# 'class': 'logging.handlers.RotatingFileHandler', -# 'filename': os.path.join( -# BASE_DIR, -# 'logs/runtime_driver.log'), -# 'formatter': 'standard', -# 'maxBytes': 1024 * 1024 * 50, -# 'backupCount': 5, -# }, -# }, -# 'loggers': { -# 'driver': { -# 'handlers': ['driver_handler'], -# 'level': 'DEBUG', -# 'propagate': False}, -# }} - -LOGGING_CONFIG = None + +if platform.system() == 'Windows' or 'test' in sys.argv: + LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'standard': { + 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', + }, + }, + 'filters': { + }, + 'handlers': { + 'driver_handler': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': os.path.join( + BASE_DIR, + 'logs/runtime_driver.log'), + 'formatter': 'standard', + 'maxBytes': 1024 * 1024 * 50, + 'backupCount': 5, + }, + }, + 'loggers': { + 'driver': { + 'handlers': ['driver_handler'], + 'level': 'DEBUG', + 'propagate': False}, + }} +else: + LOGGING_CONFIG = None # yaml configuration of logging -LOGGING_FILE = os.path.join(BASE_DIR, 'driver/log.yml') -config.yamlConfig(filepath=LOGGING_FILE, watchDog=True) + LOGGING_FILE = os.path.join(BASE_DIR, 'driver/log.yml') + config.yamlConfig(filepath=LOGGING_FILE, watchDog=True) if 'test' in sys.argv: + from driver.pub.config import config config.REG_TO_MSB_WHEN_START = False REST_FRAMEWORK = {} - import platform if platform.system() == 'Linux': TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner' TEST_OUTPUT_VERBOSE = True diff --git a/zte/vmanager/driver/swagger/views.py b/zte/vmanager/driver/swagger/management/__init__.py index 400d6dd1..342c2a8c 100644 --- a/zte/vmanager/driver/swagger/views.py +++ b/zte/vmanager/driver/swagger/management/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 ZTE Corporation. +# 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. @@ -11,16 +11,3 @@ # 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 os -import json -from rest_framework.views import APIView -from rest_framework.response import Response - - -class SwaggerView(APIView): - def get(self, request, format=None): - 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/zte/vmanager/driver/swagger/tests.py b/zte/vmanager/driver/swagger/management/commands/__init__.py index 981329a7..342c2a8c 100644 --- a/zte/vmanager/driver/swagger/tests.py +++ b/zte/vmanager/driver/swagger/management/commands/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 ZTE Corporation. +# 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. @@ -11,20 +11,3 @@ # 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 django.test import Client -from rest_framework import status - - -class SwaggerViewTest(unittest.TestCase): - def setUp(self): - self.client = Client() - - def tearDown(self): - pass - - def test_sample(self): - response = self.client.get("/api/ztevnfmdriver/v1/swagger.json") - self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) diff --git a/zte/vmanager/driver/swagger/management/commands/export_swagger.py b/zte/vmanager/driver/swagger/management/commands/export_swagger.py new file mode 100644 index 00000000..4971022f --- /dev/null +++ b/zte/vmanager/driver/swagger/management/commands/export_swagger.py @@ -0,0 +1,36 @@ +# 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 + +from django.core.management.base import BaseCommand +from django.test import Client + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument( + '-f', + '--name', + action='store', + dest='name', + default='swagger.json', + help='name of swagger file.', + ) + + def handle(self, *args, **options): + self.client = Client() + response = self.client.get("/api/ztevnfmdriver/v1/swagger.json") + with open(options['name'], 'w') as swagger_file: + swagger_file.write(json.dumps(response.data)) + print "swagger api is written to %s" % options['name'] diff --git a/zte/vmanager/driver/swagger/swagger.json b/zte/vmanager/driver/swagger/swagger.json deleted file mode 100644 index dfe53df9..00000000 --- a/zte/vmanager/driver/swagger/swagger.json +++ /dev/null @@ -1,545 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "ZTE VNFM Driver Service rest API" - }, - "basePath": "/api/ztevnfmdriver/v1", - "tags": [ - { - "name": "ztevnfmdriver" - } - ], - "paths": { - "/{vnfmid}/vnfs": { - "post": { - "tags": [ - "vnf instantiate" - ], - "summary": "instantiate the vnf", - "description": "", - "operationId": "instantiate_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfmid", - "in": "path", - "description": "vnfm instance id", - "required": true, - "type": "string" - }, - { - "name": "body", - "in": "body", - "description": "request parameters", - "required": true, - "schema": { - "$ref": "#/definitions/VnfRequestParams" - } - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/VnfResult" - } - }, - "404": { - "description": "the vnfm instance id is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfmid}/vnfs/{vnfInstanceId}/terminate": { - "post": { - "tags": [ - "vnf terminate" - ], - "summary": "terminate the vnf", - "description": "", - "operationId": "terminate_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfmid", - "in": "path", - "description": "vnfm instance id", - "required": true, - "type": "string" - }, - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/VnfResult" - } - }, - "404": { - "description": "the vnfmid and vnfInstanceId are wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfmid}/vnfs/{vnfInstanceId}": { - "get": { - "tags": [ - "query vnf" - ], - "summary": "query the vnf", - "description": "", - "operationId": "query_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfmid", - "in": "path", - "description": "vnfm instance id", - "required": true, - "type": "string" - }, - { - "name": "vnfInstanceId", - "in": "path", - "description": "vnf instance id", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/returnVnfInfo" - } - }, - "404": { - "description": "the vnfmid and vnfInstanceId are wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfmid}/jobs/{jobid}": { - "get": { - "tags": [ - "operation status" - ], - "summary": "operation status", - "description": "", - "operationId": "operation_status", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfmid", - "in": "path", - "description": "vnfm instance id", - "required": true, - "type": "string" - }, - { - "name": "jobid", - "in": "path", - "description": "vnf job id", - "required": true, - "type": "string" - }, - { - "name": "responseId", - "in": "path", - "description": "vnf response id", - "required": true, - "type": "integer" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "$ref": "#/definitions/OperationStatusInfo" - } - }, - "404": { - "description": "the vnfmid ,jobid and responseId are wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/resource/grant": { - "put": { - "tags": [ - "grant vnf" - ], - "summary": "grant the vnf", - "description": "", - "operationId": "grant_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "body", - "in": "body", - "description": "request data for grant the vnf", - "required": true, - "schema": { - "$ref": "#/definitions/RequestGrantParams" - } - } - ], - "responses": { - "201": { - "description": "successful grant", - "schema": { - "$ref": "#/definitions/responseGrantResult" - } - }, - "404": { - "description": "the request body is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/vnfs/lifecyclechangesnotification": { - "post": { - "tags": [ - "life cycle changes notification" - ], - "summary": "life cycle changes notification", - "description": "", - "operationId": "lifecyclechangesnotification", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "body", - "in": "body", - "description": "request data for grant the vnf", - "required": true, - "schema": { - "$ref": "#/definitions/RequestNotifyParams" - } - } - ], - "responses": { - "201": { - "description": "successful Notify", - "schema": { - "$ref": "#/definitions/ResponseNotifyResult" - } - }, - "404": { - "description": "the request body is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - }, - "/{vnfmid}/vnfs/{nfInstanceId}/scale": { - "post": { - "tags": [ - "scale vnf" - ], - "summary": "scale vnf", - "description": "", - "operationId": "scale_vnf", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "vnfmid", - "in": "path", - "description": "vnfm instance id", - "required": true, - "type": "string" - }, - { - "name": "nfInstanceId", - "in": "path", - "description": "nf instance id", - "required": true, - "type": "string" - }, - { - "name": "body", - "in": "body", - "description": "request data for grant the vnf", - "required": true, - "schema": { - "$ref": "#/definitions/RequestScaleParams" - } - } - ], - "responses": { - "201": { - "description": "successful scale", - "schema": { - "$ref": "#/definitions/ResponseScaleResult" - } - }, - "404": { - "description": "the request body is wrong" - }, - "500": { - "description": "the url is invalid" - } - } - } - } - }, - "definitions": { - "VnfRequestParams": { - "type": "object", - "properties": { - "vnfInstanceName": { - "type": "string" - }, - "vnfPackageId": { - "type": "string" - }, - "vnfDescriptorId": { - "type": "string" - }, - "additionalParam": { - "type": "object", - "properties": { - "sdncontroller": { - "type": "string" - }, - "NatIpRange": { - "type": "string" - }, - "m6000_mng_ip": { - "type": "string" - }, - "externalPluginManageNetworkName": { - "type": "string" - }, - "location": { - "type": "string" - }, - "externalManageNetworkName": { - "type": "string" - }, - "sfc_data_network": { - "type": "string" - }, - "externalDataNetworkName": { - "type": "string" - }, - "inputs": { - "type": "object" - } - } - } - } - }, - "VnfResult": { - "type": "object", - "properties": { - "vnfInstanceId": { - "type": "string" - }, - "jobId": { - "type": "string" - } - } - }, - "returnVnfInfo": { - "type": "object", - "properties": { - "vnfInfo": { - "type": "object", - "properties": { - "vnfStatus": { - "type": "string" - } - } - } - } - }, - "OperationStatusInfo": { - "type": "object", - "properties": { - "responsedescriptor": { - "type": "object", - "properties": { - "status": { - "type": "string" - }, - "responsehistorylist": { - "type": "string" - }, - "responseid": { - "type": "integer" - }, - "errorcode": { - "type": "string" - }, - "progress": { - "type": "integer" - }, - "statusdescription": { - "type": "string" - } - } - }, - "jobid": { - "type": "string" - } - } - }, - "RequestGrantParams": { - "type": "object", - "properties": { - "vnfmid": { - "type": "string" - }, - "nfvoid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "exvimidlist": { - "type": "string" - }, - "tenant": { - "type": "string" - }, - "vnfistanceid": { - "type": "string" - }, - "operationright": { - "type": "string" - }, - "vmlist": { - "type": "string" - } - } - }, - "responseGrantResult": { - "type": "object", - "properties": { - "vimid": { - "type": "string" - }, - "tenant": { - "type": "string" - } - } - }, - "RequestNotifyParams": { - "type": "object", - "properties": { - "nfvoid": { - "type": "string" - }, - "vnfmid": { - "type": "string" - }, - "vimid": { - "type": "string" - }, - "timestamp": { - "type": "string" - }, - "vnfinstanceid": { - "type": "string" - }, - "eventtype": { - "type": "string" - }, - "vmlist": { - "type": "string" - } - } - }, - "ResponseNotifyResult": { - "type": "object" - }, - "RequestScaleParams": { - "type": "object", - "properties": { - "type": { - "type": "string" - }, - "aspectId": { - "type": "string" - }, - "numberOfSteps": { - "type": "string" - }, - "additionalParam": { - "type": "object" - } - } - }, - "ResponseScaleResult": { - "type": "object", - "properties": { - "jobid": { - "type": "string" - }, - "nfInstanceId": { - "type": "string" - } - } - } - } -}
\ No newline at end of file diff --git a/zte/vmanager/driver/swagger/urls.py b/zte/vmanager/driver/swagger/urls.py index dc377d31..56c3c8b6 100644 --- a/zte/vmanager/driver/swagger/urls.py +++ b/zte/vmanager/driver/swagger/urls.py @@ -35,7 +35,6 @@ SchemaView = get_schema_view( ) urlpatterns = [ - # url(r'^api/ztevnfmdriver/v1/swagger.json$', views.SwaggerView.as_view()), url(r'^api/ztevnfmdriver/v1/swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'), url(r'^api/ztevnfmdriver/v1/swagger$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), url(r'^api/ztevnfmdriver/v1/redoc$', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc') |