01-11-2018 09:59 AM - edited 03-01-2019 04:04 AM
Hi Team,
I’m trying to better understand the following:
I get the following error when running my code:
Error: Operation was aborted (49): Operation on: /ncs:devices/device{xr1}/config/cisco-ios-xr:class-map{af} failed because: sharedCreate() called outside fastmap
Here is the code snippet:
# -*- mode: python; python-indent: 4 -*-
import ncs
from ncs.application import Service
class ServiceCallbacks(Service):
@Service.create
def cb_create(self, tctx, root, service, proplist):
self.log.info('Service create(service=', service._path, ')')
srcPE = service.src_device
srcGePhyPort = service.src_GigE_physint
destPE = service.dest_device
destPort = service.dest_interface
currentClass = 'af'
m = ncs.maagic.get_maapi(root)
t = m.attach(tctx.th)
t.shared_copy_tree('/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (srcPE, currentClass), '/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (destPE, currentClass))
template = ncs.template.Template(service)
template.apply('service-template', vars)
To me the above function is inside FASTMAP since it’s in cb_create and using the same root and session transaction handler, what am I missing?
If I pass flag 0 the error I get back is bad formatted or non-existent path, the above works fine with copy_tree but not shared, which is problematic when I want to remove or modify the service
Please excuses any obvious mistakes, my python skills are very rudimental to say the least
Thanks!
Solved! Go to Solution.
01-11-2018 01:57 PM
Dan, thanks so much for your help! Below is how we made it work:
instead of
m = ncs.maagic.get_maapi(root)
t = m.attach(tctx)
t.shared_copy_tree('/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (srcPE, currentClass), '/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (destPE, currentClass))
we used
t = ncs.maagic.get_trans(root)
t.shared_copy_tree('/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (srcPE, currentClass), '/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (destPE, currentClass))
no need to redefine a maapi object and attaching to a transaction, just use the existing transaction by root
Thanks!
01-11-2018 10:25 AM
Hi Maan,
If you don't used share_copy_tree and must copy_tree does it do what you want?
-Dan
01-11-2018 11:14 AM
Hi Dan,
With copy_tree I can deploy the service and see the class-map in my example being copied from xr0 to xr1, however when I delete the service, it's doesn't remove the class-map from xr1. That's why I thought I need to use shared_copy_tree, as indicated in the documentation:
shared_copy_tree(*args, **kwargs)
FASTMAP version of copy_tree().
Does that make sense?
Thanks!
01-11-2018 11:55 AM
Hi Maan,
No, that's not really the purpose of 'shared'. In fact, shared sets are used to insure configuration changes can be handled correctly among 1 or more services which share some common configuration items. I'm not sure exactly what is going on with your service. I'll take a closer look.
-Dan
01-11-2018 12:00 PM
Hi Maan,
Can you post the service modifications once your service is configured?
-Dan
01-11-2018 12:20 PM
Hi Dan,
admin@ncs(config)# services emergency_pe_migration_mx_mx 123 src-device xr0 src-GigE-physint 0/0/0/1 dest-device xr1 dest-interface 0/0/0/1
admin@ncs(config-emergency_pe_migration_mx_mx-123)# commit dry-run cli {
local-node {
data devices {
device xr1 {
config {
+ cisco-ios-xr:class-map af {
+ prematch match-any;
+ match {
+ dscp {
+ dscp-list ef;
+ }
+ }
+ }
}
}
}
services {
+ emergency_pe_migration_mx_mx 123 {
+ src-device xr0;
+ src-GigE-physint 0/0/0/1;
+ dest-device xr1;
+ dest-interface 0/0/0/1;
+ }
}
}
}
admin@ncs(config-emergency_pe_migration_mx_mx-123)# commit
Commit complete.
admin@ncs(config-emergency_pe_migration_mx_mx-123)# exit
admin@ncs(config)# no services emergency_pe_migration_mx_mx 123
admin@ncs(config)# commit dry-run
cli {
local-node {
data services {
- emergency_pe_migration_mx_mx 123 {
- src-device xr0;
- src-GigE-physint 0/0/0/1;
- dest-device xr1;
- dest-interface 0/0/0/1;
- }
}
}
}
This is with tree_copy , pong deleting the service, the changes earlier made on xr1 is not reverted.
Thanks!
01-11-2018 01:57 PM
Dan, thanks so much for your help! Below is how we made it work:
instead of
m = ncs.maagic.get_maapi(root)
t = m.attach(tctx)
t.shared_copy_tree('/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (srcPE, currentClass), '/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (destPE, currentClass))
we used
t = ncs.maagic.get_trans(root)
t.shared_copy_tree('/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (srcPE, currentClass), '/ncs:devices/device{%s}/config/cisco-ios-xr:class-map{%s}' % (destPE, currentClass))
no need to redefine a maapi object and attaching to a transaction, just use the existing transaction by root
Thanks!
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