From c4a259e89fc19cc668bd17495b791067f4c8048d Mon Sep 17 00:00:00 2001 From: Tadas Scerbinskas Date: Thu, 13 May 2021 11:13:34 +0100 Subject: [PATCH 1/3] Add missing dependency The create script depends on dateutil being available --- maintenance_windows_bulk_operations/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/maintenance_windows_bulk_operations/requirements.txt b/maintenance_windows_bulk_operations/requirements.txt index 5b1e11c..50983a8 100644 --- a/maintenance_windows_bulk_operations/requirements.txt +++ b/maintenance_windows_bulk_operations/requirements.txt @@ -1 +1,2 @@ pdpyras >= 2.1.0 +python-dateutil From 5870230604dbfcb3e6ed46a8dd7a1c4681311ee4 Mon Sep 17 00:00:00 2001 From: Tadas Scerbinskas Date: Thu, 13 May 2021 11:14:39 +0100 Subject: [PATCH 2/3] Don't print the dry-run message when it isn't --- .../create_recurring_maintenance_windows.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maintenance_windows_bulk_operations/create_recurring_maintenance_windows.py b/maintenance_windows_bulk_operations/create_recurring_maintenance_windows.py index a3e2fb8..ddb17fe 100755 --- a/maintenance_windows_bulk_operations/create_recurring_maintenance_windows.py +++ b/maintenance_windows_bulk_operations/create_recurring_maintenance_windows.py @@ -36,8 +36,9 @@ def create_recurring_maintenance_windows(args): if e.response is not None: msg += "HTTP %d: %s"%(e.response.status_code, e.response.text) print(msg) - print("(Note: no maintenance windows actually created because -n/--dry-run " - "was given)") + if args.dry_run: + print("(Note: no maintenance windows actually created because -n/--dry-run " + "was given)") def main(): desc = "Create a series of recurring maintenance windows." ap = argparse.ArgumentParser(description=desc) From be30970c9c809f3218831f7c12254ec315ea99c9 Mon Sep 17 00:00:00 2001 From: Tadas Scerbinskas Date: Thu, 13 May 2021 11:15:20 +0100 Subject: [PATCH 3/3] Remove total from the progress output It seems like the API isn't returning that anymore even when True is passed which breaks this script. Also, print the start time of the maintenance window to be more consitent with the create script. --- .../remove_all_future_maintenance_windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maintenance_windows_bulk_operations/remove_all_future_maintenance_windows.py b/maintenance_windows_bulk_operations/remove_all_future_maintenance_windows.py index 9919f2a..5d1b944 100755 --- a/maintenance_windows_bulk_operations/remove_all_future_maintenance_windows.py +++ b/maintenance_windows_bulk_operations/remove_all_future_maintenance_windows.py @@ -6,15 +6,15 @@ def remove_all_future_maintenance_windows(args): session = pdpyras.APISession(args.api_key) - progress_printer = lambda o, i, n: (print("Deleting %d/%d: %s"%( - i, n, o['summary'] + progress_printer = lambda o, i, n: (print("Deleting %d: %s starting %s"%( + i, o['summary'], o['start_time'] ))) mw_params = {"filter":"future"} if len(args.service_ids): mw_params['service_ids[]'] = args.service_ids for mw in session.iter_all("maintenance_windows", - item_hook=progress_printer, params=mw_params, total=True): + item_hook=progress_printer, params=mw_params, total=False): if args.dry_run: continue try: