-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnb-priming.py
63 lines (52 loc) · 1.32 KB
/
nb-priming.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3
import os
import pynetbox
from dotenv import load_dotenv
def connect_to_netbox(netbox_url=None, api_token=None):
if api_token is None and netbox_url is None:
load_dotenv()
netbox_url = os.environ['Netbox_URL']
api_token = os.environ['Netbox__APIToken']
return(pynetbox.api(url=netbox_url, token=api_token))
nb = connect_to_netbox()
#nb.http_session.verify = False
def create_object(nb_object, list):
for i in list:
slug = i.lower().replace(' ', '-')
if not nb_object.get(slug=slug):
nb_object.create(
name=i,
slug=slug,
)
print(f"{i} created")
else:
print(f"{i} already exists - skipping")
device_roles = [
'Appliance',
'Collaboration',
'Environment',
'Firewalls',
'Load Balancers',
'Network',
'Printers',
'Power',
'Servers',
'Storage',
'Wireless',
'Workstation'
]
sites = [
('Site A', 'formula1'),
('Site B', 'formula3'),
('Site C', 'formuul4'),
]
site_names = [name for name, regex in sites]
regions = [
'Region 1',
'Region 2',
'Region 3'
]
create_object(nb.dcim.sites, site_names)
create_object(nb.dcim.regions, regions)
create_object(nb.dcim.device_roles , device_roles)
print("Script complete!")