05-06-2023 11:58 AM - edited 05-06-2023 12:00 PM
Hello
I'm trying to use ncclient to add an SNMP server, after successfully getting the config. I really don't know where to put operation="create" or if I even need to do it.
This is just a lab environment, IOS-XE v 16.12.05
05-06-2023 12:42 PM
05-06-2023 12:47 PM
I don't think I'm trying to do that, I'm simply trying to change the SNMP server on the device using NETCONF.
05-07-2023 01:57 AM
Try
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<snmp-server>
<community>
<name>public</name>
<RO/>
</community>
<host>
<version>2c</version>
<ip>
<hostip>4.4.4.4</hostip>
</ip>
<community>public</community>
</host>
</snmp-server>
</native>
</config>
"""
05-07-2023 04:17 AM
No joy, said community is a bad element. Not sure where you got the above from, to be honest.
05-07-2023 06:46 AM
@ChrisNewnham_ test this on the DV sandbox version 17.09.02a. Works ok. HTH
from ncclient import manager
import xml.dom.minidom
RTR = manager.connect(
host="sandbox-iosxe-latest-1.cisco.com",
port="830",
username="admin",
password="C1sco12345",
hostkey_verify=False)
snmp_server_xml = """
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<snmp-server>
<host-config xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-snmp">
<ip-community>
<ip-address>4.4.4.4</ip-address>
<community-or-user>MOO</community-or-user>
</ip-community>
</host-config>
</snmp-server>
</native>
</config>
"""
edit_config_response = RTR.edit_config(target="running", config=snmp_server_xml)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide