-
Notifications
You must be signed in to change notification settings - Fork 3
/
edit_config_merge.py
152 lines (141 loc) · 4.27 KB
/
edit_config_merge.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from ncclient import manager
eos=manager.connect(host="10.83.28.221", port="830", timeout=30, username="arista", password="arista", hostkey_verify=False)
# Edit the running configuration with merge operation
# Small examples
cfg_domain_name = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<config>
<domain-name>abc.xyz</domain-name>
</config>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = cfg_domain_name, default_operation="merge")
cfg_login_banner = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<config>
<login-banner>Access to this swicth is stricly restticted to authorized persons only. Every activity on this system is monitored. </login-banner>
</config>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = cfg_login_banner, default_operation="merge")
cfg_hostname = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<config>
<hostname>switch1</hostname>
</config>
</system>
</config>'''
reply = eos.edit_config(target = "running", config = cfg_hostname, default_operation="merge")
cfg_username = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<aaa>
<authentication>
<users>
<user>
<username>gnmi</username>
<config>
<username>gnmi</username>
<password>gnmi123</password>
<role>network-admin</role>
</config>
</user>
</users>
</authentication>
</aaa>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = cfg_username, default_operation="merge")
cfg_username = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<aaa>
<authentication>
<users>
<user>
<username>netconf</username>
<config>
<username>netconf</username>
<password-hashed>$6$AqpRA4JEgazppO2A$M9Yg7bXVTvuWN/ht0Uf3j08rFsXLJPjEuE8kr.H85Mb1D9I7YMgUcEJoDDrGPtYC4yHOdC9il32MtPI8R916f1</password-hashed>
<role>network-admin</role>
</config>
</user>
</users>
</authentication>
</aaa>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = cfg_username, default_operation="merge")
cfg_interface_ethernet3_description = '''
<config>
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Ethernet3</name>
<config>
<description>This is the best</description>
</config>
</interface>
</interfaces>
</config>
'''
reply = eos.edit_config(target="running", config=cfg_interface_ethernet3_description, default_operation="merge")
reply = eos.edit_config(target="running", config=cfg_interface_ethernet3_description)
# Edit the running configuration with merge operation
# Larger example
cfg_system = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<config>
<domain-name>abc.xyz</domain-name>
<hostname>switch1</hostname>
</config>
<dns>
<servers>
<server>
<address>
8.8.8.8
</address>
<config>
<address>8.8.8.8</address>
<port>53</port>
</config>
</server>
<server>
<address>10.83.28.52</address>
<config>
<address>10.83.28.52</address>
<port>53</port>
</config>
</server>
</servers>
</dns>
</system>
</config>
'''
configuration = eos.edit_config(target = "running", config = cfg_system, default_operation="merge")
print(configuration)
print(configuration.ok)
system = '''
<system xmlns="http://openconfig.net/yang/system">
<dns>
<servers>
</servers>
</dns>
<config>
<domain-name>
</domain-name>
<hostname>
</hostname>
</config>
</system>
'''
system_conf = eos.get_config(source="running", filter=("subtree", system))
print (system_conf)
eos.close_session()