-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |