Skip to content
Snippets Groups Projects
test.py 1.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • from ncclient import manager
    from ncclient.xml_ import *
    import lxml.etree as ET
    
    device = {
        'host': '10.0.2.10',        # IP address or hostname of the remote machine
        'port': 2023,                # SSH port (default: 22)
        'username': 'admin',    # SSH username
        'password': 'admin',    # SSH password
        'device_params': {'name': 'default'},
         'hostkey_verify':False,
         "allow_agent":False
         ,"look_for_keys":False
    }
    def extract_value (xml_data):
        xml_bytes = xml_data.encode("utf-8")
        root = ET.fromstring(xml_bytes)
        namespace = {'oc': 'http://openconfig.net/yang/platform',
                  'td': 'http://openconfig.net/yang/terminal-device'}
    
        element = root.find('.//oc:component[oc:name="channel-4"]', namespace)
        if element is not None:
          parameter= element.find('.//td:frequency',namespace)
          if (parameter is not None):
             print(parameter.text)
          else :
              print("parameter is None")   
          
        else:
           print(" element not found.")
    
    with manager.connect(**device) as m:
        # Perform operations on the remote machine using the 'm' object
        # For example, you can retrieve the running configuration:
        #result =m.edit_config(target='running',config=edit_config)
        running_config = m.get_config('running').data_xml
       
       
       
        extract_value(running_config)