Skip to content

Commit 88921c7

Browse files
authored
Update unregister_routers_batch.py
1 parent 314c131 commit 88921c7

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

examples/unregister_routers_batch.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ def read_router_ids_from_csv(csv_filename):
9595
return router_ids
9696

9797

98-
def delete_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_file=None):
98+
def unregister_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_file=None):
9999
"""
100-
Delete routers using the NCM client in batches.
100+
Unregister routers using the NCM client in batches.
101101
102102
Args:
103-
router_ids: List of router IDs to delete
103+
router_ids: List of router IDs to unregister
104104
ncm_client: Initialized NCM client instance
105105
batch_size: Number of routers to process per batch
106106
delay: Delay in seconds between batches
@@ -112,7 +112,7 @@ def delete_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_fi
112112
total_routers = len(router_ids)
113113
num_batches = (total_routers + batch_size - 1) // batch_size # Ceiling division
114114

115-
print(f"\nStarting deletion of {total_routers} routers in {num_batches} batch(es)...")
115+
print(f"\nStarting unregistration of {total_routers} routers in {num_batches} batch(es)...")
116116
print(f"Batch size: {batch_size}, Delay between batches: {delay} seconds")
117117
print("=" * 80)
118118

@@ -129,12 +129,12 @@ def delete_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_fi
129129

130130
for idx, router_id in enumerate(batch, start=1):
131131
batch_idx = start_idx + idx
132-
print(f" [{batch_idx}/{total_routers}] Deleting router ID: {router_id}...", end=' ', flush=True)
132+
print(f" [{batch_idx}/{total_routers}] Unregistering router ID: {router_id}...", end=' ', flush=True)
133133

134134
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
135135

136136
try:
137-
result = ncm_client.delete_router_by_id(router_id)
137+
result = ncm_client.unregister_router_by_id(router_id)
138138

139139
# Check if deletion was successful
140140
if hasattr(result, 'status_code'):
@@ -148,7 +148,7 @@ def delete_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_fi
148148
# Successful DELETE usually returns 204 No Content
149149
if status_code == 204 or (isinstance(result, dict) and result.get('success', False)):
150150
status = 'success'
151-
message = 'Router deleted successfully'
151+
message = 'Router unregistered successfully'
152152
print("✓ Success")
153153
successful += 1
154154
else:
@@ -203,13 +203,13 @@ def delete_routers_batch(router_ids, ncm_client, batch_size=100, delay=0, log_fi
203203
def main():
204204
"""Main function."""
205205
parser = argparse.ArgumentParser(
206-
description='Delete routers from NCM by reading router IDs from a CSV file',
206+
description='Unregister routers from NCM by reading router IDs from a CSV file',
207207
formatter_class=argparse.RawDescriptionHelpFormatter,
208208
epilog="""
209209
Examples:
210-
python delete_routers_batch.py routers.csv
211-
python delete_routers_batch.py routers.csv --batch-size 50
212-
python delete_routers_batch.py routers.csv --batch-size 200 --delay 30
210+
python unregister_routers_batch.py routers.csv
211+
python unregister_routers_batch.py routers.csv --batch-size 50
212+
python unregister_routers_batch.py routers.csv --batch-size 200 --delay 30
213213
"""
214214
)
215215

@@ -231,7 +231,7 @@ def main():
231231
sys.exit(1)
232232

233233
print("=" * 80)
234-
print("NCM Router Batch Deletion Script")
234+
print("NCM Router Batch Unregistration Script")
235235
print("=" * 80)
236236
print(f"CSV file: {args.csv_file}")
237237
print(f"Batch size: {args.batch_size}")
@@ -246,7 +246,7 @@ def main():
246246
print("No router IDs found in CSV file.")
247247
sys.exit(1)
248248

249-
print(f"Found {len(router_ids)} router IDs to delete.")
249+
print(f"Found {len(router_ids)} router IDs to unregister.")
250250

251251
# Initialize NCM client
252252
print("\nInitializing NCM client...")
@@ -282,45 +282,45 @@ def main():
282282

283283
# Create log file with timestamp
284284
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
285-
log_filename = f'NCM_Delete_Routers_Log_{timestamp}.txt'
285+
log_filename = f'NCM_Unregister_Routers_Log_{timestamp}.txt'
286286

287287
print(f"\nLog file: {log_filename}")
288288

289-
# Confirm before deletion
290-
print(f"\n⚠️ WARNING: This will delete {len(router_ids)} routers from NCM!")
289+
# Confirm before unregistration
290+
print(f"\n⚠️ WARNING: This will unregister {len(router_ids)} routers from NCM!")
291291
response = input("Type 'yes' to continue, or anything else to cancel: ")
292292

293293
if response.lower() != 'yes':
294-
print("Deletion cancelled.")
294+
print("Unregistration cancelled.")
295295
sys.exit(0)
296296

297-
# Open log file and delete routers
297+
# Open log file and unregister routers
298298
with open(log_filename, 'w', encoding='utf-8') as log_file:
299-
log_file.write(f"NCM Router Deletion Log\n")
299+
log_file.write(f"NCM Router Unregistration Log\n")
300300
log_file.write(f"Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
301301
log_file.write(f"CSV file: {args.csv_file}\n")
302302
log_file.write(f"Total routers: {len(router_ids)}\n")
303303
log_file.write(f"Batch size: {args.batch_size}\n")
304304
log_file.write(f"Delay between batches: {args.delay} seconds\n")
305305
log_file.write("=" * 80 + "\n\n")
306306

307-
summary = delete_routers_batch(router_ids, ncm_client, args.batch_size, args.delay, log_file)
307+
summary = unregister_routers_batch(router_ids, ncm_client, args.batch_size, args.delay, log_file)
308308

309309
# Write summary to log file
310310
log_file.write("\n" + "=" * 80 + "\n")
311311
log_file.write("SUMMARY\n")
312312
log_file.write("=" * 80 + "\n")
313313
log_file.write(f"Total routers processed: {summary['total']}\n")
314-
log_file.write(f"Successfully deleted: {summary['successful']}\n")
314+
log_file.write(f"Successfully unregistered: {summary['successful']}\n")
315315
log_file.write(f"Failed: {summary['failed']}\n")
316316
log_file.write(f"Completed: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
317317

318318
# Print summary
319319
print("\n" + "=" * 80)
320-
print("DELETION RESULTS SUMMARY")
320+
print("UNREGISTRATION RESULTS SUMMARY")
321321
print("=" * 80)
322322
print(f"\nTotal routers processed: {summary['total']}")
323-
print(f"Successfully deleted: {summary['successful']}")
323+
print(f"Successfully unregistered: {summary['successful']}")
324324
print(f"Failed: {summary['failed']}")
325325
print(f"\nLog file: {log_filename}")
326326

0 commit comments

Comments
 (0)