X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=lib%2Fosm%2Fosm_rdcl_parser.py;h=48ffcbc9c6c37e1fa0a57d32c4745f3891efb974;hb=70f9629aef040ce2bd6fba9c082f15d33ac00ef1;hp=0ba27aadc17758e9c4f650e386dedd28af9ecf76;hpb=e6eb7437628e932ef823800b5a8380790a6b22d7;p=osm%2FLW-UI.git diff --git a/lib/osm/osm_rdcl_parser.py b/lib/osm/osm_rdcl_parser.py index 0ba27aa..48ffcbc 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: @@ -256,11 +257,304 @@ class OsmParser(RdclGraph): self.add_node(ns_vld['id'], 'ns_vl', None, None, graph, {'property': {'custom_label': ns_vld['name']}, 'osm': ns_vld}) for cp_ref in ns_vld['vnfd-connection-point-ref']: - self.add_link(map_vnf_index_to_id[str(cp_ref['member-vnf-index-ref'])], ns_vld['id'], 'nsr', None, - graph) + ns_vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref'] + cp_id = ns_vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref'] + cp_label = str(cp_ref['vnfd-connection-point-ref']) + self.add_node(cp_id,'ns_cp','nsd',None,graph, {'property': {'custom_label': cp_label}, 'osm': cp_ref}) + self.add_link(cp_id, ns_vld['id'], 'nsr', None, graph) + self.add_link(cp_id, map_vnf_index_to_id[str(cp_ref['member-vnf-index-ref'])], 'nsr', None, graph) return graph + def vnfd_to_graph(self, vnfd_catalog): + graph = {'vertices': [], 'edges': [], 'model': { + "layer": { + "vnfd": { + "nodes": { + "vdu": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + }, + "cp": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + }, + "int_cp": { + "removable": { + "callback": "removeNode" + } + }, + "vnf_vl": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + } + }, + "allowed_edges": { + "vdu": { + "destination": { + "cp": { + "callback": "addLink", + "direct_edge": False, + "removable": {} + }, + "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, + # } + # } + # }, + "vnf_vl": { + "destination": { + "int_cp": { + "direct_edge": False + }, + "vdu": { + "callback": "addLink", + "direct_edge": False, + "removable": {} + } + } + } + } + }, + "name": "OSM", + "version": 1, + "description": "osm" + }, "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] + elif 'vnfd:vnfd-catalog' in vnfd_catalog: + vnfd = vnfd_catalog['vnfd:vnfd-catalog']['vnfd'][0] + else: + return graph + vnfd_graph_param = graph['graph_parameters']['view']['vnfd'] + vnfd_graph_param['id'] = vnfd['id'] if 'id' in vnfd else None + vnfd_graph_param['name'] = vnfd['name'] if 'name' in vnfd else None + vnfd_graph_param['short-name'] = vnfd['short-name'] if 'short-name' in vnfd else None + vnfd_graph_param['description'] = vnfd['description'] if 'description' in vnfd else None + vnfd_graph_param['version'] = vnfd['version'] if 'version' in vnfd else None + vnfd_graph_param['vendor'] = vnfd['vendor'] if 'vendor' in vnfd else None + 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": { + "vnf": { + "addable": {"callback": "addNode"}, + "removable": {"callback": "removeNode"} + }, + "ns_cp": { + "removable": {"callback": "removeNode"} + }, + "ns_vl": { + "addable": { + "callback": "addNode" + }, + "removable": { + "callback": "removeNode" + } + } + }, + "allowed_edges": { + "vnf":{ + "destination": { + "ns_cp": { + "direct_edge": False, + "removable" : { + "callback": "removeLink", + } + }, + "ns_vl": { + "direct_edge": False, + "callback": "addLink", + } + } + }, + "ns_vl": { + "destination": { + "ns_cp": { + "direct_edge": False, + "removable": { + "callback": "removeLink", + } + }, + "vnf": { + "direct_edge": False, + "callback": "addLink", + } + } + }, + "ns_cp": { + "destination": { + "ns_vl": { + "direct_edge": False, + "removable": { + "callback": "removeLink", + } + }, + "vnf": { + "direct_edge": False, + "removable": { + "callback": "removeLink", + } + } + } + } + } + }, + "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" + }, "callback": {"addNode": {"class": "OSMController"}, "removeNode": {"class": "OSMController"}, + "removeLink": {"class": "OSMController"}, "addLink": {"class": "OSMController"}} + }, 'graph_parameters': {'view': {'nsd': {}}}} + 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 + + nsd_graph_param = graph['graph_parameters']['view']['nsd'] + nsd_graph_param['id'] = nsd['id'] if 'id' in nsd else None + nsd_graph_param['name'] = nsd['name'] if 'name' in nsd else None + nsd_graph_param['short-name'] = nsd['short-name'] if 'short-name' in nsd else None + nsd_graph_param['description'] = nsd['description'] if 'description' in nsd else None + nsd_graph_param['version'] = nsd['version'] if 'version' in nsd else None + nsd_graph_param['vendor'] = nsd['vendor'] if 'vendor' in nsd else None + + if 'constituent-vnfd' in nsd: + for vnfd in nsd['constituent-vnfd']: + costinuent_id = vnfd['vnfd-id-ref']+":"+str(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']) + cp_id = vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref'] + cp_label = vld['id']+ ':' + cp_ref['vnfd-connection-point-ref'] + node_payload = {'vld_id': vld['id']} + node_payload.update(cp_ref) + self.add_node(cp_id,'ns_cp',None,None,graph, + {'property': {'custom_label': cp_label}, 'osm': node_payload}) + + self.add_link(cp_id, vld['id'], 'nsd', None, graph) + self.add_link(cp_id, vnfd_id, 'nsd', None, graph) + return graph + if __name__ == '__main__': parser = OsmParser()