Skip to content
Snippets Groups Projects
test.py 3 KiB
Newer Older
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
from ncclient import manager

Mohammad Ismaeel's avatar
Mohammad Ismaeel committed

media_channel = ''' 
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">  
    <wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">    
        <media-channels>      
            <channel operation="create">        
            <index>2</index>       
                <config>          
                <name>C_BAND</name>          
                <optical-band-parent xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on">1</optical-band-parent>          
                <index>2</index>          
                <lower-frequency>192006251</lower-frequency>          
                <upper-frequency>192056250</upper-frequency>       
                </config>        
            <dest>          
                <config>            
                <port-name>2</port-name>          
                </config>        
            </dest>      
            </channel>    
        </media-channels>  
    </wavelength-router>
</config>

'''


Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
disable_mc= ''' 
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> 
    <wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">    
        <media-channels>      
            <channel operation="delete">        
                <index>2</index>        
                <config>          
                 <index>2</index>      
                </config>      
            </channel>   
        </media-channels>  
    </wavelength-router>
</config>
'''
create_ob= ''' 
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">  
<wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">  
<optical-bands xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on">    
<optical-band>        <index>1</index>        <config>          <name>C_BAND</name>       
<index>1</index>          <lower-frequency>192006252</lower-frequency>       
<upper-frequency>192206250.0</upper-frequency>          <admin-status>ENABLED</admin-status>    
</config>        <dest>          <config>            <port-name>101</port-name>          
</config>        </dest>      </optical-band>    </optical-bands>  </wavelength-router></config>
'''
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
# Define device connection details
device = {
    'host': '10.0.2.4',  # replace with the target device's hostname or IP address
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    'port': 2025,               # NETCONF default port
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    'username': 'admin', # replace with your username
    'password': 'admin', # replace with your password
    'hostkey_verify': False ,   # disable host key verification (use only for testing)

Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    "look_for_keys": False,
    "allow_agent": False,

    "device_params": {
                "name": "default"
                },
}

# Establish a NETCONF connection
with manager.connect(**device) as m:
    print("Connected to the device successfully!")
    config = m.get_config(source='running').data_xml
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
  
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    print("Device Configuration:")
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    with open('d.log', 'w') as log_file:
        print(config,file=log_file)
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    # result = m.edit_config(target='running', config=create_ob)
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed
    # print (result)
Mohammad Ismaeel's avatar
Mohammad Ismaeel committed