コード例 #1
0
def add_subnet(ipam=None, sect_id=None, loc_id=None, **kwargs):
    """ use API to add a subnet """
    subnets_api = phpipamsdk.SubnetsApi(phpipam=ipam)

    addresult = subnets_api.add_subnet(subnet=kwargs['subnet'],
                                       mask=kwargs['mask'],
                                       description=kwargs['description'],
                                       section_id=sect_id,
                                       permissions=kwargs['permissions'],
                                       location_id=loc_id)

    if 'id' in addresult:
        return addresult['id']
    else:
        raise ValueError('Add Subnet Failed')
コード例 #2
0
def add_first_free_subnet(ipam=None,
                          subnet_id=None,
                          mask=None,
                          description=None,
                          loc_id=None):
    """ use API to add first available subnet to a parent subnet """
    subnets_api = phpipamsdk.SubnetsApi(phpipam=ipam)

    addresult = subnets_api.add_subnet_first_free(subnet_id=subnet_id,
                                                  description=description,
                                                  location_id=loc_id,
                                                  mask=mask)

    if 'id' in addresult:
        return addresult['id']
    else:
        raise ValueError('Add Address Failed')
コード例 #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...")
コード例 #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)
コード例 #5
0
    #     print(len(res1['data']))
    #     for section_item in res1['data']:
    #         print(section_item)
    # print('='*100)
    # res1_1 = [i for i in res1['data'] if i['masterSubnetId'] == '0']
    # print(len(res1_1))
    # print(res1_1)

    # print('='*100)
    # res1_1 = [i for i in res1['data'] if i['description'] == 'Connect_IPPool_NETWORK']
    # if len(res1_1) == 1:
    #     print(res1_1[0])
    # else:
    #     print('there are more than one ippool named Connect_IPPool_NETWORK!')

    subnets_api = phpipamsdk.SubnetsApi(phpipam=IPAM)
    # res1 = subnets_api.get_subnets_index()
    # print(res1)
    # if res1['code'] == 200 and res1['success'] is True:
    #     print(len(res1['data']))
    #     for i in res1['data']:
    #         print('{0}'.format(i))
    # res1 = subnets_api.get_subnet(subnet_id='10')
    # print(res1)
    # if res1['code'] == 200 and res1['success'] is True:
    #     print(len(res1['data']))
    #     for k,v in res1['data'].items():
    #         print('{0}:{1}'.format(k,v))

    # res2 = subnets_api.get_subnet(subnet_id='77')
    res2 = subnets_api.get_subnet_usage(subnet_id='506')