fix error handling nsd/vnd composer; promt for cp-ref 08/7008/3
authorlombardofr <lombardo@everyup.it>
Fri, 30 Nov 2018 09:15:11 +0000 (10:15 +0100)
committerlombardofr <lombardo@everyup.it>
Sun, 2 Dec 2018 10:46:41 +0000 (11:46 +0100)
Change-Id: Icbec00681fa1274f7d242505d4f9bf9b3c755c4e
Signed-off-by: lombardofr <lombardo@everyup.it>
descriptorhandler/template/descriptor_view.html
descriptorhandler/template/descriptor_view_base.html
descriptorhandler/views.py
lib/osm/osm_util.py
lib/osm/osmclient/clientv2.py
static/TopologyComposer/js/model_graph_editor.js
static/src/descriptorhandler/composer.js
static/src/descriptorhandler/controller.js
static/src/osm_gui_properties.js

index 2a18666..8a3fd3e 100644 (file)
@@ -29,8 +29,8 @@ Edit {{ descriptor_type|upper }} Descriptor
 {% block nav_buttons_list %}
     {{ block.super }}
     <li class="pull-right"><button id="save" type="button" class="btn btn-block btn-primary btn-sm"  onclick="update(this.id)" ><i class="fa fa-save"></i> Update</button></li>
-    <li class="pull-right"><button id="save_show_graph" type="button" class="btn btn-block btn-primary btn-sm"  onclick="update(this.id)" disabled><i class="fa fa-save"></i> Update and Show Graph</button></li>
-    <li class="pull-right"><button type="button" class="btn btn-block btn-primary btn-sm"  onclick="goToGraph()" disabled><i class="fa fa-sitemap"></i> Show Graph</button></li>
+    <li class="pull-right"><button id="save_show_graph" type="button" class="btn btn-block btn-primary btn-sm"  onclick="update(this.id, 'true')"><i class="fa fa-save"></i> Update and Show Graph</button></li>
+    <li class="pull-right"><button type="button" class="btn btn-block btn-primary btn-sm"  onclick="goToGraph()"><i class="fa fa-sitemap"></i> Show Graph</button></li>
 
 {% endblock %}
 
@@ -79,7 +79,7 @@ Edit {{ descriptor_type|upper }} Descriptor
     });
 
 
-    function update(e) {
+    function update(e, show_graph) {
         var dialog = bootbox.dialog({
             message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
             closeButton: false
@@ -107,6 +107,9 @@ Edit {{ descriptor_type|upper }} Descriptor
                 'text': text
             },
             success: function (result) {
+                if(show_graph){
+                    goToGraph();
+                }
                 dialog.modal('hide');
                 $("#success-alert").fadeTo(2000, 500).slideDown(500, function(){
                     setTimeout(function () {
@@ -116,9 +119,14 @@ Edit {{ descriptor_type|upper }} Descriptor
                 });
             },
             error: function (result) {
-                console.log(result);
                 dialog.modal('hide');
-                bootbox.alert(result);
+                var data = result.responseJSON;
+                var title = "Error " + (data && data.code ? data.code : 'unknown');
+                var message = data && data.detail ? data.detail : 'No detail available.';
+                bootbox.alert({
+                    title: title,
+                    message: message
+                });
             }
         });
     }
index 918e810..6f7618a 100644 (file)
 
 
         function goToGraph() {
-            window.location.href = '/projects/graph?type={{descriptor_type}}&id={{descriptor_id}}'
+            window.location.href = '/projects/descriptors/composer?type={{descriptor_type}}&id={{descriptor_id}}'
         }
     </script>
 {% endblock %}
index fda9aff..5824e57 100644 (file)
@@ -216,6 +216,7 @@ def removeElement(request, descriptor_type=None, descriptor_id=None, element_typ
 
             return __response_handler(request, result_graph, url=None, status=200)
 
+
 @login_required
 def updateElement(request, descriptor_type=None, descriptor_id=None, element_type=None):
     user = osmutils.get_user(request)
index 7e536cb..21b4ac7 100644 (file)
@@ -39,6 +39,8 @@ class OsmUtil():
                 vnfd['internal-vld'] = [item for item in vnfd['internal-vld'] if item['id'] != element_id]
             if node_type == 'cp':
                 vnfd['connection-point'] = [item for item in vnfd['connection-point'] if item['name'] != args['name']]
+                if vnfd['mgmt-interface']['cp'] == args['name']:
+                    del vnfd['mgmt-interface']['cp']
                 for vdu in vnfd['vdu']:
                     if 'interface' in vdu:
                         vdu['interface'] = [item for item in vdu['interface'] if 'external-connection-point-ref' not in item
@@ -89,6 +91,11 @@ class OsmUtil():
                 for k, v in enumerate(vnfd['connection-point']):
                     if v['name'] == old['name']:
                         vnfd['connection-point'][k].update(updated)
+                for vdu in vnfd['vdu']:
+                    if 'interface' in vdu:
+                        for intf in vdu['interface']:
+                            if 'external-connection-point-ref' in intf and intf['external-connection-point-ref'] == old['name']:
+                                intf['external-connection-point-ref'] = updated['name']
             if node_type == 'vdu':
                 for k, v in enumerate(vnfd['vdu']):
                     if v['name'] == old['name']:
@@ -180,7 +187,7 @@ class OsmUtil():
                             "virtual-interface": {
                                 "type": "VIRTIO"
                             },
-                            "name": element_id,
+                            "name": args["name"],
                             "mgmt-interface": True,
                             "type": "EXTERNAL",
                             "external-connection-point-ref": args["external-connection-point-ref"]
index 8fbb0d2..79092b7 100644 (file)
@@ -405,6 +405,7 @@ class Client(object):
 
         try:
             self._create_base_pkg('nsd', pkg_name)
+            headers['Content-Filename'] = pkg_name + '.tar.gz'
             r = requests.post(_url, data=open('/tmp/' + pkg_name + '.tar.gz', 'rb'), verify=False, headers=headers)
         except Exception as e:
             log.exception(e)
@@ -516,6 +517,11 @@ class Client(object):
             return result
         if r.status_code == requests.codes.no_content:
             result['error'] = False
+        else:
+            try:
+                result['data'] = r.json()
+            except Exception as e:
+                result['data'] = {}
 
         return result
 
@@ -542,6 +548,11 @@ class Client(object):
             return result
         if r.status_code == requests.codes.no_content:
             result['error'] = False
+        else:
+            try:
+                result['data'] = r.json()
+            except Exception as e:
+                result['data'] = {}
 
         return result
 
@@ -625,7 +636,9 @@ class Client(object):
                             "short-name": str(pkg_name),
                             "vdu": [],
                             "description": "",
-                            "mgmt-interface": {},
+                            "mgmt-interface": {
+                                "cp": ""
+                            },
                             "id": str(pkg_name),
                             "version": "1.0",
                             "internal-vld": [],
index 4afc955..4ec7650 100644 (file)
@@ -195,8 +195,10 @@ TCD3.ModelGraphEditor = (function () {
      * @returns {boolean}
      */
     ModelGraphEditor.prototype.updateGraphParams = function (args, success, error) {
+        var self = this;
         var controller = new  TCD3.OsmController();
-        controller.updateGraphParams(args, function(){
+        controller.updateGraphParams(args, function(result){
+            self.updateData(result);
             success && success();
         }, error);
     };
@@ -218,8 +220,9 @@ TCD3.ModelGraphEditor = (function () {
             if (self.model.layer[current_layer].nodes[node_type].removable.callback) {
                 var c = self.model.callback[self.model.layer[current_layer].nodes[node_type].removable.callback].class;
                 var controller = new  TCD3.OsmController();
-                controller[self.model.layer[current_layer].nodes[node_type].removable.callback](self, node, function () {
-                    self.parent.removeNode.call(self, node);
+                controller[self.model.layer[current_layer].nodes[node_type].removable.callback](self, node, function (result) {
+                    self._deselectAllNodes();
+                    self.updateData(result);
                     success && success();
                 }, error);
             } else {
@@ -263,11 +266,10 @@ TCD3.ModelGraphEditor = (function () {
                 link.directed_edge = direct_edge;
                 var c = self.model.callback[callback].class;
                 var controller = new  TCD3.OsmController();
-                controller[callback](self, link, function () {
+                controller[callback](self, link, function (result) {
                     self._deselectAllNodes();
-                    self.parent.addLink.call(self, link);
-                    if (success)
-                        success();
+                    self.updateData(result);
+                    success && success();
                 }, error);
             } else {
                 log('addLink: callback undefined in model spec.');
index 18072a8..b3d849e 100644 (file)
@@ -141,8 +141,14 @@ function initDropOnGraph() {
 
         graph_editor.addNode(node_information, function () {
             console.log("OK")
-        }, function (error) {
-            showAlert(error)
+        }, function (result) {
+            var data = result.responseJSON;
+            var title = "Error " + (data && data.code ? data.code : 'unknown');
+                var message = data && data.detail ? data.detail : 'No detail available.';
+                bootbox.alert({
+                    title: title,
+                    message: message
+                });
         })
 
     };
@@ -287,7 +293,13 @@ function updatePalette(view) {
                 palette.append(palette_template)
             },
             error: function (result) {
-                showAlert(result);
+                var data = result.responseJSON;
+                var title = "Error " + (data && data.code ? data.code : 'unknown');
+                var message = data && data.detail ? data.detail : 'No detail available.';
+                bootbox.alert({
+                    title: title,
+                    message: message
+                });
             }
         });
     }
index 6285f82..fd22411 100644 (file)
@@ -51,23 +51,29 @@ TCD3.OsmController = (function (global) {
 
             var vnfd_node = (link.source.info.type === 'vnf') ? link.source : link.target;
             var vld_node = (link.source.info.type === 'ns_vl') ? link.source : link.target;
+            bootbox.prompt("Please insert the vnfd-connection-point-ref:", function(result){
+                if (result){
+                    data_form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
+                    data_form.append('vnfd-connection-point-ref', result);
+                    data_form.append('member-vnf-index-ref', vnfd_node.info.osm['member-vnf-index']);
+                    data_form.append('vnfd-id-ref', vnfd_node.info.osm['vnfd-id-ref']);
+                    data_form.append('vld_id', vld_node.info.osm['id']);
+
+                    $.ajax({
+                        url: '/projects/descriptors/' + desc_type + '/' + desc_id + '/addElement/' + element_type,
+                        type: 'POST',
+                        data: data_form,
+                        cache: false,
+                        contentType: false,
+                        processData: false,
+                        success: success,
+                        error: error
+                    });
+                }
 
-            data_form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
-            data_form.append('vnfd-connection-point-ref', 'cp_temp');
-            data_form.append('member-vnf-index-ref', vnfd_node.info.osm['member-vnf-index']);
-            data_form.append('vnfd-id-ref', vnfd_node.info.osm['vnfd-id-ref']);
-            data_form.append('vld_id', vld_node.info.osm['id']);
-
-            $.ajax({
-                url: '/projects/descriptors/' + desc_type + '/' + desc_id + '/addElement/' + element_type,
-                type: 'POST',
-                data: data_form,
-                cache: false,
-                contentType: false,
-                processData: false,
-                success: success,
-                error: error
             });
+
+
         }
         else if (desc_type === 'vnfd') {
             if (['vdu', 'cp'].indexOf(link.source.info.type) > -1 && ['vdu', 'cp'].indexOf(link.target.info.type) > -1) {
@@ -78,6 +84,7 @@ TCD3.OsmController = (function (global) {
                 data_form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
                 data_form.append('vdu_id', vdu_node.info.osm.id);
                 data_form.append('external-connection-point-ref', cp_node.info.osm.name);
+                data_form.append('name',  "eth_" + generateUID());
                 $.ajax({
                     url: '/projects/descriptors/' + desc_type + '/' + desc_id + '/addElement/interface',
                     type: 'POST',
@@ -210,7 +217,7 @@ TCD3.OsmController = (function (global) {
             var vld_node = (link.source.info.type === 'ns_vl') ? link.source : link.target;
 
             data_form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
-            data_form.append('vnfd-connection-point-ref', 'cp_temp');
+            //data_form.append('vnfd-connection-point-ref', 'cp_temp');
             data_form.append('member-vnf-index-ref', vnfd_node.info.osm['member-vnf-index']);
             data_form.append('vnfd-id-ref', vnfd_node.info.osm['vnfd-id-ref']);
             data_form.append('vld_id', vld_node.info.osm['id']);
index 0241b34..0060e13 100644 (file)
@@ -55,13 +55,13 @@ var osm_gui_properties = {
             "vdur": {
                 "shape": "square",
                 "color": "#cf1c24",
-                "size": 60,
+                "size": 40,
                 "name": "VDUR"
             },
             "vnfr": {
                 "shape": "square",
                 "color": "#605ca8",
-                "size": 60,
+                "size": 40,
                 "name": "VNFR"
             },