X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=instancehandler%2Fviews.py;h=45120e2842893a0f132816fd1d32fa0cd3025835;hb=6e240e970b0f01790b20cff77f2a49d1f66834b6;hp=212fbbf59f4988450e9f5c065ce455100d67c808;hpb=0b4fb877a77e112fd242ff244be8c9eb613447a7;p=osm%2FLW-UI.git diff --git a/instancehandler/views.py b/instancehandler/views.py index 212fbbf..45120e2 100644 --- a/instancehandler/views.py +++ b/instancehandler/views.py @@ -15,33 +15,39 @@ # from django.shortcuts import render, redirect -from django.contrib.auth.decorators import login_required +#from django.contrib.auth.decorators import login_required from django.http import HttpResponse, JsonResponse import yaml import json import logging from lib.osm.osmclient.clientv2 import Client import authosm.utils as osmutils +from sf_t3d.decorators import login_required logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('instancehandler/view.py') + @login_required def list(request, type=None): + user = osmutils.get_user(request) project_id = user.project_id client = Client() + result = {'type': type, 'project_id': project_id} + if "OSM_ERROR" in request.session: + result['alert_error'] = request.session["OSM_ERROR"] + del request.session["OSM_ERROR"] + raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',') + if 'application/json' not in raw_content_types: + return __response_handler(request, result, 'instance_list.html') + instance_list = None if type == 'ns': instance_list = client.ns_list(user.get_token()) elif type == 'vnf': instance_list = client.vnf_list(user.get_token()) - result = {'instances': instance_list['data'] if instance_list and instance_list['error'] is False else [], - 'type': type, 'project_id': project_id} - - if "OSM_ERROR" in request.session: - result['alert_error'] = request.session["OSM_ERROR"] - del request.session["OSM_ERROR"] + result['instances'] = instance_list['data'] if instance_list and instance_list['error'] is False else [] return __response_handler(request, result, 'instance_list.html') @@ -58,7 +64,7 @@ def create(request): "vimAccountId": request.POST.get('vimAccountId', ''), } if 'ssh_key' in request.POST and request.POST.get('ssh_key') != '': - ns_data["ssh-authorized-key"] = [request.POST.get('ssh_key')] + ns_data["ssh_keys"] = request.POST.get('ssh_key') if 'config' in request.POST: ns_config = yaml.load(request.POST.get('config')) @@ -96,12 +102,16 @@ def create(request): def ns_operations(request, instance_id=None, type=None): user = osmutils.get_user(request) project_id = user.project_id + + result = {'type': 'ns', 'project_id': project_id, 'instance_id': instance_id} + raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',') + if 'application/json' not in raw_content_types: + return __response_handler(request, result, 'instance_operations_list.html') client = Client() op_list = client.ns_op_list(user.get_token(), instance_id) - return __response_handler(request, - {'operations': op_list['data'] if op_list and op_list['error'] is False else [], - 'type': 'ns', 'project_id': project_id}, 'instance_operations_list.html') + result['operations'] = op_list['data'] if op_list and op_list['error'] is False else [] + return __response_handler(request, result, 'instance_operations_list.html') @login_required def ns_operation(request, op_id, instance_id=None, type=None):