04-05-2020 10:50 AM
Hi, it would be very useful for a code I'm writing in Python, to be able to get "commit dry-run outfomat xml" like output in python.
The code is like
...
with ncs.maapi.single_write_trans('admin', 'python') as t:
....
several maagic writes to CDB
...
At this point, before applying the transaction, I would lke to get CLI o XML output similar to "commit dry-run..." on the NSO CLI..
I tried t.apply with COMMIT_NCS_DRY_RUN_XML flag, but didn't get any result..
Anybody knows if that is possible?
Regards
04-05-2020 11:02 AM
04-05-2020 03:32 PM
Thanks a lot...I don't find documentation on that function...would be nice if you have an example
04-06-2020 07:55 AM
04-06-2020 08:34 AM
You can find apply_params() pydocs here: nso-5.2.0.1/doc/api/python/ncs.maapi.html
CommitParams class here: nso-5.2.0.1/src/ncs/pyapi/pysrc/maapi.py
Using CommitParams() along with apply_params() you can do dry-run like this:
04-06-2020 11:40 AM
05-07-2020 10:38 AM
05-11-2020 08:38 AM
HI Johan,
I don't recognize the this exact error, but usually it is not prudent to apply a transaction 'inside' of a transaction - tends to get into a transaction lock deadlock situation.
See this thread previous thread on a similar:
Presumably, you are attempting to save off the dry-run config that is getting written to the network. I've seen this done through a 2-step action, does a transaction for the dry-run followed by a transaction for the actual service instance commit. Also seen it done via a custom cli command that issues subsequent commit-dry-run and commit commands. I'm sure a reactive fastmap service could be crafted to do the dry-run/commit sequence as well.
11-04-2020 06:10 AM
Hi Imanor,
As per above logic, t.apply_params(True, cp) will always commit the transaction.
We have 1 scenario where we just need to show dry-run output without doing actual commit from an action.
So is it possible to do so ?
We are aware of the old way by using services commit-dry-run like below
```
However since it is deprecated; we are looking for new way.
Thanks in advance
11-04-2020 08:33 AM
Hello,
I am not seeing the behavior that you see, the dry-run commit is _not_ committed to the running-config:
[edit]
admin@ncs% show devices device ios-1 config ios:hostname
ios:hostname TEST1;
[ok][2020-11-04 11:13:30]
In [8]: 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)
...: name = 'ios-1'
...: dev = root.ncs__devices.device['ios-1']
...: dev.config.ios__hostname = 'Test_82'
...: cp = ncs.maapi.CommitParams()
...: cp.dry_run_cli()
...: r = t.apply_params(True, cp)
...: print (r)
...:
{'dry-run': True, 'outformat': 'cli', 'local-node': ' devices {\n device ios-1 {\n config {\n- ios:hostname TEST1;\n+ ios:hostname Test_82;\n }\n }\n }\n'}
[edit]
admin@ncs% show devices device ios-1 config ios:hostname
ios:hostname TEST1;
[ok][2020-11-04 11:14:04]
In [9]: 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)
...: name = 'ios-1'
...: dev = root.ncs__devices.device['ios-1']
...: dev.config.ios__hostname = 'Test_82'
...: cp = ncs.maapi.CommitParams()
...: cp.dry_run_xml()
...: r = t.apply_params(True, cp)
...: print (r)
...:
{'dry-run': True, 'outformat': 'xml', 'local-node': '<devices xmlns="http://tail-f.com/ns/ncs">\n <device>\n <name>ios-1</name>\n <config>\n <hostname xmlns="urn:ios">Test_82</hostname>\n </config>\n </device>\n</devices>\n'}
[edit]
admin@ncs% show devices device ios-1 config ios:hostname
ios:hostname TEST1;
[ok][2020-11-04 11:14:44]
In [10]: 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)
...: name = 'ios-1'
...: dev = root.ncs__devices.device['ios-1']
...: dev.config.ios__hostname = 'Test_82'
...: cp = ncs.maapi.CommitParams()
...: cp.dry_run_native()
...: r = t.apply_params(True, cp)
...: print (r)
{'dry-run': True, 'outformat': 'native', 'device': {'ios-1': '\n\nhostname Test_82\n'}}
[edit]
admin@ncs% show devices device ios-1 config ios:hostname
ios:hostname TEST1;
[ok][2020-11-04 11:16:49]
08-18-2022 06:49 AM
I have the same problem. NSO Version 5.6.4
11-05-2020 01:14 AM
Got it Thanks.
06-10-2021 10:37 PM
Hi all,
I am looking to access the Commit Parameters (dry-run, no-networking, etc) in the cb_create or in the service pre_modification.
I simply tried this :
03-11-2022 03:13 AM
Hi,
just to follow-up .
The answer is there for NSO >5.5 : Solved: Re: How to check if it is a dry-run in python for a service - Cisco Community
Benoit
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: