cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
688
Views
5
Helpful
4
Replies

How to implement 'insert ... before...' with Magic/MAAPI

icwang
Cisco Employee
Cisco Employee

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?

1 Accepted Solution

Accepted Solutions

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.

View solution in original post

4 Replies 4

snovello
Cisco Employee
Cisco Employee

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/

 

 

 

Hello, 

if using move method of list, in fact, the configuration will be deleted first and then added. This is not what I want

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.

appriecate your reply, this gave me a lot of inspiration