diff options
-rw-r--r-- | zte/vmanager/driver/interfaces/urls.py | 4 | ||||
-rw-r--r-- | zte/vmanager/driver/interfaces/views.py | 38 |
2 files changed, 40 insertions, 2 deletions
diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py index e3f55bb9..fe70e460 100644 --- a/zte/vmanager/driver/interfaces/urls.py +++ b/zte/vmanager/driver/interfaces/urls.py @@ -31,6 +31,8 @@ urlpatterns = [ views.operation_status, name='operation_status'), url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/resource/grant$', views.grantvnf, name='grantvnf'), url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfs/lifecyclechangesnotification$', views.notify, name='notify'), - url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<nfInstanceId>[0-9a-zA-Z\-\_]+)/scale$', + url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/scale$', views.scale, name='scale'), + url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/heal$', + views.heal, name='heal'), url(r'^samples/$', views.samples, name='samples'), ] diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py index ce625a35..ec0342d9 100644 --- a/zte/vmanager/driver/interfaces/views.py +++ b/zte/vmanager/driver/interfaces/views.py @@ -432,7 +432,7 @@ def scale(request, *args, **kwargs): logger.info("request.data = %s", request.data) logger.info("requested_url = %s", request.get_full_path()) vnfm_id = ignorcase_get(kwargs, "vnfmid") - nf_instance_id = ignorcase_get(kwargs, "nfInstanceId") + nf_instance_id = ignorcase_get(kwargs, "vnfInstanceId") ret = vnfm_get(vnfm_id) if ret[0] != 0: return Response(data={'error': ret[1]}, status=ret[2]) @@ -477,6 +477,42 @@ def scale(request, *args, **kwargs): return Response(data={'error':'scale expection'}, status='500') return Response(data=resp_data, status=ret[2]) +@api_view(http_method_names=['POST']) +def heal(request, *args, **kwargs): + logger.info("====heal_vnf===") + try: + logger.info("request.data = %s", request.data) + logger.info("requested_url = %s", request.get_full_path()) + vnfm_id = ignorcase_get(kwargs, "vnfmid") + nf_instance_id = ignorcase_get(kwargs, "vnfInstanceId") + ret = vnfm_get(vnfm_id) + if ret[0] != 0: + return Response(data={'error': ret[1]}, status=ret[2]) + vnfm_info = json.JSONDecoder().decode(ret[1]) + data = request.data + data['lifecycleoperation'] = 'operate' + data['isgrace'] = 'force' + + logger.info("data = %s", data) + ret = restcall.call_req( + base_url=ignorcase_get(vnfm_info, "url"), + user=ignorcase_get(vnfm_info, "userName"), + passwd=ignorcase_get(vnfm_info, "password"), + auth_type=restcall.rest_no_auth, + resource=nf_scaling_url.format(vnfInstanceID=nf_instance_id), + method='put', # POST + content=json.JSONEncoder().encode(data)) + logger.info("ret=%s", ret) + if ret[0] != 0: + return Response(data={'error': 'heal error'}, status=ret[2]) + resp_data = json.JSONDecoder().decode(ret[1]) + # jobId = resp_data["jobid"] + logger.info("resp_data=%s", resp_data) + except Exception as e: + logger.error("Error occurred when healing VNF") + logger.error(traceback.format_exc()) + return Response(data={'error': 'heal expection'}, status='500') + return Response(data=resp_data, status=ret[2]) #@staticmethod def get_vdus(nf_model, aspect_id): |