forked from annetutil/annetbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_async.py
More file actions
41 lines (30 loc) · 923 Bytes
/
Copy pathexample_async.py
File metadata and controls
41 lines (30 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
import os
from annetbox.base.client_async import NetboxStatusClient
from annetbox.v37.client_async import NetboxV37
async def main():
url = os.getenv("NETBOX_URL")
token = os.getenv("NETBOX_TOKEN")
# check the status of netbox installation
# ClientError with `.status_code == 404` for 2.x versions
status_client = NetboxStatusClient(url=url)
status = await status_client.status()
print(status)
await status_client.close()
# basic netbox methods
netbox = NetboxV37(url=url, token=token)
res = await netbox.dcim_devices(limit=1)
print(res)
print()
res = await netbox.dcim_interfaces(limit=1)
print(res)
print()
res = await netbox.ipam_ip_addresses(limit=1)
print(res)
print()
res = await netbox.dcim_cables(limit=1)
print(res)
print()
await netbox.close()
if __name__ == '__main__':
asyncio.run(main())