<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NETCONF - YANG Capabilities Script on IOS XE in Code Exchange</title>
    <link>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4921259#M11</link>
    <description>&lt;P&gt;Hi, the port is 830, not 22 - either change it in the connect-call or leave it empty (as it's the default value):&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# CHANGE PORT TO 830
with manager.connect(
  host='10.254.199.199', # IP address of the XR device in your pod
  port=830, # Port to connect to
  username=USERNAME, # SSH Username
  password=PASSWORD, # SSH Password
  hostkey_verify=False # Allow unknown hostkeys not in local store
) as m:&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;# LEAVE PORT OUT (830=DEFAULT)
with manager.connect(
  host='10.254.199.199', # IP address of the XR device in your pod
  username=USERNAME, # SSH Username
  password=PASSWORD, # SSH Password
  hostkey_verify=False # Allow unknown hostkeys not in local store
) as m:&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 11 Sep 2023 06:10:01 GMT</pubDate>
    <dc:creator>Marcel Zehnder</dc:creator>
    <dc:date>2023-09-11T06:10:01Z</dc:date>
    <item>
      <title>NETCONF - YANG Capabilities Script on IOS XE</title>
      <link>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4921078#M8</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;When running the following code to retrieve YANG capabilities, I do receive the following errors:&lt;/P&gt;&lt;P&gt;DK_YANG.py", line 11, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with manager.connect(&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "/usr/local/lib/python3.8/dist-packages/ncclient/manager.py", line 176, in connect&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return connect_ssh(*args, **kwds)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "/usr/local/lib/python3.8/dist-packages/ncclient/manager.py", line 143, in connect_ssh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; session.connect(*args, **kwds)&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "/usr/local/lib/python3.8/dist-packages/ncclient/transport/ssh.py", line 401, in connect&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; self._post_connect()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "/usr/local/lib/python3.8/dist-packages/ncclient/transport/session.py", line 112, in _post_connect&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise SessionError("Capability exchange timed out")&lt;/P&gt;&lt;P&gt;ncclient.transport.errors.SessionError: Capability exchange timed out&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following is enabled on the IOS XE switch:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;netconf&lt;/STRONG&gt; &lt;STRONG&gt;ssh&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;netconf&lt;/STRONG&gt;&lt;STRONG&gt;-yang&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Based on logs, netconf session has been established.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PY Code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;import re&lt;BR /&gt;from ncclient import manager&lt;BR /&gt;import urllib3&lt;BR /&gt;from getpass import getpass&lt;/P&gt;&lt;P&gt;USERNAME = input("Enter your username:")&lt;BR /&gt;PASSWORD = getpass(prompt='Input your password: ') # the default prompt is 'Password&lt;/P&gt;&lt;P&gt;# Context manager keeping ncclient connection alive for the duration of&lt;BR /&gt;# the context.&lt;BR /&gt;with manager.connect(&lt;BR /&gt;host='10.254.199.199', # IP address of the XR device in your pod&lt;BR /&gt;port=22, # Port to connect to&lt;BR /&gt;username=USERNAME, # SSH Username&lt;BR /&gt;password=PASSWORD, # SSH Password&lt;BR /&gt;hostkey_verify=False # Allow unknown hostkeys not in local store&lt;BR /&gt;) as m: # Context manager reference, i.e. instance of connected manager&lt;BR /&gt;# The rest of your script code should go here.&lt;/P&gt;&lt;P&gt;capabilities = []&lt;BR /&gt;# Write each capability to console&lt;BR /&gt;for capability in m.server_capabilities:&lt;BR /&gt;# Print the capability&lt;BR /&gt;print("Capability: %s" % capability)&lt;BR /&gt;# Store the capability list for later.&lt;BR /&gt;capabilities.append(capability)&lt;/P&gt;&lt;P&gt;# Sort the list alphabetically.&lt;BR /&gt;capabilities = sorted(capabilities)&lt;BR /&gt;# List of modules that we store for use later&lt;BR /&gt;modules = []&lt;BR /&gt;# Iterate server capabilities and extract supported modules.&lt;BR /&gt;for capability in capabilities:&lt;BR /&gt;# Scan the capabilities and extract modules via this regex.&lt;BR /&gt;# i.e., if this was the capability string:&lt;BR /&gt;# &lt;A href="http://www.cisco.com/calvados/show_diag?module=show_diag&amp;amp;revision=2012-03-27" target="_blank"&gt;http://www.cisco.com/calvados/show_diag?module=show_diag&amp;amp;revision=2012-03-27&lt;/A&gt;&lt;BR /&gt;# then:&lt;BR /&gt;# show_diag&lt;BR /&gt;# .. would be the module printed.&lt;BR /&gt;# Scan capability string for module&lt;BR /&gt;supported_model = re.search('module=(.*)&amp;amp;', capability)&lt;BR /&gt;# If module found in string, store it.&lt;BR /&gt;if supported_model is not None:&lt;BR /&gt;# Module string was found, store it.&lt;BR /&gt;print("Supported Model: %s" % supported_model.group(1))&lt;BR /&gt;# Store the module for later use.&lt;BR /&gt;modules.append(supported_model.groups(0)[0])&lt;/P&gt;&lt;P&gt;# List of models that we want to download.&lt;BR /&gt;# We will get the schema for each and write it to disk.&lt;BR /&gt;models_desired = ['openconfig-extensions', 'openconfig-interfaces']&lt;BR /&gt;# Iterate each desired model and write it to ./lab/models/&lt;BR /&gt;for model in models_desired:&lt;BR /&gt;# Get the model schema.&lt;BR /&gt;schema = m.get_schema(model)&lt;BR /&gt;# Open new file handle.&lt;BR /&gt;with open("./{}.yang".format(model), 'w') as f:&lt;BR /&gt;# Write schema&lt;BR /&gt;f.write(schema.data)&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 01:38:11 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4921078#M8</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2023-09-11T01:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: NETCONF - YANG Capabilities Script on IOS XE</title>
      <link>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4921259#M11</link>
      <description>&lt;P&gt;Hi, the port is 830, not 22 - either change it in the connect-call or leave it empty (as it's the default value):&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# CHANGE PORT TO 830
with manager.connect(
  host='10.254.199.199', # IP address of the XR device in your pod
  port=830, # Port to connect to
  username=USERNAME, # SSH Username
  password=PASSWORD, # SSH Password
  hostkey_verify=False # Allow unknown hostkeys not in local store
) as m:&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;# LEAVE PORT OUT (830=DEFAULT)
with manager.connect(
  host='10.254.199.199', # IP address of the XR device in your pod
  username=USERNAME, # SSH Username
  password=PASSWORD, # SSH Password
  hostkey_verify=False # Allow unknown hostkeys not in local store
) as m:&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Sep 2023 06:10:01 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4921259#M11</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-09-11T06:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: NETCONF - YANG Capabilities Script on IOS XE</title>
      <link>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4922211#M14</link>
      <description>&lt;P&gt;Thank Marcel.&lt;/P&gt;&lt;P&gt;Should it work when I add in Cisco IOS XE config the following at global config level:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;netconf&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;ssh&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Netmart&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 17:29:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4922211#M14</guid>
      <dc:creator>Netmart</dc:creator>
      <dc:date>2023-09-12T17:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: NETCONF - YANG Capabilities Script on IOS XE</title>
      <link>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4922216#M16</link>
      <description>&lt;P&gt;On IOS-XE you just need to configure &lt;STRONG&gt;&lt;EM&gt;netconf-yang&lt;/EM&gt;&lt;/STRONG&gt; + a level 15 user (local or via AAA), see&amp;nbsp;&lt;A href="https://developer.cisco.com/docs/ios-xe/#!enabling-netconf-on-ios-xe" target="_blank"&gt;https://developer.cisco.com/docs/ios-xe/#!enabling-netconf-on-ios-xe&lt;/A&gt;&amp;nbsp;for details.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 17:42:07 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/netconf-yang-capabilities-script-on-ios-xe/m-p/4922216#M16</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-09-12T17:42:07Z</dc:date>
    </item>
  </channel>
</rss>

