ā09-23-2022 12:44 AM
Hello, NSO experts
I would like to know how to write python codes for implementing āinsert ... before ...ā feature with Maggic/MAAPI?
for example,
admin@ncs(config)# insert devices device fmc config policy accesspolicies FTD_LAB_Policy accessrules rule10 before rule2
In my NSO package, I used Action not Service and I didnāt use template.
Example of my codes is below, I just set value for xpath.
class PolicyProvision(Action):
@Action.action
def cb_action(self, uinfo, name, kp, input, output):
with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, uinfo.username, 'system'):
with m.start_write_trans() as t:
device_config = nso_root.devices.device[dev_name].config
policy_config = device_config.cisco_fmc__policy.accesspolicies[ftd_policy_name]
policy_config.accessrules[request_policy.id].action = 'ALLOW'
policy_config.accessrules[request_policy.id].enabled = 'true'
ā¦ā¦
t.apply()
how to implement āinsert ā¦ before ā¦ā with xpath vule setting?
Solved! Go to Solution.
ā09-23-2022 06:38 AM
The create callback specifies the changes to the DB, in this transaction you add an element in a list and using move you ensure the ordering is as you need. Then after the create callback has returned the NED receives the set of diffs and decides how to configure them. If it decides to delete and recreate some part of the configuration, that might be a device limitation, or simply the NED developer did not know there was a better way achieve the config change.
The point is that how things are configured is controlled by the NED. In the create callback you control what is the intended state of the configuration. If the CLI commands you see are not as required maybe share the dry run in native as well as curly brackets format and explain how the NED could be optimised. You will might need to open a TAC case on the NED.
ā09-23-2022 01:48 AM
Hello,
I saw this is not documented in the development guide, but it is in the API reference here:
https://developer.cisco.com/docs/nso/api/#ncs-maagic/ncs.maagic.List
There you can see there is a move method you can apply after you create the element.
I sometimes find it hard to find things in the API reference docs, so I often just load the API code in visual studio and search there. That is actually how I found that move method today. The python code is all here: $NCS_DIR/src/ncs/pyapi/
ā09-23-2022 02:38 AM
Hello,
if using move method of list, in fact, the configuration will be deleted first and then added. This is not what I want
ā09-23-2022 06:38 AM
The create callback specifies the changes to the DB, in this transaction you add an element in a list and using move you ensure the ordering is as you need. Then after the create callback has returned the NED receives the set of diffs and decides how to configure them. If it decides to delete and recreate some part of the configuration, that might be a device limitation, or simply the NED developer did not know there was a better way achieve the config change.
The point is that how things are configured is controlled by the NED. In the create callback you control what is the intended state of the configuration. If the CLI commands you see are not as required maybe share the dry run in native as well as curly brackets format and explain how the NED could be optimised. You will might need to open a TAC case on the NED.
ā09-24-2022 02:25 AM
appriecate your reply, this gave me a lot of inspiration
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