From 36e3ddd4e43444ab84a45ec619a89009969ba7c0 Mon Sep 17 00:00:00 2001 From: lombardofr Date: Fri, 30 Nov 2018 10:15:11 +0100 Subject: [PATCH] fix error handling nsd/vnd composer; promt for cp-ref Change-Id: Icbec00681fa1274f7d242505d4f9bf9b3c755c4e Signed-off-by: lombardofr --- .../template/descriptor_view.html | 18 ++++++--- .../template/descriptor_view_base.html | 2 +- descriptorhandler/views.py | 1 + lib/osm/osm_util.py | 9 ++++- lib/osm/osmclient/clientv2.py | 15 ++++++- .../TopologyComposer/js/model_graph_editor.js | 16 ++++---- static/src/descriptorhandler/composer.js | 18 +++++++-- static/src/descriptorhandler/controller.js | 39 +++++++++++-------- static/src/osm_gui_properties.js | 4 +- 9 files changed, 86 insertions(+), 36 deletions(-) diff --git a/descriptorhandler/template/descriptor_view.html b/descriptorhandler/template/descriptor_view.html index 2a18666..8a3fd3e 100644 --- a/descriptorhandler/template/descriptor_view.html +++ b/descriptorhandler/template/descriptor_view.html @@ -29,8 +29,8 @@ Edit {{ descriptor_type|upper }} Descriptor {% block nav_buttons_list %} {{ block.super }}
  • -
  • -
  • +
  • +
  • {% endblock %} @@ -79,7 +79,7 @@ Edit {{ descriptor_type|upper }} Descriptor }); - function update(e) { + function update(e, show_graph) { var dialog = bootbox.dialog({ message: '
    Loading...
    ', 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 + }); } }); } diff --git a/descriptorhandler/template/descriptor_view_base.html b/descriptorhandler/template/descriptor_view_base.html index 918e810..6f7618a 100644 --- a/descriptorhandler/template/descriptor_view_base.html +++ b/descriptorhandler/template/descriptor_view_base.html @@ -135,7 +135,7 @@ 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}}' } {% endblock %} diff --git a/descriptorhandler/views.py b/descriptorhandler/views.py index fda9aff..5824e57 100644 --- a/descriptorhandler/views.py +++ b/descriptorhandler/views.py @@ -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) diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index 7e536cb..21b4ac7 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -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"] diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 8fbb0d2..79092b7 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -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": [], diff --git a/static/TopologyComposer/js/model_graph_editor.js b/static/TopologyComposer/js/model_graph_editor.js index 4afc955..4ec7650 100644 --- a/static/TopologyComposer/js/model_graph_editor.js +++ b/static/TopologyComposer/js/model_graph_editor.js @@ -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.'); diff --git a/static/src/descriptorhandler/composer.js b/static/src/descriptorhandler/composer.js index 18072a8..b3d849e 100644 --- a/static/src/descriptorhandler/composer.js +++ b/static/src/descriptorhandler/composer.js @@ -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 + }); } }); } diff --git a/static/src/descriptorhandler/controller.js b/static/src/descriptorhandler/controller.js index 6285f82..fd22411 100644 --- a/static/src/descriptorhandler/controller.js +++ b/static/src/descriptorhandler/controller.js @@ -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']); diff --git a/static/src/osm_gui_properties.js b/static/src/osm_gui_properties.js index 0241b34..0060e13 100644 --- a/static/src/osm_gui_properties.js +++ b/static/src/osm_gui_properties.js @@ -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" }, -- 2.25.1