Browse Source

first commit

master
Artur 4 years ago
commit
965e26a215
2 changed files with 53 additions and 0 deletions
  1. +0
    -0
      README.md
  2. +53
    -0
      update_patchpanel_label.py

+ 0
- 0
README.md View File


+ 53
- 0
update_patchpanel_label.py View File

@ -0,0 +1,53 @@
#!/usr/bin/python3.8
import requests
import json
import urllib3
id_or_name=(input('Input id of patchpanel:\n'))
#print(type(id_or_name))
urllib3.disable_warnings()
API_HOST = 'https://demo.netbox.dev/api'
TYPE = '/dcim/front-ports/'
API_FRONTPORT = '/dcim/front-ports/?device_id='+id_or_name
headers = {
'Authorization': "Token 8554b98861e47bc6a6fea03e5c4629c3659cacc5",
'User-Agent': 'PyScript 0.1',
'Content-Type': 'application/json',
'accept': 'application/json'
}
FRONTPORT = requests.get(API_HOST+API_FRONTPORT, headers=headers, verify=False)
ports_label = []
with open('list_pp.csv') as f:
for line in f:
ports_label.append(line.strip())
label_list = []
count_of_ports = (FRONTPORT.json()["count"])
count_in_list = len(ports_label)
if count_of_ports == count_in_list:
print('Generating list')
else:
print('Please check list')
print(f'Ports count: {count_of_ports} and ports in list: {count_in_list}')
data = []
for p in range(count_of_ports):
front_port_id = (FRONTPORT.json()["results"][p]["id"])
front_port_label = (ports_label[p])
list_done = (f'{{"id": {front_port_id}, "label": "{front_port_label}"}},')
print(list_done)

Loading…
Cancel
Save