def ns_view(ns_id): # get the nsdId that corresponds to nsId nsd_id = ns_db.get_nsdId(ns_id) domain = nsd_db.get_nsd_domain(nsd_id) nsd_json = nsd_db.get_nsd_json(nsd_id) flavour_id = ns_db.get_ns_flavour_id(ns_id) ns_instantiation_level_id = ns_db.get_ns_instantiation_level_id(ns_id) # print("Flavor /instantiation level of ns_id to be visualize: {} {}".format(flavour_id, ns_instantiation_level_id)) ns_network = {} level = "{}_{}_{}".format(nsd_id, flavour_id, ns_instantiation_level_id) # print("Total Level: {}".format(level)) if domain == 'local': html_page = 'ns_view.html' placement_info = nsir_db.get_placement_info(ns_id) list_osm_json, default_index = gui_utils.ifa014_conversion(nsd_json) for element in list_osm_json: if element['nsd:nsd-catalog']['nsd'][0]['id'] == level: ns_network = gui_utils.json_network_nsd( element, placement_info) elif domain == 'Composite': html_page = 'ns_composite_view.html' list_osm_json, default_index = gui_utils.composite_desc_conversion( nsd_json) for element in list_osm_json: if element['nsd:nsd-catalog']['nsd-composite'][0]['id'] == level: ns_network = gui_utils.json_network_composite_ns( element, ns_id) else: message = {'Error': 'Error: Something Wrong with domain of Descriptor'} log_queue.put(["ERROR", message['Error']]) flash(message['Error'], 'danger') return redirect(request.referrer) return render_template(html_page, html_title=ns_db.get_ns_name(ns_id), d3_network=json_graph.node_link_data(ns_network))
def descriptor_viewer(): """ This function just responds to the browser Url :return: the rendered template 'descriptor.html' """ if request.method == 'POST': try: already_onboarded_in_so = False # retrieving the IFA descriptor # print(request.form, request.files) if 'convert_text' in request.form: ifa_json = json.loads(request.form['convert_text']) elif 'file_to_convert' in request.files: f = request.files['file_to_convert'] response = f.read() ifa_json = json.loads(response.decode('utf-8')) elif 'show_json' in request.form: ifa_json = eval(request.form['show_json']) already_onboarded_in_so = True elif 'onboard_json' in request.form: ifa_json = eval(request.form['onboard_json']) record = {} if 'nsd' in ifa_json: # nsd case if 'vnfdId' in ifa_json['nsd']: record = { "nsdId": ifa_json["nsd"]["nsdIdentifier"], "nsdCloudifyId": {}, "version": ifa_json["nsd"]["version"], "nsdName": ifa_json["nsd"]["nsdName"], "nsdJson": ifa_json, "shareable": True, "domain": "local" } if nsd_db.get_nsd_json(nsdId=record['nsdId']) is None: nsd_db.insert_nsd(record) message = { "Success": 'nsdId : {} onboarded on SO with success!'. format(record['nsdId']) } else: log_queue.put( ["DEBUG", 'nsdId already in the SO DB']) raise ValueError('nsdId already in the SO DB') # nsd-composite case else: record = { "nsdId": ifa_json["nsd"]["nsdIdentifier"], "nsdCloudifyId": {}, "version": ifa_json["nsd"]["version"], "nsdName": ifa_json["nsd"]["nsdName"], "nsdJson": ifa_json, "shareable": False, "domain": "Composite" } if nsd_db.get_nsd_json(nsdId=record['nsdId']) is None: nsd_db.insert_nsd(record) message = { "Success": 'nsdId : {} onboarded on SO with success!'. format(record['nsdId']) } else: log_queue.put( ["DEBUG", 'nsdId already in the SO DB']) raise ValueError('nsdId already in the SO DB') # vnfd case else: record = { "vnfdId": ifa_json["vnfdId"], "vnfdVersion": ifa_json["vnfdVersion"], "vnfdName": ifa_json["vnfProductName"], "vnfdJson": ifa_json } if vnfd_db.get_vnfd_json( vnfdId=ifa_json["vnfdId"]) is None: vnfd_db.insert_vnfd(record) message = { 'Success': 'vnfdId : {} onboarded on SO with success!'.format( record['vnfdId']) } else: log_queue.put(["DEBUG", 'vnfdId already in the SO DB']) raise ValueError('vnfdId already in the SO DB') log_queue.put(["INFO", message["Success"]]) flash(message['Success'], 'success') already_onboarded_in_so = True else: raise ValueError('No text/file valid') if 'nsd' in ifa_json: if 'vnfdId' in ifa_json['nsd']: # convert a NSD list_osm_json, default_index = gui_utils.ifa014_conversion( ifa_json) default_osm_json = list_osm_json[default_index] osm_json_network = [] for level in list_osm_json: osm_json_network.append( json_graph.node_link_data( gui_utils.json_network_nsd(level))) descriptor_type = 'nsd' else: # convert a composite NSD list_osm_json, default_index = gui_utils.composite_desc_conversion( ifa_json) default_osm_json = list_osm_json[default_index] osm_json_network = [] for level in list_osm_json: osm_json_network.append( json_graph.node_link_data( gui_utils.json_network_composite_nsd(level))) descriptor_type = 'nsd-composite' else: # convert a VNFD list_osm_json = [gui_utils.ifa011_conversion(ifa_json)] default_osm_json = list_osm_json[ 0] # done in case of possible list of ifa vnfd conversion osm_json_network = [ json_graph.node_link_data( gui_utils.json_network_vnfd(default_osm_json)) ] descriptor_type = 'vnfd' yaml_descriptor_list = [] for osm_json in list_osm_json: yaml_descriptor_list.append( yaml.safe_dump(osm_json, default_flow_style=False)) yaml_ifa_descriptor = yaml.safe_dump(ifa_json, default_flow_style=False) return render_template( 'descriptor.html', html_title='Descriptor Viewer', descriptor_type=descriptor_type, yaml_network=osm_json_network, list_osm_json=list_osm_json, yaml_osm_descriptor=yaml_descriptor_list, yaml_ifa_descriptor=yaml_ifa_descriptor, ifa_json=ifa_json, already_onboarded_in_so=already_onboarded_in_so) except (TypeError, KeyError, ValueError) as error: message = {'Error': 'Error: {}'.format(error)} log_queue.put(["ERROR", message['Error']]) flash(message['Error'], 'danger') return redirect(url_for('home'))