1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#!/usr/bin/python3
import logging
from ncclient import manager
from ncclient.xml_ import *
def connect(host, port, user, password):
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=10,
device_params={'name': 'alu'},
hostkey_verify=False)
print('Set CLI -config -block')
config = """
configure port 1/1/1
description \"Loaded as CLI -block\"
exit"""
conn.load_configuration(format='cli', config=config)
print('Load XML -config')
config = new_ele('configure', attrs={'xmlns': ALU_CONFIG})
port = sub_ele(config, 'port')
sub_ele(port, 'port-id').text = '1/1/1'
desc = sub_ele(port, 'description')
sub_ele(desc, 'long-description-string').text = "Loaded using XML"
conn.load_configuration(config=config, format='xml')
conn.close_session()
if __name__ == '__main__':
connect('router', 830, 'admin', 'admin')
|