-
Notifications
You must be signed in to change notification settings - Fork 389
/
edit-config-text-std.py
executable file
·45 lines (32 loc) · 1.13 KB
/
edit-config-text-std.py
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
40
41
42
43
44
#!/usr/bin/env python
import logging
import sys
from ncclient import manager
def connect(host, port, user, password):
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
conn.lock()
# configuration as a text string
host_name = """
system {
host-name foo-bar;
}
"""
edit_config_result = conn.edit_config(format='text', config=host_name)
logging.info(edit_config_result)
validate_result = conn.validate()
logging.info(validate_result)
compare_config_result = conn.compare_configuration()
logging.info(compare_config_result)
conn.commit()
conn.unlock()
conn.close_session()
if __name__ == '__main__':
LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT)
connect('router', '22', 'netconf', 'juniper!')