From: lombardofr Date: Tue, 20 Nov 2018 22:47:32 +0000 (+0100) Subject: fix missing vnfd composer constraint X-Git-Tag: v5.0.0~11 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=e65ab995302cb8ea6d91cb0916d72a31528df67a;p=osm%2FLW-UI.git fix missing vnfd composer constraint Change-Id: I58644c97076cf87fe82017cb10a072db21fecab6 Signed-off-by: lombardofr --- diff --git a/descriptorhandler/views.py b/descriptorhandler/views.py index 1bdb9b4..1cf6906 100644 --- a/descriptorhandler/views.py +++ b/descriptorhandler/views.py @@ -137,6 +137,24 @@ def addElement(request, descriptor_type=None, descriptor_id=None, element_type=N 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.add_base_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 removeElement(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 84814f2..ab62688 100644 --- a/lib/osm/osm_rdcl_parser.py +++ b/lib/osm/osm_rdcl_parser.py @@ -267,9 +267,30 @@ class OsmParser(RdclGraph): "layer": { "vnfd": { "nodes": { - "vdu": {}, - "cp": {}, - "int_cp": {}, + "vdu": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + }, + "cp": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + }, + "int_cp": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + }, "vnf_vl": { "addable": { "callback": "addNode" @@ -287,9 +308,6 @@ class OsmParser(RdclGraph): }, "int_cp": { "direct_edge": False, - }, - "vnf_vl": { - "direct_edge": False, } } }, @@ -312,7 +330,7 @@ class OsmParser(RdclGraph): }, "vnf_vl": { "destination": { - "vdu": { + "int_cp": { "direct_edge": False } } diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index 5d314ce..12e567b 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -29,6 +29,16 @@ class OsmUtil(): str(item['member-vnf-index-ref']) != str( args['member-vnf-index-ref']) or str( item['vnfd-id-ref']) != str(args['vnfd-id-ref'])] + elif descriptor_type == 'vnfd': + if 'vnfd-catalog' in descriptor: + vnfd = descriptor['vnfd-catalog']['vnfd'][0] + elif 'vnfd:vnfd-catalog' in descriptor: + vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0] + + if node_type == 'vnf_vl': + 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'] != element_id] return descriptor @@ -92,6 +102,41 @@ class OsmUtil(): "vnfd-id-ref": args['vnfd-id-ref'] }, ) + + elif descriptor_type == 'vnfd': + if 'vnfd-catalog' in descriptor: + vnfd = descriptor['vnfd-catalog']['vnfd'][0] + elif 'vnfd:vnfd-catalog' in descriptor: + vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0] + if node_type == 'vdu': + vnfd['vdu'].append({ + "count": "1", + "description": "", + "monitoring-param": [], + "internal-connection-point": [], + "image": "ubuntu", + "cloud-init-file": "", + "vm-flavor": {}, + "interface": [], + "id": element_id, + "name": element_id + }) + if node_type == 'cp': + vnfd['connection-point'].append({ + "type": "VPORT", + "name": element_id + }) + + if node_type == 'vnf_vl': + vnfd['internal-vld'].append({ + "short-name": element_id, + "name": element_id, + "internal-connection-point": [], + "type": "ELAN", + "ip-profile-ref": "", + "id": element_id + }) + return descriptor @staticmethod diff --git a/static/src/descriptorhandler/composer.js b/static/src/descriptorhandler/composer.js index d56e22f..4b8bfd5 100644 --- a/static/src/descriptorhandler/composer.js +++ b/static/src/descriptorhandler/composer.js @@ -118,7 +118,7 @@ function initDropOnGraph() { var nodetype = $('#' + elemet_id).attr('type-name'); var random_name = nodetype + "_" + generateUID(); - + console.log(nodetype) var node_information = { 'id': random_name, 'info': { @@ -134,21 +134,17 @@ function initDropOnGraph() { 'x': e.layerX, 'y': e.layerY }; - if (nodetype === 'ns_vl') { - graph_editor.addNode(node_information, function () { - console.log("OK") - }, function (error) { - showAlert(error) - }) - } else if (nodetype === 'vnf') { + if (nodetype === 'vnf') { node_information['id'] = $('#' + elemet_id).attr('desc_id'); - graph_editor.addNode(node_information, function () { - console.log("OK") - }, function (error) { - showAlert(error) - }) } + + graph_editor.addNode(node_information, function () { + console.log("OK") + }, function (error) { + showAlert(error) + }) + }; dropZone.ondragover = function (ev) { @@ -261,7 +257,7 @@ function updatePalette(view) { var node = nodes[n]; if (nodes_properties[node]) { palette_template += '
' + + 'type-name="' + node + '" draggable="true" ondragstart="nodeDragStart(event)">' + '
' + '
' + nodes_properties[node].name + '
'; }