From: lombardofr Date: Tue, 30 Oct 2018 21:16:25 +0000 (+0100) Subject: improved ns topology X-Git-Tag: v5.0.0~18 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FLW-UI.git;a=commitdiff_plain;h=1e3200610a98085cb6a2529e7d728927ca2813ca improved ns topology Change-Id: I6eb1ee664cf52a86b8b723b52c5c6490998a0e63 Signed-off-by: lombardofr --- diff --git a/descriptorhandler/template/composer.html b/descriptorhandler/template/composer.html index cad68fa..2de4ae8 100644 --- a/descriptorhandler/template/composer.html +++ b/descriptorhandler/template/composer.html @@ -30,9 +30,32 @@ {% block content_body %} {{ block.super }} {% csrf_token %} +
+
+ Select Element +
+
+
+
+
VDU
+
+
+
+
VL
+
+
+
+
intCP
+
+
+
+
extCp
+
+ +
@@ -61,6 +84,7 @@ + @@ -71,6 +95,7 @@ + {# #} {% endblock %} diff --git a/descriptorhandler/template/descriptorlist.html b/descriptorhandler/template/descriptorlist.html index 9d86624..df7bda2 100644 --- a/descriptorhandler/template/descriptorlist.html +++ b/descriptorhandler/template/descriptorlist.html @@ -7,9 +7,12 @@

-
- -
+ {% comment %}
+ +
{% endcomment %}
diff --git a/descriptorhandler/views.py b/descriptorhandler/views.py index 8b902af..c80af8a 100644 --- a/descriptorhandler/views.py +++ b/descriptorhandler/views.py @@ -25,6 +25,7 @@ from django.shortcuts import render, redirect from lib.util import Util from lib.osm.osmclient.clientv2 import Client +from lib.osm.osm_rdcl_parser import OsmParser import authosm.utils as osmutils logging.basicConfig(level=logging.DEBUG) @@ -263,6 +264,30 @@ def download_pkg(request, descriptor_id, descriptor_type): def open_composer(request): user = osmutils.get_user(request) project_id = user.project_id + descriptor_id = request.GET.get('id') + descriptor_type = request.GET.get('type') + client = Client() + if descriptor_id: + try: + if descriptor_type == 'nsd': + descriptor_result = client.nsd_get(user.get_token(), descriptor_id) + elif descriptor_type == 'vnfd': + descriptor_result = client.vnfd_get(user.get_token(), descriptor_id) + + except Exception as e: + descriptor_result = {'error': True, 'data': str(e)} + + if isinstance(descriptor_result, dict) and 'error' in descriptor_result and descriptor_result['error']: + return render(request, 'error.html') + + test = OsmParser() + # print nsr_object + if descriptor_type == 'nsd': + result = test.nsd_to_graph(descriptor_result) + elif descriptor_type == 'vnfd': + result = test.vnfd_to_graph(descriptor_result) + return __response_handler(request, result,'composer.html') + result = {'project_id': project_id, 'vertices': [ {"info": {"type": "vnf", "property": {"custom_label": ""}, diff --git a/lib/osm/osm_rdcl_parser.py b/lib/osm/osm_rdcl_parser.py index 0ba27aa..009c0e7 100644 --- a/lib/osm/osm_rdcl_parser.py +++ b/lib/osm/osm_rdcl_parser.py @@ -50,8 +50,9 @@ class RdclGraph(object): } edge_obj.update(optional) - if edge_obj not in graph_object['edges']: - graph_object['edges'].append(edge_obj) + #if edge_obj not in graph_object['edges']: + # graph_object['edges'].append(edge_obj) + graph_object['edges'].append(edge_obj) def add_node(self, id, type, group, positions, graph_object, optional={}): if id is None: @@ -261,6 +262,203 @@ class OsmParser(RdclGraph): return graph + def vnfd_to_graph(self, vnfd_catalog): + graph = {'vertices': [], 'edges': [], 'model': { + "layer": { + "vnfd": { + "nodes": { + "vdu": {}, + "cp": {}, + "int_cp": {}, + "vnf_vl": {} + + }, + "allowed_edges": { + "vdu": { + "destination": { + "cp": { + "direct_edge": False, + }, + "int_cp": { + "direct_edge": False, + }, + "vnf_vl": { + "direct_edge": False, + } + } + }, + "cp": { + "destination": { + "vdu": { + "direct_edge": False, + } + } + }, + "int_cp": { + "destination": { + "vdu": { + "direct_edge": False, + }, + "vnf_vl": { + "direct_edge": False, + } + } + }, + "vnf_vl": { + "destination": { + "vdu": { + "direct_edge": False + } + } + } + } + }, + "name": "OSM", + "version": 1, + "description": "osm" + } + }, 'graph_parameters': {'view': {'vnfd': {}}}} + if 'vnfd-catalog' in vnfd_catalog: + vnfd = vnfd_catalog['vnfd-catalog']['vnfd'][0] + elif 'vnfd:vnfd-catalog' in vnfd_catalog: + vnfd = vnfd_catalog['vnfd:vnfd-catalog']['vnfd'][0] + else: + return graph + if 'connection-point' in vnfd: + for extCp in vnfd['connection-point']: + self.add_node(extCp['name'], 'cp', vnfd['id'], None, graph, + {'property': {'custom_label': extCp['name']}, 'osm': extCp}) + if 'vdu' in vnfd: + for vdu in vnfd['vdu']: + self.add_node(vdu['id'], 'vdu', vnfd['id'], None, graph, + {'property': {'custom_label': vdu['id']}, 'osm': vdu}) + if 'internal-connection-point' in vdu: + for intCp in vdu['internal-connection-point']: + self.add_node(intCp['id'], 'int_cp', vnfd['id'], None, graph, + {'property': {'custom_label': intCp['id']}, 'osm': intCp}) + if 'interface' in vdu: + for interface in vdu['interface']: + if interface['type'] == "EXTERNAL": + self.add_link(vdu['id'], interface['external-connection-point-ref'], 'vnfd', vnfd['id'], graph) + elif interface['type'] == "INTERNAL": + self.add_link(vdu['id'], interface['internal-connection-point-ref'], 'vnfd', vnfd['id'], graph, {'short': True}) + if 'internal-vld' in vnfd: + for intVl in vnfd['internal-vld']: + self.add_node(intVl['id'], 'vnf_vl', intVl['id'], None, graph, + {'property': {'custom_label': intVl['id']}, 'osm': intVl}) + for intCp in intVl['internal-connection-point']: + self.add_link(intVl['id'], intCp['id-ref'], 'vnfd', vnfd['id'], graph) + + return graph + + def nsd_to_graph(self, nsd_catalog): + graph = {'vertices': [], 'edges': [], 'model': { + "layer": { + "nsd": { + "nodes": { + "vnfd": {}, + "cp": {}, + "ns_vl": {} + }, + "allowed_edges": { + "cp": { + "destination": { + "vnfd": { + "direct_edge": False, + } + } + }, + "vnfd":{ + "destination": { + "ns_vl": { + "direct_edge": False, + } + } + }, + "ns_vl": { + "destination": { + "vnfd": { + "direct_edge": False, + } + } + } + } + }, + "vnfd": { + "nodes": { + "vdu": {}, + "cp": {}, + "int_cp": {}, + "vnf_vl": {} + }, + "allowed_edges": { + "vdu": { + "destination": { + "cp": { + "direct_edge": False, + }, + "int_cp": { + "direct_edge": False, + }, + "vnf_vl": { + "direct_edge": False, + } + } + }, + "cp": { + "destination": { + "vdu": { + "direct_edge": False, + } + } + }, + "int_cp": { + "destination": { + "vdu": { + "direct_edge": False, + }, + "vnf_vl": { + "direct_edge": False, + } + } + }, + "vnf_vl": { + "destination": { + "vdu": { + "direct_edge": False + } + } + } + } + }, + "name": "OSM", + "version": 1, + "description": "osm" + } + }, 'graph_parameters': {'view': {'vnfd': {}}}} + if 'nsd-catalog' in nsd_catalog: + nsd = nsd_catalog['nsd-catalog']['nsd'][0] + elif 'nsd:nsd-catalog' in nsd_catalog: + nsd = nsd_catalog['nsd:nsd-catalog']['nsd'][0] + else: + return graph + if 'constituent-vnfd' in nsd: + for vnfd in nsd['constituent-vnfd']: + costinuent_id = vnfd['vnfd-id-ref']+":"+vnfd['member-vnf-index'] + self.add_node(costinuent_id, 'vnf', None, None, graph, + {'property': {'custom_label': costinuent_id}, 'osm': vnfd}) + + if 'vld' in nsd: + for vld in nsd['vld']: + self.add_node(vld['id'], 'ns_vl', None, None, graph, + {'property': {'custom_label': vld['id']}, 'osm': vld}) + if 'vnfd-connection-point-ref' in vld: + for cp_ref in vld['vnfd-connection-point-ref']: + vnfd_id = cp_ref['vnfd-id-ref'] + ':' + str(cp_ref['member-vnf-index-ref']) + self.add_link(vld['id'], vnfd_id, 'nsd', None, graph) + + return graph + if __name__ == '__main__': parser = OsmParser() diff --git a/projecthandler/template/project/osm/osm_project_descriptors.html b/projecthandler/template/project/osm/osm_project_descriptors.html index 8c1ceb2..bfbc355 100644 --- a/projecthandler/template/project/osm/osm_project_descriptors.html +++ b/projecthandler/template/project/osm/osm_project_descriptors.html @@ -135,8 +135,8 @@ ' \n' + '\n' + + ' onclick="location.href=\'/projects/descriptors/composer?type='+descriptor_type+'&id='+row["_id"] +'\'"\n' + + ' disabled >\n' + '