Script Python pour obtenir la liste des capacités
Se connecter au routeur
In [1]: from ncclient import manager
m = [Link](
host="[Link]",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)
print("Connected")
C:\Users\Administrator\anaconda3\Lib\site-packages\paramiko\[Link]: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": [Link],
Connected
Afficher les commandes avec NETCONF
In [2]: import [Link]
from ncclient import manager
def get_running_config():
m = [Link](
host="[Link]",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)
netconf_reply = m.get_config(source='running')
netconf_data = [Link](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="[Link]
<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>[Link]</virtualportgroup-guest-ip-address-1>
<virtualportgroup-guest-ip-netmask-1>[Link]</virtualportgroup-guest-ip-netmask-1>
<nameserver-0>[Link]</nameserver-0>
</application-network-resource>
</app>
</apps>
</app-hosting-cfg-data>
<mdt-config-data xmlns="[Link]
<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>[Link]</address>
<port>57500</port>
<protocol>grpc-tcp</protocol>
</mdt-receivers>
</mdt-subscription>
</mdt-config-data>
<native xmlns="[Link]
<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="[Link]
<tac-profile xmlns="[Link]
<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="[Link]
<output>virtual</output>
</console>
<qfp xmlns="[Link]
<utilization>
<monitor>
<load>80</load>
</monitor>
</utilization>
</qfp>
<punt-keepalive xmlns="[Link]
<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>[Link]</name>
</domain>
<forward-protocol>
<protocol>nd</protocol>
</forward-protocol>
<ftp>
<passive/>
</ftp>
<multicast>
<route-limit xmlns="[Link]
</multicast>
<route>
<ip-route-interface-forwarding-list>
<prefix>[Link]</prefix>
<mask>[Link]</mask>
<fwd-list>
<fwd>GigabitEthernet1</fwd>
<interface-next-hop>
<ip-address>[Link]</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="[Link]
<name>NAT-ACL</name>
<access-list-seq-rule>
<sequence>10</sequence>
<ace-rule>
<action>permit</action>
<protocol>ip</protocol>
<ipv4-address>[Link]</ipv4-address>
<mask>[Link]</mask>
<dst-any/>
</ace-rule>
</access-list-seq-rule>
</extended>
<extended xmlns="[Link]
<name>Test</name>
<access-list-seq-rule>
<sequence>10</sequence>
<ace-rule>
<action>permit</action>
<protocol>ip</protocol>
<any/>
<dst-host-address>[Link]</dst-host-address>
<dst-host>[Link]</dst-host>
</ace-rule>
</access-list-seq-rule>
</extended>
</access-list>
<http xmlns="[Link]
<authentication>
<local/>
</authentication>
<server>true</server>
<secure-server>true</secure-server>
</http>
<igmp xmlns="[Link]
<snooping>
<querier/>
</snooping>
</igmp>
<nat xmlns="[Link]
<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="[Link]
<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="[Link]
<native>
<vlan-config>
<tag>true</tag>
</vlan-config>
</native>
</trunk>
</switchport>
<ip>
<address>
<primary>
<address>[Link]</address>
<mask>[Link]</mask>
</primary>
</address>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
<access-session>
<host-mode>multi-auth</host-mode>
</access-session>
<negotiation xmlns="[Link]
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<GigabitEthernet>
<name>2</name>
<description>Network Interface</description>
<switchport>
<trunk xmlns="[Link]
<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="[Link]
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<GigabitEthernet>
<name>3</name>
<description>Network Interface</description>
<switchport>
<trunk xmlns="[Link]
<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="[Link]
<auto>true</auto>
</negotiation>
</GigabitEthernet>
<Loopback>
<name>0</name>
<ip>
<address>
<primary>
<address>[Link]</address>
<mask>[Link]</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>[Link]</address>
<mask>[Link]</mask>
</primary>
</address>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
</Loopback>
<VirtualPortGroup>
<name>0</name>
<ip>
<address>
<primary>
<address>[Link]</address>
<mask>[Link]</mask>
</primary>
</address>
<nat xmlns="[Link]
<inside/>
</nat>
</ip>
<logging>
<event>
<link-status/>
</event>
</logging>
</VirtualPortGroup>
</interface>
<control-plane/>
<aaa>
<new-model xmlns="[Link]
<authentication xmlns="[Link]
<login>
<name>default</name>
<a1>
<local/>
</a1>
</login>
</authentication>
<authorization xmlns="[Link]
<exec>
<name>default</name>
<a1>
<local/>
</a1>
</exec>
</authorization>
<session-id xmlns="[Link]
</aaa>
<login>
<on-success>
<log/>
</on-success>
</login>
<multilink>
<bundle-name xmlns="[Link]
</multilink>
<redundancy/>
<subscriber>
<templating/>
</subscriber>
<ethernet>
<cfm xmlns="[Link]
<alarm>
<delay>2500</delay>
<reset>10000</reset>
</alarm>
</cfm>
</ethernet>
<crypto>
<ikev2 xmlns="[Link]
<http-url>
<cert/>
</http-url>
</ikev2>
<pki xmlns="[Link]
<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="[Link]
<bootup>
<level>minimal</level>
</bootup>
</diagnostic>
</native>
<netconf-yang xmlns="[Link]
<cisco-ia xmlns="[Link]
<snmp-trap-control>
<global-forwarding>true</global-forwarding>
</snmp-trap-control>
<snmp-community-string>private</snmp-community-string>
</cisco-ia>
</netconf-yang>
<licensing xmlns="[Link]
<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>[Link]</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>[Link]</ip>
<netmask>[Link]</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>[Link]</ip>
<netmask>[Link]</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>[Link]</ip>
<netmask>[Link]</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>[Link]</ip>
<netmask>[Link]</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>[Link]/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="[Link]
<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>[Link]/24</source-address>
<protocol xmlns:oc-acl-cisco="[Link]
-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>[Link]/32</destination-address>
<protocol xmlns:oc-acl-cisco="[Link]
-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="[Link]
<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="[Link]
<addresses>
<address>
<ip>[Link]</ip>
<config>
<ip>[Link]</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="[Link]
<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="[Link]
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="[Link]
<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="[Link]
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<config>
<enabled>false</enabled>
</config>
</ipv6>
</subinterface>
</subinterfaces>
<ethernet xmlns="[Link]
<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="[Link]
<addresses>
<address>
<ip>[Link]</ip>
<config>
<ip>[Link]</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<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="[Link]
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<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="[Link]
<addresses>
<address>
<ip>[Link]</ip>
<config>
<ip>[Link]</ip>
<prefix-length>24</prefix-length>
</config>
</address>
</addresses>
<proxy-arp>
<config>
<mode>ALL</mode>
</config>
</proxy-arp>
</ipv4>
<ipv6 xmlns="[Link]
<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="[Link]
<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="[Link]
<network-instance>
<name>default</name>
<config>
<name>default</name>
<type xmlns:oc-ni-types="[Link]
<description>default-vrf [read-only]</description>
</config>
<tables>
<table>
<protocol xmlns:oc-pol-types="[Link]
ol>
<address-family xmlns:oc-types="[Link]
<config>
<protocol xmlns:oc-pol-types="[Link]
</protocol>
<address-family xmlns:oc-types="[Link]
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="[Link]
ol>
<address-family xmlns:oc-types="[Link]
<config>
<protocol xmlns:oc-pol-types="[Link]
</protocol>
<address-family xmlns:oc-types="[Link]
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="[Link]
<address-family xmlns:oc-types="[Link]
<config>
<protocol xmlns:oc-pol-types="[Link]
<address-family xmlns:oc-types="[Link]
mily>
</config>
</table>
<table>
<protocol xmlns:oc-pol-types="[Link]
<address-family xmlns:oc-types="[Link]
<config>
<protocol xmlns:oc-pol-types="[Link]
<address-family xmlns:oc-types="[Link]
mily>
</config>
</table>
</tables>
<protocols>
<protocol>
<identifier xmlns:oc-pol-types="[Link]
<name>DEFAULT</name>
<config>
<identifier xmlns:oc-pol-types="[Link]
er>
<name>DEFAULT</name>
</config>
<static-routes>
<static>
<prefix>[Link]/0</prefix>
<config>
<prefix>[Link]/0</prefix>
</config>
<next-hops>
<next-hop>
<index>GigabitEthernet1_10.10.20.254</index>
<config>
<index>GigabitEthernet1_10.10.20.254</index>
<next-hop>[Link]</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="[Link]
tifier>
<name>DEFAULT</name>
<config>
<identifier xmlns:oc-pol-types="[Link]
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 = [Link](
host="[Link]",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)
netconf_reply = m.get_config(source='running')
netconf_data = [Link](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 = [Link](
host="[Link]",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)
filter = """
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="[Link]
<hostname></hostname>
<version></version>
</native>
</filter>
"""
netconf_reply = m.get_config(source='running', filter=filter)
netconf_data = [Link](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 = [Link](
host="[Link]",
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 [Link] as ET
from ncclient import manager
def save_running_config():
m = [Link](
host="[Link]",
port=830,
username="developer",
password="C1sco12345",
hostkey_verify=False
)
rpc_body = '''
<cisco-ia:save-config xmlns:cisco-ia="[Link]
'''
netconf_reply = [Link]([Link](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='[Link] running-config successful</result>
</rpc-reply>