From 965e26a215c3c18a3983b9c3ebd921a6678cd547 Mon Sep 17 00:00:00 2001 From: Artur Date: Wed, 30 Mar 2022 12:53:11 +0000 Subject: [PATCH] first commit --- README.md | 0 update_patchpanel_label.py | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 README.md create mode 100755 update_patchpanel_label.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/update_patchpanel_label.py b/update_patchpanel_label.py new file mode 100755 index 0000000..7088edc --- /dev/null +++ b/update_patchpanel_label.py @@ -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) + + +