-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_create_int
More file actions
40 lines (31 loc) · 1.21 KB
/
bulk_create_int
File metadata and controls
40 lines (31 loc) · 1.21 KB
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
import requests
API_TOKEN = "token_skfdjgsfkldgiosetu5ugoe"
HEADERS = {'Authorization': f'Token {API_TOKEN}', 'Content-Type': 'application/json',}
NB_URL = "http://exem.com"
number_of_ints = int(input('Number of interfaces: '))
interface_name = list(input('Interface names separated by ,: ').split(','))
device_name = input('Device name: ')
desc = 'some desc'
def request_devices(device_name):
url = f'{NB_URL}/api/dcim/devices/?q={device_name}'
devices = requests.get(url, headers=HEADERS)
result = devices.json()
id = result["results"][0]["id"]
return id
def bulk_post_interface(device_name, interface_name):
id = request_devices(device_name)
url = f'{NB_URL}/api/dcim/interfaces/?device={device_name}'
interface_params = []
for name in interface_name:
interface_params.append({
"device": id,
"name": name,
"description": desc,
"type": 'virtual',
"enabled": True,
"mode": "access",
},
)
new_device= requests.post(url, headers=HEADERS, json=interface_params)
print(new_device.json())
bulk_post_interface(device_name, interface_name)