<?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 Issue creating Sample Loopback Interface Script Using OpenConfig!! in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/issue-creating-sample-loopback-interface-script-using-openconfig/m-p/4010200#M2536</link>
    <description>&lt;P&gt;I am trying to create and run the openconfig script which is shown as a sample in DevNet tutorial&amp;nbsp;&lt;SPAN&gt;NETCONF/YANG on Nexus Part 3: Using OpenConfig YANG Models on Nexus Switches&lt;/SPAN&gt;. The file as an example is add_oc_loopback.py.&amp;nbsp;&lt;BR /&gt;The file contents are :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/env python

from ncclient import manager
import sys
from lxml import etree

# Add parent directory to path to allow importing common vars
sys.path.append("..") # noqa
from device_info import sbx_n9kv_ao as device # noqa

# Loopback Info - Change the details for your interface
loopback = {"id": "98", "ip": "10.98.98.1", "prefix": "24"}

# create a main() method
def main():
    """
    Main method that adds loopback interfaces
    """

    add_oc_interface = """&amp;lt;config&amp;gt;
    &amp;lt;interfaces xmlns="http://openconfig.net/yang/interfaces"&amp;gt;
        &amp;lt;interface&amp;gt;
            &amp;lt;name&amp;gt;lo{id}&amp;lt;/name&amp;gt;
            &amp;lt;config&amp;gt;
                &amp;lt;description&amp;gt; Configured using OpenConfig Model &amp;lt;/description&amp;gt;
                &amp;lt;name&amp;gt;lo{id}&amp;lt;/name&amp;gt;
                &amp;lt;type&amp;gt;ianaift:softwareLoopback&amp;lt;/type&amp;gt;
            &amp;lt;/config&amp;gt;
            &amp;lt;subinterfaces&amp;gt;
                &amp;lt;subinterface&amp;gt;
                    &amp;lt;index&amp;gt;0&amp;lt;/index&amp;gt;
                    &amp;lt;ipv4&amp;gt;
                        &amp;lt;addresses&amp;gt;
                            &amp;lt;address&amp;gt;
                                &amp;lt;config&amp;gt;
                                    &amp;lt;ip&amp;gt;{ip}&amp;lt;/ip&amp;gt;
                                    &amp;lt;prefix-length&amp;gt;{prefix}&amp;lt;/prefix-length&amp;gt;
                                &amp;lt;/config&amp;gt;
                                &amp;lt;ip&amp;gt;{ip}&amp;lt;/ip&amp;gt;
                            &amp;lt;/address&amp;gt;
                        &amp;lt;/addresses&amp;gt;
                    &amp;lt;/ipv4&amp;gt;
                &amp;lt;/subinterface&amp;gt;
            &amp;lt;/subinterfaces&amp;gt;
        &amp;lt;/interface&amp;gt;
    &amp;lt;/interfaces&amp;gt;
    &amp;lt;/config&amp;gt;""".format(id = loopback["id"], ip = loopback["ip"], prefix = loopback["prefix"])

    # print(add_oc_interface)

    with manager.connect(host = device["address"],
                         port = device["netconf_port"],
                         username = device["username"],
                         password = device["password"],
                         hostkey_verify = False) as m:

        # Add the loopback interface IP
        print("\nNow adding IP address {} to interface lo{} on device {}...\n".format(loopback["ip"],
                                                                                      loopback["id"],
                                                                                      device["address"]))

        netconf_response = m.edit_config(target='running', config=add_oc_interface)
        # Parse the XML response
        print(netconf_response)

if __name__ == '__main__':
    sys.exit(main())&lt;/PRE&gt;&lt;P&gt;Could not attach it as it was saying&amp;nbsp;&lt;/P&gt;&lt;P class="lia-form-error-text"&gt;The contents of the attachment doesn't match its file type.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The error I get after changing the parameters to my switch IP, user,pwd , etc. is :&lt;/P&gt;&lt;PRE&gt;Element 'config': This element is not expected. Expected is one of ( {urn:ietf:params:xml:ns:netconf:base:1.0}default-operation, {urn:ietf:params:xml:ns:netconf:base:1.0}test-option, {urn:ietf:params:xml:ns:netconf:base:1.0}error-option, {urn:ietf:params:&lt;/PRE&gt;&lt;P&gt;I changed to include&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;rpc message-id="101"
          xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"&amp;gt;
         &amp;lt;edit-config&amp;gt;
         &amp;lt;target&amp;gt;
           &amp;lt;running/&amp;gt;
         &amp;lt;/target&amp;gt;&lt;/PRE&gt;&lt;P&gt;However, I get another error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;Element [{urn:ietf:params:xml:ns:netconf:base:1.0}rpc] does not meet requirement&lt;/PRE&gt;&lt;P&gt;Please help or advise!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 01:45:15 GMT</pubDate>
    <dc:creator>sindhujit</dc:creator>
    <dc:date>2020-01-13T01:45:15Z</dc:date>
    <item>
      <title>Issue creating Sample Loopback Interface Script Using OpenConfig!!</title>
      <link>https://community.cisco.com/t5/controllers/issue-creating-sample-loopback-interface-script-using-openconfig/m-p/4010200#M2536</link>
      <description>&lt;P&gt;I am trying to create and run the openconfig script which is shown as a sample in DevNet tutorial&amp;nbsp;&lt;SPAN&gt;NETCONF/YANG on Nexus Part 3: Using OpenConfig YANG Models on Nexus Switches&lt;/SPAN&gt;. The file as an example is add_oc_loopback.py.&amp;nbsp;&lt;BR /&gt;The file contents are :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/env python

from ncclient import manager
import sys
from lxml import etree

# Add parent directory to path to allow importing common vars
sys.path.append("..") # noqa
from device_info import sbx_n9kv_ao as device # noqa

# Loopback Info - Change the details for your interface
loopback = {"id": "98", "ip": "10.98.98.1", "prefix": "24"}

# create a main() method
def main():
    """
    Main method that adds loopback interfaces
    """

    add_oc_interface = """&amp;lt;config&amp;gt;
    &amp;lt;interfaces xmlns="http://openconfig.net/yang/interfaces"&amp;gt;
        &amp;lt;interface&amp;gt;
            &amp;lt;name&amp;gt;lo{id}&amp;lt;/name&amp;gt;
            &amp;lt;config&amp;gt;
                &amp;lt;description&amp;gt; Configured using OpenConfig Model &amp;lt;/description&amp;gt;
                &amp;lt;name&amp;gt;lo{id}&amp;lt;/name&amp;gt;
                &amp;lt;type&amp;gt;ianaift:softwareLoopback&amp;lt;/type&amp;gt;
            &amp;lt;/config&amp;gt;
            &amp;lt;subinterfaces&amp;gt;
                &amp;lt;subinterface&amp;gt;
                    &amp;lt;index&amp;gt;0&amp;lt;/index&amp;gt;
                    &amp;lt;ipv4&amp;gt;
                        &amp;lt;addresses&amp;gt;
                            &amp;lt;address&amp;gt;
                                &amp;lt;config&amp;gt;
                                    &amp;lt;ip&amp;gt;{ip}&amp;lt;/ip&amp;gt;
                                    &amp;lt;prefix-length&amp;gt;{prefix}&amp;lt;/prefix-length&amp;gt;
                                &amp;lt;/config&amp;gt;
                                &amp;lt;ip&amp;gt;{ip}&amp;lt;/ip&amp;gt;
                            &amp;lt;/address&amp;gt;
                        &amp;lt;/addresses&amp;gt;
                    &amp;lt;/ipv4&amp;gt;
                &amp;lt;/subinterface&amp;gt;
            &amp;lt;/subinterfaces&amp;gt;
        &amp;lt;/interface&amp;gt;
    &amp;lt;/interfaces&amp;gt;
    &amp;lt;/config&amp;gt;""".format(id = loopback["id"], ip = loopback["ip"], prefix = loopback["prefix"])

    # print(add_oc_interface)

    with manager.connect(host = device["address"],
                         port = device["netconf_port"],
                         username = device["username"],
                         password = device["password"],
                         hostkey_verify = False) as m:

        # Add the loopback interface IP
        print("\nNow adding IP address {} to interface lo{} on device {}...\n".format(loopback["ip"],
                                                                                      loopback["id"],
                                                                                      device["address"]))

        netconf_response = m.edit_config(target='running', config=add_oc_interface)
        # Parse the XML response
        print(netconf_response)

if __name__ == '__main__':
    sys.exit(main())&lt;/PRE&gt;&lt;P&gt;Could not attach it as it was saying&amp;nbsp;&lt;/P&gt;&lt;P class="lia-form-error-text"&gt;The contents of the attachment doesn't match its file type.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The error I get after changing the parameters to my switch IP, user,pwd , etc. is :&lt;/P&gt;&lt;PRE&gt;Element 'config': This element is not expected. Expected is one of ( {urn:ietf:params:xml:ns:netconf:base:1.0}default-operation, {urn:ietf:params:xml:ns:netconf:base:1.0}test-option, {urn:ietf:params:xml:ns:netconf:base:1.0}error-option, {urn:ietf:params:&lt;/PRE&gt;&lt;P&gt;I changed to include&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;rpc message-id="101"
          xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"&amp;gt;
         &amp;lt;edit-config&amp;gt;
         &amp;lt;target&amp;gt;
           &amp;lt;running/&amp;gt;
         &amp;lt;/target&amp;gt;&lt;/PRE&gt;&lt;P&gt;However, I get another error:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;Element [{urn:ietf:params:xml:ns:netconf:base:1.0}rpc] does not meet requirement&lt;/PRE&gt;&lt;P&gt;Please help or advise!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 01:45:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/issue-creating-sample-loopback-interface-script-using-openconfig/m-p/4010200#M2536</guid>
      <dc:creator>sindhujit</dc:creator>
      <dc:date>2020-01-13T01:45:15Z</dc:date>
    </item>
  </channel>
</rss>

