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 RollBackConfigurationLast struct is used. Note that the ydk and cisco_ios_xr go packages need to be installed for this example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main

// Import the rollback module, executor service, and netconf provider
import (
    "fmt"
    "github.com/CiscoDevNet/ydk-go/ydk/models/cisco_ios_xr/cfgmgr_rollback_act"
    "github.com/CiscoDevNet/ydk-go/ydk/providers"
    "github.com/CiscoDevNet/ydk-go/ydk/services"
)

// execute main program
func main() {
    // Create object
    rollBackConfigTo := cfgmgr_rollback_act.RollBackConfigurationLast{}

    // Force roll back for the five most recent changes
    rollBackConfigTo.Input.Comment = "Forced programmatic rollback"
    rollBackConfigTo.Input.Count = 5
    rollBackConfigTo.Input.Force = true
    rollBackConfigTo.Input.Label = "PRB-005"

    // Create the executor service
    executor := services.ExecutorService{}

    // Create a NetconfServiceProvider instance to connect to the device
    provider := providers.NetconfServiceProvider{
        Address: "10.0.0.1",
        Username: "test",
        Password: "test",
        Port: 830,
        Protocol: "ssh"}
    provider.Connect()

    // Execute RPC on NETCONF device
    executor.ExecuteRpc(&provider, &rollBackConfigTo)
}