-
Notifications
You must be signed in to change notification settings - Fork 3
/
rpc.py
53 lines (45 loc) · 1.31 KB
/
rpc.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
from ncclient import manager
from ncclient.xml_ import to_ele
vlan_id = "7"
vlan_name = "seven"
interface_description = "whatever"
interface = "3"
def vlan_rpc(id, name):
vlan_rpc = """
<nc:edit-config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<commands>
<command>vlan %s</command>
<command>name %s</command>
</commands>
</nc:edit-config>
""" % (vlan_id, vlan_name)
return (vlan_rpc)
def interface_rpc(interface, description, vlan):
interface_rpc = """
<nc:edit-config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<running/>
</target>
<commands>
<command>interface ethernet %s</command>
<command>description %s</command>
<command>switchport access vlan %s</command>
</commands>
</nc:edit-config>
""" % (interface, description, vlan)
return (interface_rpc)
eos=manager.connect(host="10.83.28.203", port="830", timeout=30, username="arista", password="arista", hostkey_verify=False)
rpc = vlan_rpc(vlan_id, vlan_name)
# print(rpc)
rpcreply = eos.dispatch(to_ele(rpc))
print(rpcreply)
# print(rpcreply.ok)
rpc = interface_rpc(interface, interface_description, vlan_id)
# print(rpc)
rpcreply = eos.dispatch(to_ele(rpc))
print(rpcreply)
# print(rpcreply.ok)
eos.close_session()