I've being creating a script to quickly find available ip addresses in the IPAM. What I do first is to find an available subnet, then the ip addresses on it and finally change the status for those ip addresses and for the subnet as well. The problem is that if I want to book multiple subnets I need to wait for a long time until the last subnet change its status (like 30 seconds). So, my questions are:
- Why is that happening?
- Is there a way to reduce the time?
I'm using python library orionsdk. Next is the part of the code that I'm using to book the ip addresses:
QUERIES = {'loopback':{'subnet':'''SELECT Top 1 I.DisplayName, I.Uri FROM IPAM.subnet I
WHERE I.Address like '{0}' and I.CIDR = 32 and I.Status = 1''',
'address':'''SELECT Top 1 I.DisplayName, I.Uri FROM IPAM.IPNode I
WHERE I.Subnet.Address = '{0}' and I.Status = 2'''},
'p2p':{'subnet':'''SELECT Top 1 I.DisplayName, I.Uri FROM IPAM.subnet I WHERE I.Address
like '{0}' and I.CIDR = 31 and I.Status = 1''',
'address':'''SELECT I.DisplayName, I.Uri FROM IPAM.IPNode I WHERE I.Subnet.Address
= '{0}' and I.Status = 2 group by I.DisplayName, I.Uri'''}}
def query_loo(SWIS, network, loo_type):
'''Query the ip prefixes for loopbacks from he IPAM
Keyword arguments:
SWIS -- Connection to Solarwinds IPAM
network -- Network type (MAN/IBN)
loo_type -- Loopback type (ip1/ip2)'''
# Iterate over all the valid intervals
for subnet in IPINTERVALS[network][loo_type]:
# Stop for-loop if the JOKER arrives
if subnet == 'JOKER':
break
# Split subnet prefix into address and mask
address, cidr = subnet.split('/')
# The first three octets
wildcard = address.split(".")[0] + '.' + address.split(".")[1] + \
'.' + address.split(".")[2] + '.%'
# Query the first available subnet
results = SWIS.query(QUERIES['loopback']['subnet'].format(wildcard))
# Check if it is empty
if len(results['results']) == 0:
continue
else:
ip_subnet, mask = results['results'][0]['DisplayName'].split('/')
subnet_uri = results['results'][0]['Uri']
# Query the first ip available
results = SWIS.query(QUERIES['loopback']['address'].format(ip_subnet.rstrip()))
address = results['results'][0]['DisplayName']
uri = results['results'][0]['Uri']
# Update Status
SWIS.update(uri, Status=1)
# Update Subnet status
SWIS.update(subnet_uri, Status=14)
break
return [address, uri]
Thank you in advance.
Greetings,
Amado.