示例#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)
def add_section(ipam=None, **kwargs):
    """ use API to add a section """
    sections_api = phpipamsdk.SectionsApi(phpipam=ipam)

    addresult = sections_api.add_section(name=kwargs['name'],
                                         description=kwargs['description'],
                                         permissions=kwargs['permissions'],
                                         show_vlan=kwargs['show_vlan'],
                                         show_vrf=kwargs['show_vrf'])

    if 'id' in addresult:
        return addresult['id']
    else:
        raise ValueError('Add Section Failed')
示例#3
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']))
示例#4
0
 def __init__(self):
     super().__init__()
     self.section_api = phpipamsdk.SectionsApi(phpipam=self.ipam)
     self.subnets_api = phpipamsdk.SubnetsApi(phpipam=self.ipam)
     self.address_api = phpipamsdk.AddressesApi(phpipam=self.ipam)