Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
ksator committed Jul 16, 2021
1 parent 2c3bed2 commit 8681aef
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@
with eos.locked("candidate"):
eos.edit_config(target = "candidate", config = cfg_system, default_operation="merge")
eos.edit_config(target = "candidate", config = cfg_interface_ethernet3_description, default_operation="merge")
# to commit changes
eos.commit()
# to discard changes
# eos.discard_changes()
50 changes: 50 additions & 0 deletions candidate_configuration_discard_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file shows an example with the edit-config NETCONF operation and the candidate configuration datastore.

cfg_system = '''
<config>
<system xmlns="http://openconfig.net/yang/system">
<config>
<domain-name>abc.xyz</domain-name>
<hostname>switch1</hostname>
<login-banner>Access to this swicth is stricly restticted to authorized persons only. Every activity on this system is monitored. </login-banner>
</config>
<dns>
<servers>
<server>
<address>8.8.8.8</address>
<config>
<address>8.8.8.8</address>
</config>
</server>
<server>
<address>1.1.1.1</address>
<config>
<address>1.1.1.1</address>
</config>
</server>
</servers>
</dns>
</system>
</config>
'''

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>
'''

from ncclient import manager

with manager.connect(host="10.83.28.221", port="830", timeout=30, username="arista", password="arista", hostkey_verify=False) as eos:
with eos.locked("candidate"):
eos.edit_config(target = "candidate", config = cfg_system, default_operation="merge")
eos.edit_config(target = "candidate", config = cfg_interface_ethernet3_description, default_operation="merge")
eos.discard_changes()
68 changes: 68 additions & 0 deletions edit_config_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 delete operation
# Get first the running configuration to be sure to then delete existing configuration data

conf = '''
<system xmlns="http://arista.com/yang/openconfig/system/">
<config>
<domain-name>
</domain-name>
</config>
<dns>
<servers>
<server>
</server>
</servers>
</dns>
<aaa>
<authentication>
<users>
<user>
<username>
</username>
</user>
</users>
</authentication>
</aaa>
</system>
'''
eos.get_config(source="running", filter=("subtree", conf))

conf = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="http://arista.com/yang/openconfig/system/">
<config>
<domain-name operation="delete">abc.xyz</domain-name>
</config>
<dns>
<servers>
<server>
<address operation="delete">1.1.1.1</address>
</server>
</servers>
</dns>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = conf, default_operation="none")

conf = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="http://arista.com/yang/openconfig/system/">
<aaa>
<authentication>
<users>
<user>
<username operation="delete">gnmi</username>
</user>
</users>
</authentication>
</aaa>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = conf, default_operation="none")

eos.close_session()
80 changes: 1 addition & 79 deletions edit_config.py → edit_config_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,82 +149,4 @@
system_conf = eos.get_config(source="running", filter=("subtree", system))
print (system_conf)

# Edit the running configuration with replace operation

cfg_interface_ethernet3_description = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Ethernet3/1</name>
<config>
<description nc:operation="replace">This is the new interface description</description>
</config>
</interface>
</interfaces>
</config>
'''
reply = eos.edit_config(target="running", config=cfg_interface_ethernet3_description, default_operation="none")

# Edit the running configuration with delete operation
# Get first the running configuration to be sure to then delete existing configuration data

conf = '''
<system xmlns="http://arista.com/yang/openconfig/system/">
<config>
<domain-name>
</domain-name>
</config>
<dns>
<servers>
<server>
</server>
</servers>
</dns>
<aaa>
<authentication>
<users>
<user>
<username>
</username>
</user>
</users>
</authentication>
</aaa>
</system>
'''
eos.get_config(source="running", filter=("subtree", conf))

conf = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="http://arista.com/yang/openconfig/system/">
<config>
<domain-name operation="delete">abc.xyz</domain-name>
</config>
<dns>
<servers>
<server>
<address operation="delete">1.1.1.1</address>
</server>
</servers>
</dns>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = conf, default_operation="none")

conf = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="http://arista.com/yang/openconfig/system/">
<aaa>
<authentication>
<users>
<user>
<username operation="delete">gnmi</username>
</user>
</users>
</authentication>
</aaa>
</system>
</config>
'''
reply = eos.edit_config(target = "running", config = conf, default_operation="none")
eos.close_session()
20 changes: 20 additions & 0 deletions edit_config_replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 replace operation

cfg_interface_ethernet3_description = '''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Ethernet3/1</name>
<config>
<description nc:operation="replace">This is the new interface description</description>
</config>
</interface>
</interfaces>
</config>
'''
reply = eos.edit_config(target="running", config=cfg_interface_ethernet3_description, default_operation="none")

eos.close_session()

0 comments on commit 8681aef

Please sign in to comment.