From 462eec298e50b930b1b8ec9296edf34934e9312b Mon Sep 17 00:00:00 2001 From: lombardofr Date: Thu, 22 Nov 2018 10:50:33 +0100 Subject: [PATCH] vnfd composer fix missing node update Change-Id: Ia5c84c19739fd8d611169bffefbc6e667e3eb35f Signed-off-by: lombardofr --- descriptorhandler/views.py | 16 +++++++++++++ lib/osm/osm_util.py | 24 +++++++++++++++++++ .../project/osm/osm_project_descriptors.html | 2 +- static/TopologyComposer/js/graph_editor.js | 2 +- static/src/descriptorhandler/composer.js | 11 +++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/descriptorhandler/views.py b/descriptorhandler/views.py index b6c2b2a..064b5a5 100644 --- a/descriptorhandler/views.py +++ b/descriptorhandler/views.py @@ -216,6 +216,22 @@ def updateElement(request, descriptor_type=None, descriptor_id=None, element_typ # print nsr_object if descriptor_type == 'nsd': result_graph = parser.nsd_to_graph(descriptor_updated) + if descriptor_type == 'vnfd': + descriptor_result = client.vnfd_get(user.get_token(), descriptor_id) + util = OsmUtil() + payload = request.POST.dict() + if element_type == 'graph_params': + descriptor_updated = util.update_graph_params('vnfd', descriptor_result, json.loads(payload['update'])) + else: + descriptor_updated = util.update_node('vnfd', descriptor_result, element_type, json.loads(payload['old']), json.loads(payload['update'])) + 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() + if descriptor_type == 'vnfd': + result_graph = parser.vnfd_to_graph(descriptor_updated) return __response_handler(request, result_graph, url=None, status=200) diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index f61e201..49be9df 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -72,6 +72,24 @@ class OsmUtil(): if str(v['member-vnf-index']) == str(old['member-vnf-index']) and str(v['vnfd-id-ref']) == str( old['vnfd-id-ref']): print 'update here' + 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': + for k, v in enumerate(vnfd['internal-vld']): + if v['id'] == old['id']: + vnfd['internal-vld'][k].update(updated) + if node_type == 'cp': + for k, v in enumerate(vnfd['connection-point']): + if v['name'] == old['name']: + vnfd['connection-point'][k].update(updated) + if node_type == 'vdu': + for k, v in enumerate(vnfd['vdu']): + if v['name'] == old['name']: + vnfd['vdu'][k].update(updated) return descriptor @@ -196,5 +214,11 @@ class OsmUtil(): elif 'nsd:nsd-catalog' in descriptor: nsd = descriptor['nsd:nsd-catalog']['nsd'][0] nsd.update(updated) + 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] + vnfd.update(updated) return descriptor diff --git a/projecthandler/template/project/osm/osm_project_descriptors.html b/projecthandler/template/project/osm/osm_project_descriptors.html index 0957ba2..2491bf0 100644 --- a/projecthandler/template/project/osm/osm_project_descriptors.html +++ b/projecthandler/template/project/osm/osm_project_descriptors.html @@ -133,7 +133,7 @@ ' data-toggle="tooltip" data-placement="top" title="Clone"\n' + ' onclick="javascript:clonePackage(\''+ descriptor_type +'\', \''+row["_id"]+'\')">\n' + ' \n'; - if(descriptor_type == "nsd") + //if(descriptor_type == "nsd") result += '