cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
317
Views
1
Helpful
7
Replies
Highlighted
Cisco Employee

Yang action example for live-status

 

Hi,

 

 

Can someone please provide me an example of using Yang Actions or non-config Yang statement to issue a

 

Live-status exec command? I’d like to create a service of exec commands that are relevant to the specific configuration checks of the service.

 

I searched the 4.1 docs for “actions” but came up empty on finding any examples.

 

 

I can issue the exec commands within the CLI as follows:

 

 

admin@ncs(config)# devices device vpc-si-ned-cli live-status staros-stats:exec show support detail to file /flash/test3ssd.tar

 

result

 

********************************************************************************

 

Transferred 5587968 bytes in 0.051 seconds (107000.0 KB/sec)

 

[local]VPC-SI-SAEGW#

 

admin@ncs(config)#

 

 

 

Thanks, JA

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Cisco Employee

 

Here is a pure YANG example to get the content of any file, no code is needed:

 

 

container getfile-action {

 

tailf:action getfile {

 

tailf:exec '/bin/cat' {

 

tailf:args ' ';

 

}

 

input {

 

leaf filename {

 

type string;

 

}

 

}

 

output {

 

leaf filename {

 

type string;

 

}

 

}

 

}

 

}

 



  

 

curl -X POST --header 'Content-Type: application/vnd.yang.operation+json' --header 'Accept: text/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
  "input": {
    "filename": "/path/of/file.txt"
  }
}' 'http://127.0.0.1:8080/api/running/getfile-action/_operations/getfile'

 

 

 

View solution in original post

7 REPLIES 7
Highlighted
Cisco Employee

 

Hi Julie,

 

here’s one I coded to create a full mesh of pings for a modified l3vpn demo.

 

 

Cheers

 

Stefano

 

Highlighted
Cisco Employee

 

Thanks,

 

 

I was hoping for a non-java example = is this feasible?

 

 

JA

 

Highlighted
Cisco Employee

 

Yes, you can use python. There is an example in the dev guide.

 

 

Roque

 

Highlighted
Cisco Employee

 

Ok – let me rephrase the question:

 

 

Can I create a Yang Action to issue a NED Exec command directly without writing any java or python code? I.e. can this all be done within Yang?

 

 

Thanks, JA

 

Highlighted
Cisco Employee

 

Hi,

 

 

You can run an action using tailf:exec and point that to a bash scripts that calls the exec command using NSO CLI.

 

 

This is, of course, very fragile.

 

 

Roque

 

Highlighted
Cisco Employee

 

Here is a pure YANG example to get the content of any file, no code is needed:

 

 

container getfile-action {

 

tailf:action getfile {

 

tailf:exec '/bin/cat' {

 

tailf:args ' ';

 

}

 

input {

 

leaf filename {

 

type string;

 

}

 

}

 

output {

 

leaf filename {

 

type string;

 

}

 

}

 

}

 

}

 



  

 

curl -X POST --header 'Content-Type: application/vnd.yang.operation+json' --header 'Accept: text/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
  "input": {
    "filename": "/path/of/file.txt"
  }
}' 'http://127.0.0.1:8080/api/running/getfile-action/_operations/getfile'

 

 

 

View solution in original post

Highlighted
Cisco Employee

 

Hi!

 

 

Maybe not exactly what you want but I threw something together during the flight home from Pretoria.

 

 

Attached is a python action that can run ping and show commands on devices of you selection. It can handle cisco-ios,cisco-iosxr and alu-sr devices.

 

 

Below I augmented it to mpls-vpn example and used a template called from the l3vpn service to create two actions, pinglocalhost and showVrf.

 

Not admin@ncs% show vpn l3vpn action
l3vpn volvo {
    action {
        settings {
            commands pinglocalhost {
                devices   [ ce0 ce1 ce6 ];
                command   ping;
                arguments 127.0.0.1;
            }
            commands showVrf {
                devices   [ ce0 ce1 ce6 ];
                command   show;
                arguments "ip route vrf volvo";
            }
        }
    }
}

admin@ncs% request vpn l3vpn volvo action execute command pinglocalhost
result
output from ping
device: ce0

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 127.0.0.1, timeout is 2 seconds:

.....

Success rate is 0 percent (0/5)

ce0#

 

You can use a template in your service to add the actions on to itself. The below would add the two examples at the top.

 

   <vpn xmlns="http://com/example/l3vpn">

      <l3vpn>

        <name>{/name}</name>

          <action xmlns="http://example.com/action">

            <settings>

              <commands>

                <name>pinglocalhost</name>

                <devices>{/endpoint/ce-device}</devices>

                <command>ping</command>

                <arguments>127.0.0.1</arguments>

              </commands>

              <commands>

                <name>showVrf</name>

                <devices>{/endpoint/ce-device}</devices>

                <command>show</command>

                <arguments>ip route vrf {/name}</arguments>

              </commands>

            </settings>

          </action>

      </l3vpn>

      </vpn>

 

--
Håkan Niska

This widget could not be displayed.