fix Bug 511 81/6381/1
authorlombardofr <lombardo@everyup.it>
Tue, 24 Jul 2018 15:10:48 +0000 (17:10 +0200)
committerlombardofr <lombardo@everyup.it>
Tue, 24 Jul 2018 15:10:48 +0000 (17:10 +0200)
Change-Id: I14050b6c4e9ade7de1986b24eace8ec8853c7009
Signed-off-by: lombardofr <lombardo@everyup.it>
instancehandler/template/instance_list_ns.html
instancehandler/template/modal/instance_create.html
instancehandler/views.py

index 48695cd..01bdc10 100644 (file)
 
     </div>
     <div class="box-body">
+    {% if alert_error %}
+        <div class="alert alert-danger alert-dismissible fade in">
+            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+            <h4><i class="icon fa fa-ban"></i> Error</h4>
+            {{alert_error}}
+        </div>
+    {% endif %}
         <table id="instances_table" class="table table-bordered table-striped">
             <thead>
             <tr>
index a776697..b11249b 100644 (file)
@@ -6,7 +6,7 @@
                     <span aria-hidden="true">×</span></button>
                 <h4 class="modal-title">New Instance</h4>
             </div>
-            <form id="formCreateNS" action='{% url "instances:create"   %}'
+            <form id="formCreateNS" action='{% url "instances:create" %}'
                   class="form-horizontal"
                   method="post" enctype="multipart/form-data">
                 {% csrf_token %}
index 1a37f90..212fbbf 100644 (file)
@@ -39,47 +39,57 @@ def list(request, type=None):
     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"]
+
     return __response_handler(request, result, 'instance_list.html')
 
 
 @login_required
 def create(request):
     result = {}
-    ns_data = {
-        "nsName": request.POST.get('nsName', 'WithoutName'),
-        "nsDescription": request.POST.get('nsDescription', ''),
-        "nsdId": request.POST.get('nsdId', ''),
-        "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')]
-
-    if 'config' in request.POST:
-        ns_config = yaml.load(request.POST.get('config'))
-        if isinstance(ns_config, dict):
-            if "vim-network-name" in ns_config:
-                ns_config["vld"] = ns_config.pop("vim-network-name")
-            if "vld" in ns_config:
-                for vld in ns_config["vld"]:
-                    if vld.get("vim-network-name"):
-                        if isinstance(vld["vim-network-name"], dict):
-                            vim_network_name_dict = {}
-                            for vim_account, vim_net in vld["vim-network-name"].items():
-                                vim_network_name_dict[ns_data["vimAccountId"]] = vim_net
-                            vld["vim-network-name"] = vim_network_name_dict
-                ns_data["vld"] = ns_config["vld"]
-            if "vnf" in ns_config:
-                for vnf in ns_config["vnf"]:
-                    if vnf.get("vim_account"):
-                        vnf["vimAccountId"] = ns_data["vimAccountId"]
-
-                ns_data["vnf"] = ns_config["vnf"]
+    try:
+
+        ns_data = {
+            "nsName": request.POST.get('nsName', 'WithoutName'),
+            "nsDescription": request.POST.get('nsDescription', ''),
+            "nsdId": request.POST.get('nsdId', ''),
+            "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')]
+
+        if 'config' in request.POST:
+            ns_config = yaml.load(request.POST.get('config'))
+            if isinstance(ns_config, dict):
+                if "vim-network-name" in ns_config:
+                    ns_config["vld"] = ns_config.pop("vim-network-name")
+                if "vld" in ns_config:
+                    print ns_config
+                    for vld in ns_config["vld"]:
+                        if vld.get("vim-network-name"):
+                            if isinstance(vld["vim-network-name"], dict):
+                                vim_network_name_dict = {}
+                                for vim_account, vim_net in vld["vim-network-name"].items():
+                                    vim_network_name_dict[ns_data["vimAccountId"]] = vim_net
+                                vld["vim-network-name"] = vim_network_name_dict
+                    ns_data["vld"] = ns_config["vld"]
+                if "vnf" in ns_config:
+                    for vnf in ns_config["vnf"]:
+                        if vnf.get("vim_account"):
+                            vnf["vimAccountId"] = ns_data["vimAccountId"]
+
+                    ns_data["vnf"] = ns_config["vnf"]
+    except Exception as e:
+        request.session["OSM_ERROR"] = "Error creating the NS; Invalid parameters provided."
+        return __response_handler(request, {}, 'instances:list', to_redirect=True, type='ns', )
+
     print ns_data
     user = osmutils.get_user(request)
     client = Client()
     result = client.ns_create(user.get_token(), ns_data)
-    return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns',
-                              )
+    return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns',)
 
 
 @login_required