Showing results for 
Search instead for 
Did you mean: 
Create Post

SDK occasionally returns random IP address from a subnet instead of the first available

Hello All,

I am using following Python script to reserve the first available IP address from a subnet. It works fine most of the time but occasionally it returns a random available address from the middle of the range instead of the first available. Any ideas why is this happening and how to fix it?

import sys
from orionsdk import SwisClient

api_username = sys.argv[1]
api_password = sys.argv[2]
ipam_server = ''

# Get first available ip address
query = "SELECT TOP 1 I.DisplayName, I.Uri FROM IPAM.IPNode I WHERE Status=2 AND I.Subnet.DisplayName = '{0}'".format(sys.argv[3])
swis = SwisClient(ipam_server, api_username, api_password)
results = swis.query(query)
for result in results['results']:
uri = result['Uri']

# Mark the ip address as Reserved and add a comment
swis.update(uri, Status='Reserved', DnsBackward=sys.argv[4])
0 Kudos
0 Replies