diff --git a/src/context/service/database/Device.py b/src/context/service/database/Device.py index d0674e89b03d160fc116c0f5ca5856b72769db78..6c3bd24e0de26d9a2a172bc76c5358fde32d0560 100644 --- a/src/context/service/database/Device.py +++ b/src/context/service/database/Device.py @@ -136,6 +136,7 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi 'created_at' : now, 'updated_at' : now, }) + LOGGER.info(f"endpoint data {endpoints_data}") if endpoint_topology_uuid not in topology_uuids: related_topologies.append({ diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index f3700e10488228387145a2c4c8574a899675aade..bd6a2070aa7763b3c7d22cdf8667eb949fcf6d66 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -114,6 +114,7 @@ def populate_endpoints( resources_to_get = [RESOURCE_ENDPOINTS] results_getconfig = driver.GetConfig(resources_to_get) LOGGER.debug('results_getconfig = {:s}'.format(str(results_getconfig))) + LOGGER.info('results_getconfig = {:s}'.format(str(results_getconfig))) # first quick pass to identify need of mgmt endpoints and links add_mgmt_port = False diff --git a/src/device/service/drivers/oc_driver/OCDriver.py b/src/device/service/drivers/oc_driver/OCDriver.py index 0f94b1c695228a7ccb7ff0c73f41133bd20fafab..1e9ea74c9e832a546c31a556f676a37d319d91b2 100644 --- a/src/device/service/drivers/oc_driver/OCDriver.py +++ b/src/device/service/drivers/oc_driver/OCDriver.py @@ -263,7 +263,7 @@ class OCDriver(_Driver): try: xml_data = self.__netconf_handler.get().data_xml - transceivers,interfaces,channels_lst,channel_namespace,endpoints=extractor(data_xml=xml_data,resource_keys=filter_fields,dic=config) + transceivers,interfaces,channels_lst,channel_namespace,endpoints,ports_result=extractor(data_xml=xml_data,resource_keys=filter_fields,dic=config) logging.info(f"xml response {xml_data}") @@ -273,7 +273,7 @@ class OCDriver(_Driver): self.__logger.exception(MSG.format(e)) #results.append((resource_key, e)) # if validation fails, store the exception - #///////////////////////// divider //////////////////////////////////////////////////////// + #///////////////////////// store optical configurtaion //////////////////////////////////////////////////////// value_dic={} @@ -282,13 +282,16 @@ class OCDriver(_Driver): value_dic["interfaces"]=interfaces value_dic["channel_namespace"]=channel_namespace value_dic["endpoints"]=endpoints + value_dic["ports"]=ports_result logging.info(f"parameters {value_dic}") opticalConfig.config=json.dumps(value_dic) opticalConfig.opticalconfig_id.opticalconfig_uuid=self.__device_uuid if self.__device_uuid is not None else "" config_id=context_client.SetOpticalConfig(opticalConfig) - context_client.close() - + context_client.close() + + if(len(ports_result)>0) : results.extend(ports_result) + return results @metered_subclass_method(METRICS_POOL) diff --git a/src/device/service/drivers/oc_driver/templates/Tools.py b/src/device/service/drivers/oc_driver/templates/Tools.py index bc69db6a6e6afe2d1fe4d5b2d30f6471db5fa303..a088d4a1f133cb781471ed736335359c9c81db5d 100644 --- a/src/device/service/drivers/oc_driver/templates/Tools.py +++ b/src/device/service/drivers/oc_driver/templates/Tools.py @@ -19,6 +19,7 @@ from typing import Collection, Dict, Any from yattag import Doc, indent from .VPN.physical import create_optical_channel + def add_value_from_tag(target : Dict, field_name: str, field_value : ET.Element, cast=None) -> None: if isinstance(field_value,str) or field_value is None or field_value.text is None: return field_value = field_value.text @@ -55,9 +56,10 @@ def generate_templates(resource_key: str, resource_value: str, channel:str) -> s data['name']=channel data['resource_key']=resource_key data['value']=resource_value - result_templates.append(create_physical_config(data)) + #result_templates.append(create_physical_config(data)) return result_templates + def extract_channel_xmlns (data_xml:str,is_opticalband:bool): xml_bytes = data_xml.encode("utf-8") root = ET.fromstring(xml_bytes) @@ -88,6 +90,7 @@ def extract_channel_xmlns (data_xml:str,is_opticalband:bool): return namespace + def extract_channels_based_on_channelnamespace (xml_data:str,channel_namespace:str,is_opticalband:bool): xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) @@ -122,6 +125,7 @@ def extract_channels_based_on_channelnamespace (xml_data:str,channel_namespace:s # Retrieve port-name for dest return channels + def extract_channels_based_on_type (xml_data:str): xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) @@ -196,6 +200,7 @@ def extract_tranceiver (data_xml:str,dic:dict): component_names = [component.text for component in transceiver_components] dic['transceiver']=component_names return dic + def extract_interface (xml_data:str,dic:dict): xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) @@ -218,6 +223,7 @@ def extract_interface (xml_data:str,dic:dict): else : dic['interface']={} return dic + def has_opticalbands(xml_data:str): xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) @@ -230,6 +236,29 @@ def has_opticalbands(xml_data:str): else : has_opticalbands=False return has_opticalbands + +def extract_ports_based_on_type (xml_data:str): + pattern = r'\bPORT\b' + xml_bytes = xml_data.encode("utf-8") + root = ET.fromstring(xml_bytes) + + namespace = {'oc': 'http://openconfig.net/yang/platform', 'typex': 'http://openconfig.net/yang/platform-types'} + ports = [] + components = root.findall('.//oc:type',namespace) + + + for component in components: + + + if component is not None and re.search(pattern,component.text): + + + name_element = component.getprevious() + port_name =name_element.text + port_index=name_element.text.split("-")[1] + port = (port_name,port_index) + ports.append(port) + return ports def extractor(data_xml:str,resource_keys:list,dic:dict): @@ -240,8 +269,10 @@ def extractor(data_xml:str,resource_keys:list,dic:dict): # channel_names=extract_channels_based_on_type(xml_data=data_xml) # if len(channel_names)==0 : channel_names= extract_channels_based_on_channelnamespace(xml_data=data_xml,channel_namespace=channel_namespace,is_opticalband=is_opticalband) + ports = extract_ports_based_on_type(data_xml) lst_dic=[] + ports_result=[] if (is_opticalband): endpoints=channel_names else: @@ -258,5 +289,12 @@ def extractor(data_xml:str,resource_keys:list,dic:dict): lst_dic.append(dic) transceivers_dic=extract_tranceiver(data_xml=data_xml,dic={}) interfaces_dic=extract_interface(xml_data=data_xml,dic={}) + if len(ports)>0 : + for port in ports : + endpoint_name,endpoint_id=port + resource_key = '/endpoints/endpoint[{:s}]'.format(endpoint_id) + resource_value = {'uuid': endpoint_id, 'type':endpoint_name} + ports_result.append((resource_key, resource_value)) + - return [transceivers_dic,interfaces_dic,lst_dic,channel_namespace,endpoints] \ No newline at end of file + return [transceivers_dic,interfaces_dic,lst_dic,channel_namespace,endpoints,ports_result] \ No newline at end of file