
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 04:36 AM - edited 03-01-2019 04:10 AM
I am trying to code an action in python that grabs certain variables from devices and then creates a service based on those variables. I already have the service's yang and xml template produced and I can create the service manually. However, I'm having some trouble calling it via nso action. My action returns the output but doesn't seem to actually push anything into NSO.
I was wondering if someone has a project developed where this kind of scenario happens. I'd be much obliged if you could share it with me.
Solved! Go to Solution.
- Labels:
-
Other NSO Topics
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 06:13 AM
Hi Gabriel,
Following is a sample code to create a new service instance from NSO action.
In this model, a new instance for a service model called "aclservice" is created with four variables (device, aclname, aclnum and aclentry).
class EnableAction(Action):
@Action.action
def cb_action(self, uinfo, name, kp, input, output):
self.log.info('action name: ', name)
# get instance name
self.instance_name = str(kp).split("{")[1].split("}")[0]
self.log.info('action key path: ', self.instance_name)
self.uinfo=uinfo
self.kp=kp
with ncs.maapi.single_write_trans(self.uinfo.username, self.uinfo.context) as t:
root = ncs.maagic.get_root(t)
# get service path
service = ncs.maagic.cd(root, self.kp)
# create a new instance of aclservice
aclservice = root.aclservice.create(self.instance_name)
aclservice.device = service.device
aclservice.aclname = service.aclname
aclservice.aclnum = service.aclnum
aclservice.aclentry = service.aclentry
t.apply()
Hope this helps.
Best regards,
Hiro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 06:13 AM
Hi Gabriel,
Following is a sample code to create a new service instance from NSO action.
In this model, a new instance for a service model called "aclservice" is created with four variables (device, aclname, aclnum and aclentry).
class EnableAction(Action):
@Action.action
def cb_action(self, uinfo, name, kp, input, output):
self.log.info('action name: ', name)
# get instance name
self.instance_name = str(kp).split("{")[1].split("}")[0]
self.log.info('action key path: ', self.instance_name)
self.uinfo=uinfo
self.kp=kp
with ncs.maapi.single_write_trans(self.uinfo.username, self.uinfo.context) as t:
root = ncs.maagic.get_root(t)
# get service path
service = ncs.maagic.cd(root, self.kp)
# create a new instance of aclservice
aclservice = root.aclservice.create(self.instance_name)
aclservice.device = service.device
aclservice.aclname = service.aclname
aclservice.aclnum = service.aclnum
aclservice.aclentry = service.aclentry
t.apply()
Hope this helps.
Best regards,
Hiro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 09:06 AM
Thank you so much for the help, that was exactly what I was looking for! I adapted it a bit to my specific context and it's working perfectly.
