09-28-2023 09:50 AM
I want to write code for calling the action load-native-config in python.
What is a sample code for doing that?
09-28-2023 03:07 PM - edited 09-28-2023 03:08 PM
Hello,
Here an example
import ncs
device_name="NETSIM-XR-0"
config="""
hostname TEST-PYTHON
"""
print(f"Loading config {config} on device {device_name}")
with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, 'admin', 'python', groups=['ncsadmin']):
with m.start_write_trans() as t:
root = ncs.maagic.get_root(t)
load_native_input = root.devices.device[device_name].load_native_config.get_input()
load_native_input.data = config
load_native_output = root.devices.device[device_name].load_native_config(load_native_input)
10-18-2023 10:30 AM
Thanks!
From the above solution, when I try to access: load_native_output.result , then I get the below error:-
'ActionParams' object has no attribute 'result'
10-19-2023 08:37 AM
Try load_native_output.info
See $NCS_DIR/src/ncs/yang/tailf-ncs-devices.yang under load-native-config for input and output parameters.
10-25-2023 10:42 AM
I am still getting an error parsing the response:--
load_native_input = root.devices.device[device_name].load_native_config.get_input() load_native_input.data = config load_native_input.dry_run.outformat = "native" load_output = root.devices.device[device_name].load_native_config(load_native_input) self.log.info("result") self.log.info(load_output.native.device[device_name].data) The last line parses the result and gives an error: <INFO> 19-Oct-2023::11:21:56.182 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - action name: act-load-native <INFO> 19-Oct-2023::11:21:56.182 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - config in fileinterface TenGigabitEthernet0/1/1 description SERV_005 <INFO> 19-Oct-2023::11:21:56.196 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - device name isxe0 <INFO> 19-Oct-2023::11:21:56.547 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - result <ERROR> 19-Oct-2023::11:21:56.548 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - Error in ActLoadNativeConfigAction <ERROR> 19-Oct-2023::11:21:56.548 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - '{xe0} not in /native/device' <ERROR> 19-Oct-2023::11:21:56.549 act-load-native ncs-dp-34481-act-load-native:main-1-usid-130-act-load-native: - Traceback (most recent call last): File "/Users/suvdeshm/run-5.6.41/state/packages-in-use/1/act-load-native/python/act_load_native/main.py", line 99, in cb_action self.log.info(load_output.native.device[device_name].data) File "/Users/suvdeshm/nso-5.6.4/src/ncs/pyapi/ncs/maagic.py", line 1102, in __getitem__ raise KeyError('%s not in %s' % (keystr, self._path)) KeyError: '{xe0} not in /native/device'
10-26-2023 12:09 AM - edited 10-26-2023 12:42 AM
The load-native-config action does not commit the transaction when using MAAPI as it does with, for example, RESTCONF.
So, after loading the native config, if you want the output of a dry-run and then commit/apply the transaction, try something like:
...
self.log.info("result")
t = ncs.maagic.get_trans(root)
params = t.get_params()
params.dry_run_native()
result = t.apply_params(True, params)
self.log.info(result['local-node'])
t.apply_params(True, t.get_params())
See https://developer.cisco.com/docs/nso/api/#!ncs-maapi/ncs.maapi.Transaction.apply_params for details
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