cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1145
Views
3
Helpful
4
Replies

I need help on automating openconfig-vlan.yang module

balamani
Level 1
Level 1

Hi,

I am trying to automate "openconfig-vlan.yang" module using YDK. But i am getting error.

Below is the Script and command i used to run script "python test_vlan_config.py ssh://admin:admin@1.1.1.1:11111":

But similar script worked for cisco_ios_xr "Cisco_IOS_XR_cdp_cfg" module. for this module able create, read, write and delete.

from ydk.services import CRUDService

from ydk.providers import NetconfServiceProvider

from ydk.models.openconfig import openconfig_vlan

import logging

from argparse import ArgumentParser

from urlparse import urlparse

def config_vlan(vlan_conf):

  vlan_conf.name = "VLAN100"
   vlan_conf.status = "ACTIVE"
   vlan_conf.vlan_id = 1555
   print("*****************After Setting************")

   print(vlan_conf.name)

   print(vlan_conf.status)

   print(vlan_conf.vlan_id)

   print(vlan_conf)


def test1_vlans_func():

   if __name__ == "__main__":

   """Execute main program."""
   parser = ArgumentParser()

  parser.add_argument("-v", "--verbose", help="print debugging messages",

   action="store_true")

  parser.add_argument("device",

   help="NETCONF device (ssh://user:password@host:port)")

  args = parser.parse_args()

   device = urlparse(args.device)

   # log debug messages if verbose argument specified
   if args.verbose:

  logger = logging.getLogger("ydk")

  logger.setLevel(logging.DEBUG)

  handler = logging.StreamHandler()

  formatter = logging.Formatter(("%(asctime)s - %(name)s - "
  "%(levelname)s - %(message)s"))

  handler.setFormatter(formatter)

  logger.addHandler(handler)

   # create NETCONF session
   provider = NetconfServiceProvider(address="1.1.1.1",

   port=11111,

   username="admin",

   password="admin",

   protocol="ssh")

   # create CRUD service
   crud = CRUDService()

   # create vlnas configobject
   vlan_conf = openconfig_vlan.Vlans.Vlan.Config()

   print("###Before setting####")

   print(vlan_conf)

   # print system uptime
   config_vlan(vlan_conf)

   print("####After returning from the function#######")

   print(vlan_conf)

   # create CRUD service
   crud.create(provider, vlan_conf)

   print("####After creating crud service#######")

   print(vlan_conf)

   # close NETCONF session and exit
   provider.close()

   exit()

   # End of script

test1_vlans_func()

Error Output:

###Before setting####

<ydk.models.openconfig.openconfig_vlan.Config object at 0x7fa1fa508590>

*****************After Setting************

VLAN100

ACTIVE

1555

<ydk.models.openconfig.openconfig_vlan.Config object at 0x7fa1fa508590>

####After returning from the function#######

<ydk.models.openconfig.openconfig_vlan.Config object at 0x7fa1fa508590>

Traceback (most recent call last):

  File "test_vlan_config.py", line 90, in <module>

    test1_vlans_func()

  File "test_vlan_config.py", line 81, in test1_vlans_func

    crud.create(provider, vlan_conf)

  File "/usr/local/lib/python2.7/dist-packages/ydk/services/crud_service.py", line 62, in create

    self._execute_crud_operation_on_provider(provider, entity, 'CREATE', False)

  File "/usr/local/lib/python2.7/dist-packages/ydk/services/crud_service.py", line 166, in _execute_crud_operation_on_provider

    only_config

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/netconf_provider.py", line 88, in encode

    return self.sp_instance.encode(entity, operation, only_config)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 112, in encode

    root = self._encode_edit_request(root, entity, operation)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 432, in _encode_edit_request

    root = self._create_preamble(entity, root)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 494, in _create_preamble

    parent_meta_tuple_list = self._get_parent_tuple_list(entity, entity._meta_info())

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 590, in _get_parent_tuple_list

    self._raise_parent_hierarchy_error()

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 520, in _raise_parent_hierarchy_error

    raise YPYServiceProviderError(error_code=YPYErrorCode.INVALID_HIERARCHY_PARENT)

ydk.errors.YPYServiceProviderError: Parent is not set.                     Parent Hierarchy cannot be determined

I am completely new to YDK and data model automation. also I don't understand in detail about create and delete operation. Please help me on this.

Below are the details of YDK.

vagrant@ydk-py:test_openconfig_vlan$ pip list | grep ydk

ydk                     0.5.4

ydk-models-cisco-ios-xr 6.2.1

ydk-models-ietf         0.1.1

ydk-models-openconfig   0.1.2

vagrant@ydk-py:test_openconfig_vlan$

Thanks & Regards,

Basavaraj

Message was edited by: Basavaraj Lamani

Message was edited by: Basavaraj Lamani

1 Accepted Solution

Accepted Solutions

Basavaraj,

You also need to consider the content of the file cisco-xr-openconfig-vlan-deviations.yang when determining exactly what is supported:

https://github.com/YangModels/yang/blob/master/vendor/cisco/xr/622/cisco-xr-openconfig-vlan-deviations.yang

Cheers,

Einar

View solution in original post

4 Replies 4

balamani
Level 1
Level 1

I modified the script and now i am getting different error. Please help.


from ydk.services import CRUDService

from ydk.providers import NetconfServiceProvider

from ydk.models.openconfig import openconfig_vlan

import logging

from argparse import ArgumentParser

from urlparse import urlparse

def config_vlan(vlan_conf):

  vlan_conf.Vlan.Config.name = "VLAN100"
   vlan_conf.Vlan.Config.status = "ACTIVE"
   vlan_conf.Vlan.Config.vlan_id = 1555
   print("*****************After Setting************")

   print(vlan_conf.Vlan.Config.name)

   print(vlan_conf.Vlan.Config.status)

   print(vlan_conf.Vlan.Config.vlan_id)

   print(vlan_conf)

def test1_vlans_func():

   if __name__ == "__main__":

   """Execute main program."""
   parser = ArgumentParser()

  parser.add_argument("-v", "--verbose", help="print debugging messages",

   action="store_true")

  parser.add_argument("device",

   help="NETCONF device (ssh://user:password@host:port)")

  args = parser.parse_args()

   device = urlparse(args.device)

   # log debug messages if verbose argument specified
   if args.verbose:

  logger = logging.getLogger("ydk")

  logger.setLevel(logging.DEBUG)

  handler = logging.StreamHandler()

  formatter = logging.Formatter(("%(asctime)s - %(name)s - "
  "%(levelname)s - %(message)s"))

  handler.setFormatter(formatter)

  logger.addHandler(handler)

   # create NETCONF session
   provider = NetconfServiceProvider(address="1.1.1.1",

   port=11111,

   username="admin",

   password="admin",

   protocol="ssh")

   # create CRUD service
   crud = CRUDService()

   # create vlnas configobject
  #vlan_conf = openconfig_vlan.Vlans.Vlan.Config()
   vlan_conf = openconfig_vlan.Vlans()

   print("###Before setting####")

   print(vlan_conf)

   # print system uptime
   config_vlan(vlan_conf)

   print("####After returning from the function#######")

   print(vlan_conf)

   # create CRUD service
   crud.create(provider, vlan_conf)

   print("####After creating crud service#######")

   print(vlan_conf)

   # close NETCONF session and exit
   provider.close()

   exit()

   # End of script

test1_vlans_func()

########error output###:

vagrant@ydk-py:test_openconfig_vlan$ python test_vlan_config.py ssh://admin:admin@1.1.1.1:11111 -v

2017-08-18 05:25:51,013 - ydk.providers.netconf_provider - INFO - NetconfServiceProvider connected to 10.85.104.17:20083 using ssh

###Before setting####

<ydk.models.openconfig.openconfig_vlan.Vlans object at 0x7f71a1726650>

*****************After Setting************

VLAN100

ACTIVE

1555

<ydk.models.openconfig.openconfig_vlan.Vlans object at 0x7f71a1726650>

####After returning from the function#######

<ydk.models.openconfig.openconfig_vlan.Vlans object at 0x7f71a1726650>

2017-08-18 05:25:51,020 - ydk.services.crud_service - INFO - CREATE operation initiated

2017-08-18 05:25:51,022 - ydk.providers._provider_plugin - DEBUG -

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:2021e2b8-5342-49ab-8321-56d5a84dbb64">

  <edit-config>

    <target>

      <candidate/>

    </target>

    <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

      <vlans xmlns="http://openconfig.net/yang/vlan"/>

    </config>

  </edit-config>

</rpc>

2017-08-18 05:25:51,449 - ydk.providers._provider_plugin - DEBUG -

<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:2021e2b8-5342-49ab-8321-56d5a84dbb64">

  <rpc-error>

    <error-type>protocol</error-type>

    <error-tag>unknown-namespace</error-tag>

    <error-severity>error</error-severity>

    <error-info>

      <bad-element>vlans</bad-element>

      <bad-namespace>http://openconfig.net/yang/vlan</bad-namespace>

    </error-info>

  </rpc-error>

</rpc-reply>

2017-08-18 05:25:51,453 - ydk.providers._provider_plugin - ERROR -

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:2021e2b8-5342-49ab-8321-56d5a84dbb64">

  <edit-config>

    <target>

      <candidate/>

    </target>

    <config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

      <vlans xmlns="http://openconfig.net/yang/vlan"/>

    </config>

  </edit-config>

</rpc>

<?xml version="1.0"?>

<rpc-reply message-id="urn:uuid:2021e2b8-5342-49ab-8321-56d5a84dbb64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">

<rpc-error>

  <error-type>protocol</error-type>

  <error-tag>unknown-namespace</error-tag>

  <error-severity>error</error-severity>

  <error-info>

   <bad-element>vlans</bad-element>

   <bad-namespace>http://openconfig.net/yang/vlan</bad-namespace>

  </error-info>

</rpc-error>

</rpc-reply>

2017-08-18 05:25:51,456 - ydk.services.crud_service - INFO - CREATE operation completed

Traceback (most recent call last):

  File "test_vlan_config.py", line 91, in <module>

    test1_vlans_func()

  File "test_vlan_config.py", line 82, in test1_vlans_func

    crud.create(provider, vlan_conf)

  File "/usr/local/lib/python2.7/dist-packages/ydk/services/crud_service.py", line 62, in create

    self._execute_crud_operation_on_provider(provider, entity, 'CREATE', False)

  File "/usr/local/lib/python2.7/dist-packages/ydk/services/crud_service.py", line 168, in _execute_crud_operation_on_provider

    operation

  File "/usr/local/lib/python2.7/dist-packages/ydk/services/service.py", line 36, in execute_payload

    reply = provider.execute(payload, operation)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/netconf_provider.py", line 94, in execute

    return self.sp_instance.execute_operation(payload, operation)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 224, in execute_operation

    return self._handle_rpc_reply(operation, payload, reply.xml)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 246, in _handle_rpc_reply

    self._handle_rpc_error(payload, reply_str, pathlist)

  File "/usr/local/lib/python2.7/dist-packages/ydk/providers/_provider_plugin.py", line 259, in _handle_rpc_error

    raise YPYServiceProviderError(error_code=YPYErrorCode.SERVER_REJ, error_msg=reply_str)

ydk.errors.YPYServiceProviderError: Server rejected request.

        error-type: protocol

        error-tag: unknown-namespace

        error-severity: error

        bad-element: vlans

        bad-namespace: http://openconfig.net/yang/vlan

vagrant@ydk-py:test_openconfig_vlan$

From the first error, looks like there was an issue with your script as you were not correctly populating the list. Can you try something like the below?

def config_vlan(vlan_conf):

  vlan = openconfig_vlan.Vlan()

  vlan.vlan_id = 1555

  vlan.config.vlan_id = 1555

  vlan.config.name = "VLAN100"

  vlan.config.status = "ACTIVE"

  vlans.vlan.append(vlan)

# create vlans configobject

vlan_conf = openconfig_vlan.Vlans()

config_vlan(vlan_conf)

For the second error, looks like the device you are connecting to does not support the openconfig-vlan model.

Hi Abhirame,

Thanks for your input.

As per your suggestion i made changes but still i am getting 2nd error.

Also i checked in router whether "openconfig-vlan.yang" module supported or not by giving below commands on router.

1) "run" command

2) "cd /pkg/yang" command. This command lists all the available modules and i can see "openconfig-vlan.yang" module.


Please let me know is this correct procedure to check supported modules on router. Also let me know if i need to make any further changes in my script.

Basavaraj,

You also need to consider the content of the file cisco-xr-openconfig-vlan-deviations.yang when determining exactly what is supported:

https://github.com/YangModels/yang/blob/master/vendor/cisco/xr/622/cisco-xr-openconfig-vlan-deviations.yang

Cheers,

Einar