07-09-2020 07:07 AM - edited 07-09-2020 09:43 PM
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
I 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
07-09-2020 02:52 PM
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:
Cisco IOS XR Software, NETSIM
asr-0#
And, yes, I believe setting your 'empty' type parameter to an empty string:
Input.force = ''
Input.noprompt = ''
07-10-2020 12:53 AM - edited 07-10-2020 12:53 AM
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__']
>>>
11-24-2020 12:44 PM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide