cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
793
Views
0
Helpful
3
Replies
shgaiton
Cisco Employee

How to pass input parameters to request Action via python

Hi All,

I have a “reload” action to be triggered from my python code. The action expects two inputs as parameters:

+--ro actions
| | +---x reload
| | | +---w input
| | | | +---w force? empty
| | | | +---w noprompt? empty

am opening a maapi session and using the request_action_th API to do the job. My doubt is, how to pass the params args which expects ‘force’ and ‘noprompt’ to my reload leaf via python?

Also, both leaves force and prompt have types as empty so I am confused.

My code:

   th = maapi.start_trans(sock, _ncs.RUNNING, _ncs.READ_WRITE)
   path = '/ncs:devices/device{netconfd}/live-status/hw-module/oper/location{lc_loc}/actions'
   ns_hash = _ncs.str2hash("http://tail-f.com/ns/ncs")
   action_reload_hash = _ncs.str2hash('reload')
   action_force_hash = _ncs.str2hash('force')
   action_noprompt_hash = _ncs.str2hash('noprompt')
   params = []
   params += [_ncs.TagValue(_ncs.XmlTag(ns_hash, action_reload_hash), 
   _ncs.Value((action_reload_hash, ns_hash), _ncs.C_XMLBEGIN))]
   params += [_ncs.TagValue(ncs.XmlTag(ns_hash, action_force_hash), _ncs.Value(''))]
   params += [_ncs.TagValue(ncs.XmlTag(ns_hash, action_noprompt_hash), _ncs.Value(''))]
   params += [_ncs.TagValue(_ncs.XmlTag(ns_hash, 
   action_reload_hash),_ncs.Value((action_reload_hash, ns_hash), _ncs.C_XMLEND))]
   running = maapi.request_action_th(sock, th, params, path)

Thanks

3 REPLIES 3
lmanor
Cisco Employee

You need to use the action.get_input() and then fill out the input params.

 

Here is an example action call with input param:

In [6]: with ncs.maapi.Maapi() as m:

   ...:   with ncs.maapi.Session(m, 'admin', 'system'):

   ...:     with m.start_write_trans() as t:

   ...:         root = ncs.maagic.get_root(t)

   ...:         device = root.devices.device['asr-0']

   ...:         showCommand = device.live_status.cisco_ios_xr_stats__exec.any

   ...:         showInput = showCommand.get_input()

   ...:         showInput.args = ['show version']

   ...:         showResult = showCommand.request(showInput)

   ...:         print(showResult.result)

   ...:

 

Yang:

    tailf:action any {
      tailf:info "Execute any command on device";
      tailf:actionpoint ncsinternal {
        tailf:internal;
      }
      input {
        leaf-list args {
          tailf:cli-drop-node-name;
          tailf:cli-flat-list-syntax;
          type string {
            tailf:info "WORD;;any \"<cmd> [option(s)]\", e.g: any \"show ppp summary\"";
          }
        }
      }

Cisco IOS XR Software, NETSIM

asr-0#

 

And, yes, I believe setting your 'empty' type parameter to an empty string:

Input.force = ''

Input.noprompt = ''

Thanks for your reply. Tried your way. I dont see a get_input() attribute to my reload action as shown below, how to tackle this?


>>> dir(root.ncs__devices.device['netconfd'].live_status.calvados_hw_module__hw_module.oper.location["0/0"].actions.reload)
['__class__', '__delattr__', '__doc__', '__format__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__self_class__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__thisclass__']
>>>

A lot like you, dir() did not show get_input as an option, however when I tried it on my Action object it worked and I was able to continue and use Imanor's code to execute my action.  It may be too late to help you, but maybe I can help the next guy looking at this post.