0% found this document useful (0 votes)
55 views1 page

TP 5 - Netconf

The document provides code to connect to a router using NETCONF and retrieve the router's running configuration and capabilities. It connects to the router, retrieves the running configuration XML, and prints it. It also retrieves the router's model number, software version, and other system information fields.

Uploaded by

phenixeyeager
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views1 page

TP 5 - Netconf

The document provides code to connect to a router using NETCONF and retrieve the router's running configuration and capabilities. It connects to the router, retrieves the running configuration XML, and prints it. It also retrieves the router's model number, software version, and other system information fields.

Uploaded by

phenixeyeager
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Script Python pour obtenir la liste des capacités

Se connecter au routeur
In [1]: from ncclient import manager

m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

print("Connected")

C:\Users\Administrator\anaconda3\Lib\site-packages\paramiko\transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated


"class": algorithms.Blowfish,
Connected

Afficher les commandes avec NETCONF


In [2]: import xml.dom.minidom
from ncclient import manager

def get_running_config():
m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

netconf_reply = m.get_config(source='running')
netconf_data = xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml()
print(netconf_data)

get_running_config()

<?xml version="1.0" ?>


<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:60fae014-27d0-4aa2-a9f3-6ac
2454a3e78">
<data>
<app-hosting-cfg-data xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-app-hosting-cfg">
<apps>
<app>
<application-name>guestshell</application-name>
<application-network-resource>
<vnic-gateway-0>0</vnic-gateway-0>
<virtualportgroup-guest-interface-name-1>0</virtualportgroup-guest-interface-name-1>
<virtualportgroup-guest-ip-address-1>192.168.1.2</virtualportgroup-guest-ip-address-1>
<virtualportgroup-guest-ip-netmask-1>255.255.255.0</virtualportgroup-guest-ip-netmask-1>
<nameserver-0>8.8.8.8</nameserver-0>
</application-network-resource>
</app>
</apps>
</app-hosting-cfg-data>
<mdt-config-data xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-mdt-cfg">
<mdt-subscription>
<subscription-id>101</subscription-id>
<base>
<stream>yang-push</stream>
<encoding>encode-kvgpb</encoding>
<period>100</period>
<xpath>/process-cpu-ios-xe-oper:cpu-usage/cpu-utilization/five-seconds</xpath>
</base>
<mdt-receivers>
<address>10.10.20.50</address>
<port>57500</port>
<protocol>grpc-tcp</protocol>
</mdt-receivers>
</mdt-subscription>
</mdt-config-data>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<version>17.9</version>
<boot-start-marker/>
<boot-end-marker/>
<banner>
<motd>
<banner>
Welcome to the DevNet Sandbox for Cat8000V and IOS XE

The following programmability features are already enabled:

-NETCONF
-RESTCONF

Thanks for stopping by.


</banner>
</motd>
</banner>
<memory>
<free>
<low-watermark>
<processor>63709</processor>
</low-watermark>
</free>
</memory>
<call-home>
<contact-email-addr xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-call-home">sch-smart-licensing@cisco.com</contact-email-addr>
<tac-profile xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-call-home">
<profile>
<CiscoTAC-1>
<active>true</active>
<destination>
<transport-method>http</transport-method>
</destination>
</CiscoTAC-1>
</profile>
</tac-profile>
</call-home>
<service>
<timestamps>
<debug-config>
<datetime>
<msec/>
</datetime>
</debug-config>
<log-config>
<datetime>
<msec/>
</datetime>
</log-config>
</timestamps>
<call-home/>
<dhcp/>
</service>
<platform>
<console xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-platform">
<output>virtual</output>
</console>
<qfp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-platform">
<utilization>
<monitor>
<load>80</load>
</monitor>
</utilization>
</qfp>
<punt-keepalive xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-platform">
<disable-kernel-core>true</disable-kernel-core>
</punt-keepalive>
</platform>
<hostname>cat8000v</hostname>
<username>
<name>developer</name>
<privilege>15</privilege>
<secret>
<encryption>9</encryption>
<secret>$9$2uJqUsbtLlISaE$2BvT6b.W0phNXnUxNPzjppa19H0N1JbTT0PDXcWZfdM</secret>
</secret>
</username>
<ip>
<domain>
<name>cisco.com</name>
</domain>
<forward-protocol>
<protocol>nd</protocol>
</forward-protocol>
<ftp>
<passive/>
</ftp>
<multicast>
<route-limit xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-multicast">2147483647</route-limit>
</multicast>
<route>
<ip-route-interface-forwarding-list>
<prefix>0.0.0.0</prefix>
<mask>0.0.0.0</mask>
<fwd-list>
<fwd>GigabitEthernet1</fwd>
<interface-next-hop>
<ip-address>10.10.20.254</ip-address>
</interface-next-hop>
</fwd-list>
</ip-route-interface-forwarding-list>
</route>
<scp>
<server>
<enable/>
</server>
</scp>
<ssh>
<rsa>
<keypair-name>ssh-key</keypair-name>
</rsa>
<ssh-version>2</ssh-version>
<version>2</version>
</ssh>
<access-list>
<extended xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-acl">
<name>NAT-ACL</name>
<access-list-seq-rule>
<sequence>10</sequence>
<ace-rule>
<action>permit</action>
<protocol>ip</protocol>
<ipv4-address>192.168.1.0</ipv4-address>
<mask>0.0.0.255</mask>
<dst-any/>
</ace-rule>
</access-list-seq-rule>
</extended>
<extended xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-acl">
<name>Test</name>
<access-list-seq-rule>
<sequence>10</sequence>
<ace-rule>
<action>permit</action>
<protocol>ip</protocol>
<any/>
<dst-host-address>1.1.1.1</dst-host-address>
<dst-host>1.1.1.1</dst-host>
</ace-rule>
</access-list-seq-rule>
</extended>
</access-list>
<http xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-http">
<authentication>
<local/>
</authentication>
<server>true</server>
<secure-server>true</secure-server>
</http>
<igmp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-igmp">
<snooping>
<querier/>
</snooping>
</igmp>
<nat xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-nat">
<inside>
<source>
<list-interface>
<list>
<id>NAT-ACL</id>
<interface>
<name>GigabitEthernet1</name>
<overload-new/>
</interface>
</list>
</list-interface>
<list>
<id>NAT-ACL</id>
<interface>
<name>GigabitEthernet1</name>
<overload/>
</interface>
</list>
</source>
</inside>
</nat>
<nbar xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-nbar">
<classification>
<dns>
<classify-by-domain/>
</dns>
</classification>
</nbar>
</ip>
<interface>
<GigabitEthernet>
<name>1</name>
<description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description>
<switchport>
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch">
<native>
<vlan-config>
<tag>true</tag>
</vlan-config>
</native>
</trunk>
</switchport>
<ip>
<address>
<primary>
<address>10.10.20.48</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<GigabitEthernet>
<name>2</name>
<description>Network Interface</description>
<switchport>
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch">
<native>
<vlan-config>
<tag>true</tag>
</vlan-config>
</native>
</trunk>
</switchport>
<shutdown/>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<GigabitEthernet>
<name>3</name>
<description>Network Interface</description>
<switchport>
<trunk xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-switch">
<native>
<vlan-config>
<tag>true</tag>
</vlan-config>
</native>
</trunk>
</switchport>
<shutdown/>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<negotiation xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>10.0.0.1</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
</Loopback>
<Loopback>
<name>10</name>
<logging>
<event>
<link-status/>
</event>
</logging>
</Loopback>
<Loopback>
<name>109</name>
<description>Configured by RESTCONF ga jadi</description>
<ip>
<address>
<primary>
<address>10.255.255.9</address>
<mask>255.255.255.0</mask>
</primary>
</address>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
</Loopback>
<VirtualPortGroup>
<name>0</name>
<ip>
<address>
<primary>
<address>192.168.1.1</address>
<mask>255.255.255.0</mask>
</primary>
</address>
<nat xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-nat">
<inside/>
</nat>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
</VirtualPortGroup>
</interface>
<control-plane/>
<aaa>
<new-model xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-aaa"/>
<authentication xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-aaa">
<login>
<name>default</name>
<a1>
<local/>
</a1>
</login>
</authentication>
<authorization xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-aaa">
<exec>
<name>default</name>
<a1>
<local/>
</a1>
</exec>
</authorization>
<session-id xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-aaa">common</session-id>
</aaa>
<login>
<on-success>
<log/>
</on-success>
</login>
<multilink>
<bundle-name xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ppp">authenticated</bundle-name>
</multilink>
<redundancy/>
<subscriber>
<templating/>
</subscriber>
<ethernet>
<cfm xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ethernet">
<alarm>
<delay>2500</delay>
<reset>10000</reset>
</alarm>
</cfm>
</ethernet>
<crypto>
<ikev2 xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-crypto">
<http-url>
<cert/>
</http-url>
</ikev2>
<pki xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-crypto">
<certificate>
<chain>
<name>SLA-TrustPoint</name>
<certificate>
<serial>01</serial>
<certtype>ca</certtype>
</certificate>
</chain>
<chain>
<name>TP-self-signed-3209586145</name>
<certificate>
<serial>01</serial>
<certtype>self-signed</certtype>
</certificate>
</chain>
</certificate>
<trustpoint>
<id>SLA-TrustPoint</id>
<enrollment>
<enrollment-method>
<pkcs12/>
</enrollment-method>
<pkcs12/>
</enrollment>
<revocation-check>crl</revocation-check>
</trustpoint>
<trustpoint>
<id>TP-self-signed-3209586145</id>
<enrollment>
<enrollment-method>
<selfsigned/>
</enrollment-method>
<selfsigned/>
</enrollment>
<revocation-check>none</revocation-check>
<rsakeypair>
<key-label>TP-self-signed-3209586145</key-label>
</rsakeypair>
<subject-name>cn=IOS-Self-Signed-Certificate-3209586145</subject-name>
</trustpoint>
</pki>
</crypto>
<license>
<udi>
<pid>C8000V</pid>
<sn>9T53TD1XEQD</sn>
</udi>
</license>
<standby>
<redirects>true</redirects>
</standby>
<line>
<aux>
<first>0</first>
</aux>
<console>
<first>0</first>
<stopbits>1</stopbits>
</console>
<vty>
<first>0</first>
<last>4</last>
<length>0</length>
<transport>
<input>
<input>ssh</input>
</input>
</transport>
</vty>
</line>
<iox/>
<diagnostic xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-diagnostics">
<bootup>
<level>minimal</level>
</bootup>
</diagnostic>
</native>
<netconf-yang xmlns="http://cisco.com/yang/cisco-self-mgmt">
<cisco-ia xmlns="http://cisco.com/yang/cisco-ia">
<snmp-trap-control>
<global-forwarding>true</global-forwarding>
</snmp-trap-control>
<snmp-community-string>private</snmp-community-string>
</cisco-ia>
</netconf-yang>
<licensing xmlns="http://cisco.com/ns/yang/cisco-smart-license">
<config>
<enable>false</enable>
<privacy>
<hostname>false</hostname>
<version>false</version>
</privacy>
<utility>
<utility-enable>false</utility-enable>
</utility>
</config>
</licensing>
<subscription-config xmlns="urn:ietf:params:xml:ns:yang:ietf-event-notifications">
<subscription>
<subscription-id>101</subscription-id>
<stream xmlns:yp="urn:ietf:params:xml:ns:yang:ietf-yang-push">yp:yang-push</stream>
<encoding xmlns:cyp="urn:cisco:params:xml:ns:yang:cisco-xe-ietf-yang-push-ext">cyp:encode-kvgpb</encoding>
<xpath-filter xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-push">/process-cpu-ios-xe-oper:cpu-usage/cpu-utilization/five-secon
ds</xpath-filter>
<receivers>
<receiver>
<address>10.10.20.50</address>
<port>57500</port>
<protocol xmlns:cyp="urn:cisco:params:xml:ns:yang:cisco-xe-ietf-yang-push-ext">cyp:grpc-tcp</protocol>
</receiver>
</receivers>
<period xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-push">100</period>
</subscription>
</subscription-config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet1</name>
<description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.10.20.48</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet2</name>
<description>Network Interface</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>false</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>GigabitEthernet3</name>
<description>Network Interface</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<enabled>false</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>Loopback0</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.0.0.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>Loopback10</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>Loopback109</name>
<description>Configured by RESTCONF ga jadi</description>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>10.255.255.9</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
<interface>
<name>VirtualPortGroup0</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:propVirtual</type>
<enabled>true</enabled>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
<address>
<ip>192.168.1.1</ip>
<netmask>255.255.255.0</netmask>
</address>
</ipv4>
<ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip"/>
</interface>
</interfaces>
<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
<enable-nacm>true</enable-nacm>
<read-default>deny</read-default>
<write-default>deny</write-default>
<exec-default>deny</exec-default>
<enable-external-groups>true</enable-external-groups>
<rule-list>
<name>admin</name>
<group>PRIV15</group>
<rule>
<name>permit-all</name>
<module-name>*</module-name>
<access-operations>*</access-operations>
<action>permit</action>
</rule>
</rule-list>
</nacm>
<routing xmlns="urn:ietf:params:xml:ns:yang:ietf-routing">
<routing-instance>
<name>default</name>
<description>default-vrf [read-only]</description>
<routing-protocols>
<routing-protocol>
<type>static</type>
<name>1</name>
<static-routes>
<ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ipv4-unicast-routing">
<route>
<destination-prefix>0.0.0.0/0</destination-prefix>
<next-hop>
<outgoing-interface>GigabitEthernet1</outgoing-interface>
</next-hop>
</route>
</ipv4>
</static-routes>
</routing-protocol>
</routing-protocols>
</routing-instance>
</routing>
<acl xmlns="http://openconfig.net/yang/acl">
<acl-sets>
<acl-set>
<name>NAT-ACL</name>
<type>ACL_IPV4</type>
<config>
<name>NAT-ACL</name>
<type>ACL_IPV4</type>
</config>
<acl-entries>
<acl-entry>
<sequence-id>10</sequence-id>
<config>
<sequence-id>10</sequence-id>
</config>
<ipv4>
<config>
<source-address>192.168.1.0/24</source-address>
<protocol xmlns:oc-acl-cisco="http://cisco.com/ns/yang/cisco-xe-openconfig-acl-ext">oc
-acl-cisco:IP</protocol>
</config>
</ipv4>
<transport>
<config>
<source-port>ANY</source-port>
<destination-port>ANY</destination-port>
</config>
</transport>
<actions>
<config>
<forwarding-action>ACCEPT</forwarding-action>
<log-action>LOG_NONE</log-action>
</config>
</actions>
</acl-entry>
</acl-entries>
</acl-set>
<acl-set>
<name>Test</name>
<type>ACL_IPV4</type>
<config>
<name>Test</name>
<type>ACL_IPV4</type>
</config>
<acl-entries>
<acl-entry>
<sequence-id>10</sequence-id>
<config>
<sequence-id>10</sequence-id>
</config>
<ipv4>
<config>
<destination-address>1.1.1.1/32</destination-address>
<protocol xmlns:oc-acl-cisco="http://cisco.com/ns/yang/cisco-xe-openconfig-acl-ext">oc
-acl-cisco:IP</protocol>
</config>
</ipv4>
<transport>
<config>
<source-port>ANY</source-port>
<destination-port>ANY</destination-port>
</config>
</transport>
<actions>
<config>
<forwarding-action>ACCEPT</forwarding-action>
<log-action>LOG_NONE</log-action>
</config>
</actions>
</acl-entry>
</acl-entries>
</acl-set>
</acl-sets>
</acl>
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>GigabitEthernet1</name>
<config>
<name>GigabitEthernet1</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description>
<enabled>true</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<description>MANAGEMENT INTERFACE - DON'T TOUCH ME</description>
<enabled>true</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<addresses>
<address>
<ip>10.10.20.48</ip>
<config>
<ip>10.10.20.48</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
<config>
<mac-address>00:50:56:bf:f0:a5</mac-address>
<auto-negotiate>true</auto-negotiate>
<enable-flow-control>true</enable-flow-control>
</config>
</ethernet>
</interface>
<interface>
<name>GigabitEthernet2</name>
<config>
<name>GigabitEthernet2</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<description>Network Interface</description>
<enabled>false</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<description>Network Interface</description>
<enabled>false</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
<config>
<mac-address>00:50:56:bf:92:f9</mac-address>
<auto-negotiate>true</auto-negotiate>
<enable-flow-control>true</enable-flow-control>
</config>
</ethernet>
</interface>
<interface>
<name>GigabitEthernet3</name>
<config>
<name>GigabitEthernet3</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
<description>Network Interface</description>
<enabled>false</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<description>Network Interface</description>
<enabled>false</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="http://openconfig.net/yang/interfaces/ethernet">
<config>
<mac-address>00:50:56:bf:15:a7</mac-address>
<auto-negotiate>true</auto-negotiate>
<enable-flow-control>true</enable-flow-control>
</config>
</ethernet>
</interface>
<interface>
<name>Loopback0</name>
<config>
<name>Loopback0</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<enabled>true</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<addresses>
<address>
<ip>10.0.0.1</ip>
<config>
<ip>10.0.0.1</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
</interface>
<interface>
<name>Loopback10</name>
<config>
<name>Loopback10</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<enabled>true</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<enabled>true</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
</interface>
<interface>
<name>Loopback109</name>
<config>
<name>Loopback109</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
<description>Configured by RESTCONF ga jadi</description>
<enabled>true</enabled>
</config>
<subinterfaces>
<subinterface>
<index>0</index>
<config>
<index>0</index>
<description>Configured by RESTCONF ga jadi</description>
<enabled>true</enabled>
</config>
<ipv4 xmlns="http://openconfig.net/yang/interfaces/ip">
<addresses>
<address>
<ip>10.255.255.9</ip>
<config>
<ip>10.255.255.9</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="http://openconfig.net/yang/interfaces/ip">
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
</interface>
<interface>
<name>VirtualPortGroup0</name>
<config>
<name>VirtualPortGroup0</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:propVirtual</type>
<enabled>true</enabled>
</config>
</interface>
</interfaces>
<lldp xmlns="http://openconfig.net/yang/lldp">
<config>
<enabled>false</enabled>
</config>
<interfaces>
<interface>
<name>GigabitEthernet1</name>
<config>
<name>GigabitEthernet1</name>
<enabled>true</enabled>
</config>
</interface>
<interface>
<name>GigabitEthernet2</name>
<config>
<name>GigabitEthernet2</name>
<enabled>true</enabled>
</config>
</interface>
<interface>
<name>GigabitEthernet3</name>
<config>
<name>GigabitEthernet3</name>
<enabled>true</enabled>
</config>
</interface>
</interfaces>
</lldp>
<network-instances xmlns="http://openconfig.net/yang/network-instance">
<network-instance>
<name>default</name>
<config>
<name>default</name>
<type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:DEFAULT_INSTANCE</type>
<description>default-vrf [read-only]</description>
</config>
<tables>
<table>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protoc
ol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
<config>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED
</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-fa
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</protoc
ol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
<config>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED
</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-fa
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family>
<config>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-fa
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-family>
<config>
<protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</protocol>
<address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV6</address-fa
mily>
</config>
</table>
</tables>
<protocols>
<protocol>
<identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</identifier>
<name>DEFAULT</name>
<config>
<identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:STATIC</identifi
er>
<name>DEFAULT</name>
</config>
<static-routes>
<static>
<prefix>0.0.0.0/0</prefix>
<config>
<prefix>0.0.0.0/0</prefix>
</config>
<next-hops>
<next-hop>
<index>GigabitEthernet1_10.10.20.254</index>
<config>
<index>GigabitEthernet1_10.10.20.254</index>
<next-hop>10.10.20.254</next-hop>
<metric>1</metric>
</config>
<interface-ref>
<config>
<interface>GigabitEthernet1</interface>
</config>
</interface-ref>
</next-hop>
</next-hops>
</static>
</static-routes>
</protocol>
<protocol>
<identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</iden
tifier>
<name>DEFAULT</name>
<config>
<identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECT
ED</identifier>
<name>DEFAULT</name>
</config>
</protocol>
</protocols>
</network-instance>
</network-instances>
</data>
</rpc-reply>

In [3]: import xmltodict


from ncclient import manager

def get_hostname():
m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

netconf_reply = m.get_config(source='running')
netconf_data = xmltodict.parse(netconf_reply.xml)
print("IOS Version: {}".format(netconf_data["rpc-reply"]["data"]["native"]["version"]))
print("Hostname: {}".format(netconf_data["rpc-reply"]["data"]["native"]["hostname"]))

get_hostname()

IOS Version: 17.9


Hostname: cat8000v

Demande de l’ensemble de la configuration


In [4]: import xmltodict
from ncclient import manager

def get_hostname_filter():
m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

filter = """
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<hostname></hostname>
<version></version>
</native>
</filter>
"""

netconf_reply = m.get_config(source='running', filter=filter)


netconf_data = xmltodict.parse(netconf_reply.xml)
print("IOS Version: {}".format(netconf_data["rpc-reply"]["data"]["native"]["version"]))
print("Hostname: {}".format(netconf_data["rpc-reply"]["data"]["native"]["hostname"]))

get_hostname_filter()

IOS Version: 17.9


Hostname: cat8000v

Utilisation d’un filtre NETCONF


In [5]: import xmltodict
from ncclient import manager

def change_interface(user_selection):
m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

int_status = user_selection

config = '''
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>GigabitEthernet3</name>
<enabled>{}</enabled>
</interface>
</interfaces>
</config>
'''.format("true" if int_status == 1 else "false")

netconf_reply = m.edit_config(target='running', config=config)


print("Did it work? {}".format(netconf_reply.ok))

# To disable the interface


# change_interface(0) # Disable

# To enable the interface


change_interface(1) # Enable

Did it work? True

Modifier la configuration de l’interface (GigabitEthernet3):


In [6]: import lxml.etree as ET
from ncclient import manager

def save_running_config():
m = manager.connect(
host="10.10.20.48",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)

rpc_body = '''
<cisco-ia:save-config xmlns:cisco-ia="http://cisco.com/yang/cisco-ia"/>
'''

netconf_reply = m.dispatch(ET.fromstring(rpc_body)).xml
print("Did it work? {}".format(netconf_reply))

save_running_config()

Did it work? <?xml version="1.0" encoding="UTF-8"?>


<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:cefdf3de-4a4b-4ee6-9c34-bb415ba5dbd2" xmlns:nc="urn:ietf:params:xml:ns:netcon
f:base:1.0"><result xmlns='http://cisco.com/yang/cisco-ia'>Save running-config successful</result>
</rpc-reply>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy