-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIN-Network-Rename.py
51 lines (42 loc) · 1.4 KB
/
IN-Network-Rename.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
#!/usr/bin/env python3
import traceback
import json
from unicodedata import normalize
import dotenv
import meraki
from pyzabbix import ZabbixAPI, ZabbixAPIException
from tqdm import tqdm
config = dotenv.dotenv_values()
client = meraki.DashboardAPI(
config['MERAKI_API_KEY'],
output_log=False,
nginx_429_retry_wait_time=3,
action_batch_retry_wait_time=3,
print_console=False,
suppress_logging=True,
maximum_retries=10)
# zabbix = ZabbixAPI(config['ZABBIX_URL'])
# zabbix.login(api_token=config['ZABBIX_API_TOKEN'])
# dashboard = meraki.DashboardAPI(config['MERAKI_API_KEY'])
networks = client.organizations.getOrganizationNetworks(
config['ORG_ID'], total_pages='all'
)
Initial = 0
final = 1
for network in networks:
old_name = network['name']
if old_name.startswith('IN') and len(old_name) > 2 and old_name[2] != '-': # Check if the hyphen is already present
# Insert hyphen after the first two characters
new_name = old_name[:2] + '-' + old_name[2:]
# Rename the network
client.networks.updateNetwork(
network['id'],
name=new_name
)
Initial += 1
print(f"Renamed '{old_name}' to '{new_name}'")
else:
print(f"Skipped renaming '{old_name}'")
if Initial >= final:
break
print("Renaming process completed.")