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

IPAM API Create subnet


Noob here, can someone point me to some example code on how to add a subnet under a parent folder, using python and the sdk?



0 Kudos
2 Replies
Level 8


Please see my below example to create a supernet in a hierarchyGroup.

if i[0] == 'Net_Type' and i[1] == 'Supernet':
#~# Checking or Creating Subnet if not already exists
subnetcheck = IPAMSubnetUri_Query(SWIS_Dict['Address'], SWIS_Dict['CIDR'])
if str(subnetcheck['results']) != '[]':
print('The Supernet [', SWIS_Dict['FriendlyName'], f'] already exists in the Hierarchy Group "{HierarchyGroup}" !')
print('Creation of the Supernet [', SWIS_Dict['FriendlyName'], f'] in the Hierarchy Group "{HierarchyGroup}" ... ', end = '')
invoke = swis.invoke('IPAM.SubnetManagement', 'CreateSubnetForGroup', SWIS_Dict['Address'], SWIS_Dict['CIDR'], HierarchyGroup)

#~# Getting URI after have created the Subnet
subnetquery = IPAMSubnetUri_Query(SWIS_Dict['Address'], SWIS_Dict['CIDR'])
subnetUri = subnetquery['results'][0]['Uri']

#~# Change Subnet (GroupType) for Supernet
grouptype = IPAMSubnetType_Query(SWIS_Dict['Address'], SWIS_Dict['CIDR'])
if grouptype['results'][0]['GroupType'] == 8:
print(f"Convert \"GroupType\" : 'Subnet' for 'Supernet' ... ", end = '')
swis.update(subnetUri , GroupType=4)
else: print('The Supernet [', SWIS_Dict['FriendlyName'], '] has already been converted from Subnet !')

0 Kudos
Level 12

I'm not that familiar with python, but the SDK wiki provides examples in PowerShell (what you are looking for is Create new subnet for Hierarchy group): 

0 Kudos