cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
451
Views
5
Helpful
3
Replies
martin.gysi
Beginner

Resource pool per device

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
vleijon
Cisco Employee

You can create your per-device pool from the service code itself, it will then be deleted when the last reference to it is deleted.

View solution in original post

3 REPLIES 3
vleijon
Cisco Employee

You can create your per-device pool from the service code itself, it will then be deleted when the last reference to it is deleted.

View solution in original post

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

 

Good.

One comment, you probably want to skip that if-statement checking if the pool already exists or not. If you have multiple services on the same device you want them all to create the pool. NSO is reference counting which means that if they all have a reference to the pool it won’t be deleted until the last service is deleted.