diff options
Diffstat (limited to 'zte/vmanager')
-rw-r--r-- | zte/vmanager/driver/interfaces/serializers.py | 13 | ||||
-rw-r--r-- | zte/vmanager/driver/interfaces/urls.py | 2 | ||||
-rw-r--r-- | zte/vmanager/driver/interfaces/views.py | 99 |
3 files changed, 61 insertions, 53 deletions
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py index 6e9456ce..d2cd2bc1 100644 --- a/zte/vmanager/driver/interfaces/serializers.py +++ b/zte/vmanager/driver/interfaces/serializers.py @@ -79,6 +79,19 @@ class GrantReqSerializer(serializers.Serializer): required=False) +class GrantRespSerializer(serializers.Serializer): + vimid = serializers.CharField( + help_text="vimid", + max_length=255, + required=True, + allow_null=True) + tenant = serializers.CharField( + help_text="tenant", + max_length=255, + required=True, + allow_null=True) + + class VMIDlistSerializer(serializers.Serializer): VMID = serializers.CharField( help_text="VMID", diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py index 0167cfaa..d8fb6f66 100644 --- a/zte/vmanager/driver/interfaces/urls.py +++ b/zte/vmanager/driver/interfaces/urls.py @@ -24,7 +24,7 @@ urlpatterns = [ views.query_vnf, name='query_vnf'), url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/jobs/(?P<jobid>[0-9a-zA-Z\-\_]+)$', views.operation_status, name='operation_status'), - url(r'^api/ztevnfmdriver/v1/resource/grant$', views.grantvnf, name='grantvnf'), + url(r'^api/ztevnfmdriver/v1/resource/grant$', views.GrantVnf.as_view(), name='grantvnf'), url(r'^api/ztevnfmdriver/v1/vnfs/lifecyclechangesnotification$', views.Notify.as_view(), name='notify'), url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/scale$', views.Scale.as_view(), name='scale'), diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py index 0866301e..0eb2449d 100644 --- a/zte/vmanager/driver/interfaces/views.py +++ b/zte/vmanager/driver/interfaces/views.py @@ -25,7 +25,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer, \ - NotifyReqSerializer + NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer from driver.pub.config.config import VNF_FTP from driver.pub.utils import restcall from driver.pub.utils.restcall import req_by_msb @@ -257,58 +257,53 @@ def operation_status(request, *args, **kwargs): return Response(data=resp_data, status=ret[2]) -@api_view(http_method_names=['PUT']) -def grantvnf(request, *args, **kwargs): - logger.info("=====grantvnf=====") - try: - logger.info("req_data = %s", request.data) - grant_vnf_param_map = { - "VNFMID": "", - "NFVOID": "", - "VIMID": "", - "ExVIMIDList": "", - "ExVIMID": "", - "Tenant": "", - "VNFInstanceID": "vnfInstanceId", - "OperationRight": "", - "VMList": "", - "VMFlavor": "", - "VMNumber": "" - } - data = mapping_conv(grant_vnf_param_map, request.data) - data["vnfDescriptorId"] = "" - if ignorcase_get(request.data, "operationright") == 0: - data["lifecycleOperation"] = "Instantiate" - data["addresource"] = [] - for vm in ignorcase_get(request.data, "vmlist"): - for i in range(int(ignorcase_get(vm, "vmnumber"))): - data["addresource"].append( - { - "type": "vdu", - "resourceDefinitionId": i, - "vdu": ignorcase_get(vm, "vmflavor"), - "vimid": ignorcase_get(vm, "vimid"), - "tenant": ignorcase_get(vm, "tenant")}) - - data["additionalparam"] = {} - data["additionalparam"]["vnfmid"] = ignorcase_get(request.data, "vnfmid") - data["additionalparam"]["vimid"] = ignorcase_get(request.data, "vimid") - data["additionalparam"]["tenant"] = ignorcase_get(request.data, "tenant") - - ret = req_by_msb('api/nslcm/v1/ns/grantvnf', "POST", content=json.JSONEncoder().encode(data)) - logger.info("ret = %s", ret) - if ret[0] != 0: - return Response(data={'error': ret[1]}, status=ret[2]) - resp = json.JSONDecoder().decode(ret[1]) - resp_data = { - 'vimid': ignorcase_get(resp['vim'], 'vimid'), - 'tenant': ignorcase_get(ignorcase_get(resp['vim'], 'accessinfo'), 'tenant') +class GrantVnf(APIView): + @swagger_auto_schema( + request_body=GrantReqSerializer(), + responses={ + status.HTTP_201_CREATED: GrantRespSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: 'Internal error' } - logger.info("[%s]resp_data=%s", fun_name(), resp_data) - except Exception as e: - logger.error("Error occurred in Grant VNF.") - raise e - return Response(data=resp_data, status=ret[2]) + ) + def put(self, request): + logger.info("=====GrantVnf=====") + try: + logger.info("req_data = %s", request.data) + data = {} + data["vnfInstanceId"] = ignorcase_get(request.data, "vnfistanceid") + data["vnfDescriptorId"] = "" + if ignorcase_get(request.data, "operationright") == 0: + data["lifecycleOperation"] = "Instantiate" + data["addresource"] = [] + for vm in ignorcase_get(request.data, "vmlist"): + for i in range(int(ignorcase_get(vm, "vmnumber"))): + data["addresource"].append( + { + "type": "vdu", + "resourceDefinitionId": i, + "vdu": ignorcase_get(vm, "vmflavor"), + "vimid": ignorcase_get(vm, "vimid"), + "tenant": ignorcase_get(vm, "tenant")}) + + data["additionalparam"] = {} + data["additionalparam"]["vnfmid"] = ignorcase_get(request.data, "vnfmid") + data["additionalparam"]["vimid"] = ignorcase_get(request.data, "vimid") + data["additionalparam"]["tenant"] = ignorcase_get(request.data, "tenant") + + ret = req_by_msb('api/nslcm/v1/ns/grantvnf', "POST", content=json.JSONEncoder().encode(data)) + logger.info("ret = %s", ret) + if ret[0] != 0: + return Response(data={'error': ret[1]}, status=ret[2]) + resp = json.JSONDecoder().decode(ret[1]) + resp_data = { + 'vimid': ignorcase_get(resp['vim'], 'vimid'), + 'tenant': ignorcase_get(ignorcase_get(resp['vim'], 'accessinfo'), 'tenant') + } + logger.info("[%s]resp_data=%s", fun_name(), resp_data) + return Response(data=resp_data, status=status.HTTP_201_CREATED) + except Exception as e: + logger.error("Error occurred in Grant VNF.") + raise e class Notify(APIView): |