Example #1
0
def del_section(ipam=None, name=None):
    """ Use API to delete a section """
    sections_api = phpipamsdk.SectionsApi(phpipam=ipam)

    sect_id = get_section_id(ipam=ipam, name=name)

    sections_api.del_section(section_id=sect_id)
Example #2
0
def get_all_subnets(ipam_conn=None, py_section=None):
    #ipam_conn will be the actual API connection to our PHPIPAM frontend
    #py_section will be manual input for us eg. 'Python Testing'

    #phpipamsdk.SectionsApi is a class within a ton of methods for us to use (can be found in the readme for the library itself)
    apiSections = phpipamsdk.SectionsApi(phpipam=ipam_conn)

    #get_section_id will get the local ID of the section, an important value if we want to add/view/delete anything from that section
    sectionId = get_section_id(ipam=ipam_conn, name=py_section)

    #list_section_subnets will need the section ID (not a name, but a local ID number) and it will return every subnet within our section
    subnetlist = apiSections.list_section_subnets(section_id=sectionId)

    #Lets simply
    if 'data' in subnetlist:
        for item in subnetlist['data']:
            print("ID: {0}\nSubnet: {1}\n\n".format(item['id'],
                                                    item['subnet']))
Example #3
0
def create_a_subnet(ipam_conn=None, py_section=None, location=None, **kwargs):
    #We can allow optional parameters to be passed into this function (eg. we might not care about passing the description into a subnet on PHPIPAM)

    #SubnetsApi will be used, to call the methods such as 'add_subnet'
    #add_subnet method simply sends a payload to 'subnets/' (eg. https://ipaddress/subnets/
    apiSubnets = phpipamsdk.SubnetsApi(phpipam=ipam_conn)

    check = apiSubnets.add_subnet(subnet=kwargs['subnet'],
                                  mask=kwargs['mask'],
                                  description=kwargs['description'],
                                  section_id=get_section_id(ipam=ipam_conn,
                                                            name=py_section),
                                  permissions=kwargs['permissions'],
                                  location_id=location)

    if 'id' in check:
        return check[
            'id']  #Return the ID of the subnet... If we store this into a variable when we call the function, we don't need to later look for the local ID of the subnet...
    else:
        print("Something went wrong...")
Example #4
0
def del_device(ipam=None, name=None):
    """ Use API to delete a device """
    devices_api = phpipamsdk.DevicesApi(phpipam=ipam)

    device_id = get_device_id(ipam=ipam, name=name)

    devices_api.del_device(device_id=device_id)


if __name__ == "__main__":
    warnings.filterwarnings('ignore')
    IPAM = phpipamsdk.PhpIpamApi(api_uri='https://192.168.16.30/api/app/',
                                 api_verify_ssl=False)
    IPAM.login(auth=('admin', 'password'))

    section_id = get_section_id(ipam=IPAM, name='ip_fabric_one')

    # Delete the Devices

    del_device(ipam=IPAM, name='border-leaf1.dc2')
    del_device(ipam=IPAM, name='border-leaf2.dc2')
    del_device(ipam=IPAM, name='spine1.dc2')
    del_device(ipam=IPAM, name='leaf1.dc2')
    del_device(ipam=IPAM, name='spine2.dc2')
    del_device(ipam=IPAM, name='leaf2.dc2')
    del_device(ipam=IPAM, name='spine3.dc2')
    del_device(ipam=IPAM, name='leaf3.dc2')
    del_device(ipam=IPAM, name='leaf4.dc2')

    # Delete the Racks