cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1110
Views
2
Helpful
4
Replies

Using the Executor service

saalvare
Cisco Employee
Cisco Employee

YANG models not only define configuration and operational data.  They also define remote procedure calls or commands.  Cisco IOS XR 6.1.2 starts introducing models for those RPCs or commands.  Those models define how to roll back config, test SNMP traps or generate custom syslog messages.  An RPC model specifies whether the RPC takes input data and whether it produces output data. 

In YDK 0.5.1, we introduced the Executor service which allows you to execute RPCs. This service supports a single operation (execute_rpc) and is currently documented at:

http://ydk.cisco.com/py/docs/ydk.services.html#executorservice-provides-api-to-execute-rpcs

Watch the ydk-py-samples repository for a series of upcoming sample apps that execute RPCs.  Stay tuned!

4 Replies 4

ttdo
Level 1
Level 1

Hi Santiago,

I am trying to use Python Executor service, but I got this error.

Do you know if execute_rpc method support ing 0.6.1 release ?

Thanks

-Thang

===========================================================

  File "./lum.py", line 31, in exec_rpc

    inst.execute_rpc(session, rpc)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/services/executor_service.py", line 32, in execute_rpc

    return self._es.execute_rpc(provider, entity, top_entity)

  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__

    self.gen.throw(type, value, traceback)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error

    _raise(_exc)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/errors/error_handler.py", line 56, in _raise

    raise exc

ydk.errors.YPYError: Unable to cast Python instance to C++ type (compile in debug mode for details)

abhirame
Cisco Employee
Cisco Employee

Hi Thang,

Can you please post your script and complete logs?

Thanks,

Abhi

Hi Abhi,

Here is my script

=================

from __future__ import print_function

from __future__ import absolute_import

from ydk.types import Empty

from ydk.services import CRUDService

from ydk.services import ExecutorService

import logging

from session_mgr import establish_session, init_logging

from ydk.models.lumentum.ietf_netconf import Get, GetConfig

from ydk.errors import YPYError

def srv_run(crud_service, session):

    # GET

    service = ExecutorService()

    conf = GetConfig()

    service.execute_rpc(service, session, conf)

   

if __name__ == "__main__":

    init_logging()

    provider = establish_session()

    crud_service = CRUDService()

    srv_run(crud_service, provider)

    exit()

==============

And the log

tdo@ubuntu:~/ydk-gen/gen-api/python$ ./exec.py -u thang -p mypassword --host 10.100.211.201

Establishing connection with device 10.100.211.201:830 using ssh :

Path where models are to be downloaded: /home/tdo/.ydk/10.100.211.201:830

Connected to 10.100.211.201 on port 830 using ssh with timeout of -1

Connected to 10.100.211.201 on port 830 using ssh with timeout of -1

connection established...

Traceback (most recent call last):

  File "./exec.py", line 38, in <module>

    srv_run(crud_service, provider)

  File "./exec.py", line 31, in srv_run

    service.execute_rpc(service, session, conf)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/services/executor_service.py", line 32, in execute_rpc

    return self._es.execute_rpc(provider, entity, top_entity)

  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__

    self.gen.throw(type, value, traceback)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error

    _raise(_exc)

  File "/home/tdo/.local/lib/python2.7/site-packages/ydk/errors/error_handler.py", line 56, in _raise

    raise exc

ydk.errors.YPYServiceError:  incompatible function arguments. The following argument types are supported:

    1. (self: ydk_.services.ExecutorService, provider: ydk_.providers.ServiceProvider, entity: ydk_.types.Entity, top_entity: ydk_.types.Entity=None) -> ydk_.types.Entity

Invoked with: <ydk_.services.ExecutorService object at 0x7f834a9ca0a0>, <ydk.services.executor_service.ExecutorService object at 0x7f834a9dc5f0>, <ydk_.providers.NetconfServiceProvider object at 0x7f834a9ca570>, <ydk.models.lumentum.ietf_netconf.GetConfig object at 0x7f834a9dc9b0>

Disconnected from device

Disconnected from device

abhirame
Cisco Employee
Cisco Employee

Hi Thang,

As the error says, the arguments used for execute_rpc() function are wrong. Try the below :

service.execute_rpc(service, session, conf)

If you are interested in using netconf RPCs like get-config, you could look at netconf service. See an example here.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: