09-21-2020 08:45 AM
How can I (dynamically) create resource pools that assign resources on a per-device basis? Basically, I'd like to generate a pool for every device that assigns an index to some of the device's interfaces.
The following will re-use the same indexes for all devices, which is not what I want:
for interface in service.interface:
self.log.info('Working on interface ', interface.ifname)
id_allocator.id_request(service,
"/sdwan-underlay[device='%s']" % (service.device),
tctx.username,
'ifids',
interface.ifname,
False)
ifid = id_allocator.id_read(tctx.username, root,
'ifids', interface.ifname)
if not ifid: # must start at 1, 0 will drop into this
self.log.info("IFID not ready")
return
self.log.info('IFID = %s' % (ifid))
interface.intfid = ifid
I could of course manually create a pool for every device before I actually add the device, but I'm looking for a way how to handle that in Python. How can I create such a pool when (before) a new device is added? And how could it be deleted when the device disappears again?
Solved! Go to Solution.
09-21-2020 10:18 AM
09-21-2020 10:18 AM
09-21-2020 10:42 PM - edited 09-21-2020 11:04 PM
Indeed, thanks! The following works just fine:
pool_name = service.device
idpool = root.ralloc__resource_pools.idalloc__id_pool
#Check if pool exists, if not, create new one
if not pool_name in idpool:
idpool.create(pool_name)
self.log.info('Generating a new idpool for ', pool_name)
idpool[pool_name].range.start = 1
idpool[pool_name].range.end = 128
for interface in service.interface:
self.log.info('Working on interface ', interface.ifname)
id_allocator.id_request(service,
"/sdwan-underlay[device='%s']" % (service.device),
tctx.username,
pool_name,
interface.ifname,
False)
ifid = id_allocator.id_read(tctx.username, root,
pool_name, interface.ifname)
if not ifid: # must start at 1, 0 will drop into this
self.log.info("IFID not ready")
return
self.log.info('IFID = %s' % (ifid))
interface.intfid = ifid
09-21-2020 10:51 PM
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