From: lombardofr Date: Wed, 21 Nov 2018 15:26:46 +0000 (+0100) Subject: fix vnfd composer creation link between nodes X-Git-Tag: v5.0.0~10 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F40%2F6940%2F1;p=osm%2FLW-UI.git fix vnfd composer creation link between nodes Signed-off-by: lombardofr --- diff --git a/descriptorhandler/views.py b/descriptorhandler/views.py index 1cf6906..b6c2b2a 100644 --- a/descriptorhandler/views.py +++ b/descriptorhandler/views.py @@ -177,6 +177,23 @@ def removeElement(request, descriptor_type=None, descriptor_id=None, element_typ return __response_handler(request, result_graph, url=None, status=200) + elif descriptor_type == 'vnfd': + descriptor_result = client.vnfd_get(user.get_token(), descriptor_id) + element_id = request.POST.get('id', '') + util = OsmUtil() + descriptor_updated = util.remove_node('vnfd', descriptor_result, element_type, element_id, request.POST.dict()) + result = client.vnfd_update(user.get_token(), descriptor_id, descriptor_updated) + if result['error'] == True: + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + parser = OsmParser() + # print nsr_object + if descriptor_type == 'vnfd': + result_graph = parser.vnfd_to_graph(descriptor_updated) + + 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_rdcl_parser.py b/lib/osm/osm_rdcl_parser.py index ab62688..a6c6f0f 100644 --- a/lib/osm/osm_rdcl_parser.py +++ b/lib/osm/osm_rdcl_parser.py @@ -284,9 +284,6 @@ class OsmParser(RdclGraph): } }, "int_cp": { - "addable": { - "callback": "addNode" - }, "removable": { "callback": "removeNode" } @@ -304,34 +301,45 @@ class OsmParser(RdclGraph): "vdu": { "destination": { "cp": { + "callback": "addLink", "direct_edge": False, + "removable": {} }, - "int_cp": { + "vnf_vl": { + "callback": "addLink", "direct_edge": False, + "removable": {} } } }, "cp": { "destination": { "vdu": { + "callback": "addLink", "direct_edge": False, + "removable": {} } } }, - "int_cp": { - "destination": { - "vdu": { - "direct_edge": False, - }, - "vnf_vl": { - "direct_edge": False, - } - } - }, + # "int_cp": { + # "destination": { + # "vdu": { + # "direct_edge": False, + # }, + # "vnf_vl": { + # "direct_edge": False, + # } + # } + # }, "vnf_vl": { "destination": { "int_cp": { "direct_edge": False + }, + "vdu": { + "callback": "addLink", + "direct_edge": False, + "removable": {} } } } @@ -340,7 +348,8 @@ class OsmParser(RdclGraph): "name": "OSM", "version": 1, "description": "osm" - }, "callback": {"addNode": {"class": "OSMController"}, "removeNode": {"class": "OSMController"}} + }, "callback": {"addNode": {"class": "OSMController"}, "removeNode": {"class": "OSMController"}, + "removeLink": {"class": "OSMController"}, "addLink": {"class": "OSMController"}} }, 'graph_parameters': {'view': {'vnfd': {}}}} if 'vnfd-catalog' in vnfd_catalog: vnfd = vnfd_catalog['vnfd-catalog']['vnfd'][0] @@ -387,12 +396,10 @@ class OsmParser(RdclGraph): "layer": { "nsd": { "nodes": { - "vnf": {"addable": { - "callback": "addNode" - }, - "removable": { - "callback": "removeNode" - }}, + "vnf": { + "addable": {"callback": "addNode"}, + "removable": {"callback": "removeNode"} + }, "cp": {}, "ns_vl": { "addable": { diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index 12e567b..05f73ff 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -93,7 +93,7 @@ class OsmUtil(): if node_type == 'cp': for vld in nsd['vld']: if vld['id'] == args['vld_id']: - if'vnfd-connection-point-ref' not in vld: + if 'vnfd-connection-point-ref' not in vld: vld['vnfd-connection-point-ref'] = [] vld['vnfd-connection-point-ref'].append( { @@ -136,7 +136,18 @@ class OsmUtil(): "ip-profile-ref": "", "id": element_id }) - + if node_type == 'interface': + for vdu in vnfd['vdu']: + if vdu['id'] == args['vdu-id']: + vdu['interface'].append({ + "virtual-interface": { + "type": "VIRTIO" + }, + "name": element_id, + "mgmt-interface": True, + "type": "EXTERNAL", + "external-connection-point-ref": args["external-connection-point-ref"] + }) return descriptor @staticmethod @@ -148,4 +159,4 @@ class OsmUtil(): nsd = descriptor['nsd:nsd-catalog']['nsd'][0] nsd.update(updated) - return descriptor \ No newline at end of file + return descriptor diff --git a/static/src/descriptorhandler/controller.js b/static/src/descriptorhandler/controller.js index 3a96ea2..90eb863 100644 --- a/static/src/descriptorhandler/controller.js +++ b/static/src/descriptorhandler/controller.js @@ -79,6 +79,55 @@ TCD3.OsmController = (function (global) { error: error }); } + else if (desc_type === 'vnfd') { + if (['vdu', 'cp'].indexOf(link.source.info.type) > -1 && ['vdu', 'cp'].indexOf(link.target.info.type) > -1) { + var vdu_node = (link.source.info.type === 'vdu') ? link.source : link.target; + var cp_node = (link.source.info.type === 'cp') ? link.source : link.target; + + var data_form = new FormData(); + 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); + $.ajax({ + url: '/projects/descriptors/' + desc_type + '/' + desc_id + '/addElement/interface', + type: 'POST', + data: data_form, + cache: false, + contentType: false, + processData: false, + success: success, + error: error + }); + } + else if (['vdu', 'vnf_vl'].indexOf(link.source.info.type) > -1 && ['vdu', 'vnf_vl'].indexOf(link.target.info.type) > -1) { + + console.log("link tra vdu e vl"); + /*var element_type = 'cp'; + var data_form = new FormData(); + + var vdu_node = (link.source.info.type === 'vdu') ? link.source : link.target; + var vld_node = (link.source.info.type === 'vnf_vl') ? link.source : link.target; + + 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 + });*/ + } + + } + }; @@ -114,7 +163,7 @@ TCD3.OsmController = (function (global) { console.log(args) var data_form = new FormData(); data_form.append('csrfmiddlewaretoken', getCookie('csrftoken')); - data_form.append('old', JSON.stringify( node.info.osm)); + data_form.append('old', JSON.stringify(node.info.osm)); data_form.append('update', JSON.stringify(args)); /*for (var key in node.info.osm) { data_form.append(key, node.info.osm[key]); @@ -134,7 +183,7 @@ TCD3.OsmController = (function (global) { }; - OsmController.prototype.updateGraphParams = function(args, success, error){ + OsmController.prototype.updateGraphParams = function (args, success, error) { var desc_id = getUrlParameter('id'); var desc_type = getUrlParameter('type'); var data_form = new FormData();