This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Adding new IPAM subnets via SWIS to existing groups

I am working on an application that allows users to automatically add subnets into IPAM by simply putting in some basic site details. It works with a basic Django based front-end and using Netmiko to jump on the kit. It's nearly done, I just need to export all the data I have into SWIS.

I am using the OrionSDK library for Python, and am a bit confused as to how I build out the command in SWIS, so far I have this:

swis.invoke('CreateSubnetForGroup', SWIS_Dict[str(i)]['address'], SWIS_Dict[str(i)]['cidr'], SWIS_Dict[str(i)]['code'])

Where;

`SWIS_Dict` is a nested dictionary of processed parameters, i.e. subnet address, cidr and site-code

`i` is an index as this is part of a loop, for adding multiple subnets

Using this as a reference​, there is an outline as to how to do this for a 'Hierarchy Group', but all of our sites exist as groups under a single hierarchy group simply called "IP Networks" .

I am assuming I will also need to run CRUD operations on the subnets once they are added, for things such as the VLAN ID, display name and descriptions.

  • If you just want the new subnets to be placed at the top level (not under a specific group), then you can use the "CreateSubnet" verb instead of "CreateSubnetForGroup".

    Yes, you can use CRUD operations to set VLAN ID and other properties after the subnet is created. You will need to run a query to find the URI for the new subnet first.

  • Hi tdanner, thank you for your response.

    I am speaking to our SQL DBA and we are unsure how to craft a query that will return the right results for X subnet. Do you have any idea?

  • Sure. If you create a subnet like this:

    swis.invoke('IPAM.SubnetManagement', '10.199.3.0', '24')

    Then you can find the Uri of the new subnet like this:

    results = swis.query('SELECT Uri FROM IPAM.Subnet WHERE Address=@addr AND CIDR=@cidr', addr='10.199.3.0', cidr=24)

    uri = results['results'][0]['Uri']

  • Thank you for your help so far. I am still struggling to work out how I move my created subnet into the correct group after it has been created.

    For example, if I wanted to move my subnet to "AE10" folder in IPAM

    .

    So far my code looks like this:

    def IPAMBuild(SWIS_Dict):
        swis = orionsdk.SwisClient("XXX", "XXX", "XXX")
        for i in SWIS_Dict:
            SWIS_Dict_Output = {}
            try:
                SWIS_Dict_Output[i] = swis.invoke('IPAM.SubnetManagement', 'CreateSubnet', SWIS_Dict[i]['address'], SWIS_Dict[i]['cidr'])
                results = swis.query('SELECT Uri FROM IPAM.Subnet WHERE Address=@addr AND CIDR=@cidr', addr=SWIS_Dict[i]['address'], SWIS_Dict[i]['cidr'])
                uri = results['results'][0]['Uri']

    It works great, I just need those subnets in the right folder.

    ***EDIT***

    I managed to get this working.

    def IPAMBuild(SWIS_Dict):
        swis = orionsdk.SwisClient("XXX", "XXX", "XXX")
        for i in SWIS_Dict:
            if SWIS_Dict[i]['net_type'] == 'subnet':
                SWIS_Dict_Output = {}
                SWIS_Dict_Output[i] = swis.invoke('IPAM.SubnetManagement', 'CreateSubnet', SWIS_Dict[i]['address'], SWIS_Dict[i]['cidr'])
                results = swis.query('SELECT Uri FROM IPAM.Subnet WHERE Address=@addr AND CIDR=@cidr', addr=SWIS_Dict[i]['address'], cidr=SWIS_Dict[i]['cidr'])
                groupid_dty = swis.query('SELECT Groupid FROM IPAM.GroupNode WHERE FriendlyName=@name', name=SWIS_Dict[i]['code'])
                groupid = groupid_dty['results'][0]['Groupid']
                uri = results['results'][0]['Uri']
                swis.update(uri, FriendlyName = SWIS_Dict[i]['display_name'])
                swis.update(uri, VLAN = SWIS_Dict[i]['vlan'])
                swis.update(uri, ParentId = groupid)

    The only thing left now is to import the Supernets... tdanner​ any idea how I would go about that?

  • Glad you got it working.

    Unfortunately, group and supernet creation is not supported through the API. This is tracked internally as IPAM-705.

  • Thank you again. Do you have any plans to update the API to support this? If so, is there any idea of a timeline?

  • Sorry, I can't help with timelines. But I did add your vote to that case.

  • Just an FYI, if you don't want to wait for them to finish the API verbs for this you can use the API to push straight SQL commands into the database, and I know of several cases in the past where engineers have done all sorts of manipulation and creation of the supernets and groups directly via the db.  Obviously, don't test that kind of thing on your prod system, but it isn't terribly hard to figure out.

  • My SQL ability is non-existent, I essentially re-learnt python for this project. Do you know of any examples I could reference?

  • Nothing that's out in the open.  I did it twice in the past just by looking at the tables and building SQL scripts basically on the fly to insert the equivalent object in a new environment.  Don't have anything saved because at the time it seemed very straightforward, but I work in SQL all the time, sorry.