def _set_port_info_for_nfi(self, session, network_function_instance_db, network_function_instance, is_update=False): nfi_db = network_function_instance_db port_info = network_function_instance.get('port_info') with session.begin(subtransactions=True): nfi_db.port_info = [] for port in port_info: port_info_db = nfp_db_model.PortInfo( id=port['id'], port_model=port['port_model'], port_classification=port.get('port_classification'), port_role=port.get('port_role')) if is_update: session.merge(port_info_db) else: session.add(port_info_db) session.flush() # Any alternatives for flush ?? assoc = nfp_db_model.NSIPortAssociation( network_function_instance_id=( network_function_instance_db['id']), data_port_id=port['id']) nfi_db.port_info.append(assoc) del network_function_instance['port_info']
def _set_monitoring_port_id_for_nfd(self, session, network_function_device_db, network_function_device): nfd_db = network_function_device_db monitoring_port_id = network_function_device.get('monitoring_port_id') if not monitoring_port_id: nfd_db.monitoring_port_id = None return with session.begin(subtransactions=True): port_info_db = nfp_db_model.PortInfo( id=monitoring_port_id['id'], port_model=monitoring_port_id['port_model'], port_classification=monitoring_port_id['port_classification'], port_role=monitoring_port_id['port_role']) session.add(port_info_db) session.flush() nfd_db.monitoring_port_id = monitoring_port_id['id'] del network_function_device['monitoring_port_id']
def _set_mgmt_port_for_nfd(self, session, network_function_device_db, network_function_device, is_update=False): nfd_db = network_function_device_db mgmt_port_id = network_function_device.get('mgmt_port_id') if not mgmt_port_id: nfd_db.mgmt_port_id = None return with session.begin(subtransactions=True): port_info_db = nfp_db_model.PortInfo( id=mgmt_port_id['id'], port_model=mgmt_port_id['port_model'], port_classification=mgmt_port_id['port_classification'], port_role=mgmt_port_id['port_role']) if is_update: session.merge(port_info_db) else: session.add(port_info_db) session.flush() nfd_db.mgmt_port_id = port_info_db['id']
def _set_plugged_in_port_for_nfd_interface(self, session, nfd_interface_db, interface, is_update=False): plugged_in_port_id = interface.get('plugged_in_port_id') if not plugged_in_port_id: if not is_update: nfd_interface_db.plugged_in_port_id = None return with session.begin(subtransactions=True): port_info_db = nfp_db_model.PortInfo( id=plugged_in_port_id['id'], port_model=plugged_in_port_id['port_model'], port_classification=plugged_in_port_id['port_classification'], port_role=plugged_in_port_id['port_role']) if is_update: session.merge(port_info_db) else: session.add(port_info_db) session.flush() nfd_interface_db.plugged_in_port_id = port_info_db['id'] del interface['plugged_in_port_id']