How do I execute RPCs?

This document contains some examples of executing RPCs defined in yang. To perform these operations, the ExecutorService is used.

The below approach can be used to execute a rollback RPC.

Executing a rollback RPC

For this example, the Cisco_IOS_XR_cfgmgr_rollback_act.RollBackConfigurationLast class is used. Note that the ydk and ydk-models-cisco-ios-xr python packages need to be installed for this example.

 1# Import the rollback module
 2from ydk.models.cisco_ios_xr import Cisco_IOS_XR_cfgmgr_rollback_act
 3
 4# Import the executor service and netconf provider
 5from ydk.services import ExecutorService
 6from ydk.providers import NetconfServiceProvider
 7
 8# Create object
 9roll_back_configuration_to = Cisco_IOS_XR_cfgmgr_rollback_act.RollBackConfigurationLast()
10
11# Force roll back for the five most recent changes
12roll_back_configuration_to.input.comment = "Forced programmatic rollback"
13roll_back_configuration_to.input.count = 5
14roll_back_configuration_to.input.force = True
15roll_back_configuration_to.input.label = "PRB-005"
16
17# Create executor service
18executor = ExecutorService()
19
20# Create a NetconfServiceProvider instance to connect to the device
21provider = NetconfServiceProvider(address='10.0.0.1',
22                                     port=830,
23                                     username='test',
24                                     password='test')
25
26# Execute RPC on NETCONF device
27executor.execute_rpc(provider, roll_back_configuration_to)