File: edit_config.py

package info (click to toggle)
python-ncclient 0.6.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,448 kB
  • sloc: python: 9,548; xml: 476; makefile: 77; sh: 5
file content (39 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
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')