Commit 75c30dd9 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

Bugs fixed in auto discovery for Transponders , and edit config for Roadms

parent 2a8dccd9
Loading
Loading
Loading
Loading

.xml.log.swp

0 → 100644
+8 KiB

File added.

No diff preview for this file type.

device

0 → 100644
+10754 −0

File added.

Preview size limit exceeded, changes collapsed.

+3 −2
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ from device.service.driver_api.AnyTreeTools import TreeNode
from .templates.VPN.common import seperate_port_config
#from .Tools import xml_pretty_print, xml_to_dict, xml_to_file

from .templates.VPN.roadms import  (create_media_channel,create_optical_band, disable_media_channel , delete_optical_band)
from .templates.VPN.roadms import  (create_media_channel,create_optical_band, disable_media_channel
                                     , delete_optical_band,create_media_channel_v2)
from .templates.VPN.transponder import  (edit_optical_channel ,change_optical_channel_status)
from .RetryDecorator import retry
from context.client.ContextClient import ContextClient
@@ -173,7 +174,7 @@ def edit_config(
            str_config_messages = create_optical_band(resources)   
        else :
            #roadm media-channel
            str_config_messages=create_media_channel(resources)
            str_config_messages=create_media_channel_v2(resources)
   #Disabling of the Configuration         
    else :
        # Device type is Transponder
+51 −0
Original line number Diff line number Diff line
@@ -128,6 +128,57 @@ def create_media_channel (resources):
 

         
def create_media_channel_v2 (resources):
    optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on"
    results=[]
    unwanted_keys=['destination_port','source_port','channel_namespace'
                ,'frequency','operational-mode','target-output-power',
               "handled_flow","channel_num"]

    config,ports,index=filter_config(resources,unwanted_keys)

    doc, tag, text = Doc().tagtext()

    with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"):
        with tag('wavelength-router', xmlns="http://openconfig.net/yang/wavelength-router"):
                with tag('media-channels'):
                    n = 0
                
                    for flow in ports:
                        src,dest=flow
                        with tag('channel', operation="create"):
                        #with tag('channel'):
                            with tag('index'):text(str(int(index)+n))
                            with tag('config'):
                                #with tag('index'):text(index)
                                for resource in config:
                                    
                                    if resource['resource_key'] == "index":
                                        with tag('index'):text(str(int(index)+n))
                                    elif resource['resource_key']== 'optical-band-parent'    :
                                        with tag('optical-band-parent',xmlns=optical_band_namespaces):text(resource['value'])
                                    elif resource['resource_key']== 'admin-state'    :
                                        with tag('admin-status'):text(resource['value'])
                                    else:
                                        with tag(resource['resource_key']):text(resource['value'])
                                   
                           
                            if src is not None and src != '0':                    
                                with tag('source'):
                                        with tag('config'):  
                                            with tag('port-name'):text(src)     
                        n+=1    
                        
    result = indent(
                doc.getvalue(),
                indentation = ' '*2,
                newline = ''
            )
    results.append(result)
    return results
        
                


def create_optical_band_old (resources) :
    results =[]
+38 −5
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ def extract_media_channels (data_xml:str):
        
  

def extract_roadm_ports (xml_data:str):
def extract_roadm_ports_old (xml_data:str):
  
    ports =[]
    pattern = r'\bMG_ON_OPTICAL_PORT_WAVEBAND\b'
@@ -155,6 +155,38 @@ def extract_roadm_ports (xml_data:str):
    return ports     


def extract_roadm_ports (xml_data:str):
  
    ports =[]
    pattern2=r'\bMG_ON_PORT_TYPE'
    pattern = r'\bMG_ON_OPTICAL_PORT_WAVEBAND\b'
    xml_bytes = xml_data.encode("utf-8")
    root = ET.fromstring(xml_bytes)

    

    namespace = {'oc': 'http://openconfig.net/yang/platform'}
    ports = []
    components = root.findall('.//oc:component',namespace)
    #print(f"component {components}")
    
    
    for component  in components:
       
        properties = component.find(".//oc:properties",namespace)
       
        if (properties is not None):
            for property in properties :
                value = property.find(".//oc:value",namespace)
                name= property.find('.//oc:name',namespace)
                if (re.search(pattern2,name.text)):
                   value = property.find(".//oc:value",namespace)
                   name_element= component.find(".//oc:name",namespace)
                   print('value',value.text)
                   ports.append((name_element.text,value.text))
              
    return ports                


  
def roadm_values_extractor (data_xml:str,resource_keys:list,dic:dict):
@@ -167,9 +199,10 @@ def roadm_values_extractor (data_xml:str,resource_keys:list,dic:dict):
     
     if len(ports)>0 :
      for port in ports :
        name,type=port
        resource_key = '/endpoints/endpoint[{:s}]'.format(name)
        resource_value = {'uuid': name, 'type':type}
    
        resource_key = '/endpoints/endpoint[{:s}]'.format(port)
        resource_value = {'uuid': port, 'type':'MG_ON_OPTICAL_PORT_WAVEBAND'}
        ports_result.append((resource_key, resource_value))
      
     return [ports_result,optical_bands,media_cahannels]   
Loading