Commit 0c72ae9c authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

Austo discovery for Endpoints

parent d29a6712
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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({
+1 −0
Original line number Diff line number Diff line
@@ -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
+7 −4
Original line number Diff line number Diff line
@@ -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,6 +282,7 @@ 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 ""
@@ -289,6 +290,8 @@ class OCDriver(_Driver):
           
            context_client.close()
       
        if(len(ports_result)>0) : results.extend(ports_result)    
            
        return results

    @metered_subclass_method(METRICS_POOL)
+40 −2
Original line number Diff line number Diff line
@@ -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)
@@ -231,6 +237,29 @@ def has_opticalbands(xml_data:str):
      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):
   
    endpoints=[]
@@ -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