I'm trying to programmatically create subnets and have run across the following challenge: How do you determine if a subnet is already in use?
Here's a snippet from my code, which gets subnet attributes from the database:
# Get the subnet attributes
q = swis.query("SELECT TOP 1 " \
"SubnetId, Address, CIDR, Comments, VLAN, Location, Description, URI " \
"FROM IPAM.Subnet "\
"WHERE (Address = '{}' AND CIDR = {})".format(
net.network_address,
net.prefixlen
)
If this returns an empty result set, then we know that the subnet does not exist, which is great. But say I have a subnet allocated already on 10.1.1.0/24, and I ask IPAM if 10.1.1.0/28 is available? It will tell me that the 28 does not exist, which is not what I want.
Any ideas?