del _vlans[ 0] #Current index 0 is normally the heading eg. VLAN Status etc.... for _vlan in _vlans: _vlan = _vlan.split() vlan_dict = {'vlanId': _vlan[0], 'name': _vlan[1]} vlan_list.append(vlan_dict) return vlan_list if __name__ == "__main__": warnings.filterwarnings('ignore') #PhpIpamApi() is were the REST API magic happens, methods within this class handle the requests/tokens/authentication API = phpipamsdk.PhpIpamApi() #Simple a method within PhpIpamApi() class that checks if we will be using authentication, if so then it will send a http POST request which should return a token API.login() #call our function above to get all the subnets, section name is manual input, but we can do loads more with this function in a loop etc... #get_all_subnets(ipam_conn=API, py_section='Python Testing') #Permissions = SECTION Operators, SECTION Guests, something? something? #Store the function as a variable. When we print the result, it obviously creates the SUBNET itself but we have the local ID value that has been created... """ subnetPrint = create_a_subnet( ipam_conn=API, py_section='Python Testing', subnet='10.0.3.0',
racks_api.del_tools_rack(rack_id=rack_id) 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')
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) res = devices_api.del_device(device_id=device_id) print(res) if __name__ == "__main__": warnings.filterwarnings('ignore') # IPAM = phpipamsdk.PhpIpamApi( # api_uri='http://127.0.0.1/api/admin/', api_verify_ssl=False) # IPAM.login(auth=('admin', 'root@123')) IPAM = phpipamsdk.PhpIpamApi() IPAM.login() # 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
def login(self): warnings.filterwarnings('ignore') IPAM = phpipamsdk.PhpIpamApi() IPAM.login() return IPAM