From 6f82adb050e4e4c69f95f80e58d5c8a3218c65e1 Mon Sep 17 00:00:00 2001 From: saqib-perwaiz_navi Date: Sun, 1 Oct 2023 21:28:21 +0530 Subject: [PATCH] INFRA-2270 | Saqib | Change disasterRecovery values --- scripts/update_manifest_for_validations.py | 42 ++++++++++++++++++++ scripts/update_threshold_value_to_numbers.py | 37 ----------------- 2 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 scripts/update_manifest_for_validations.py delete mode 100644 scripts/update_threshold_value_to_numbers.py diff --git a/scripts/update_manifest_for_validations.py b/scripts/update_manifest_for_validations.py new file mode 100644 index 00000000..77cab6c1 --- /dev/null +++ b/scripts/update_manifest_for_validations.py @@ -0,0 +1,42 @@ +import time +import requests + + + +url = "" #deployment portal url +s = requests.Session() +cookie = "" #cookie +x_xsrf_token = "" # token +s.headers.update({'cookie': cookie, 'x-xsrf-token': x_xsrf_token}) +list_manifest_path = "/api/manifest/list" +r = s.get(url + list_manifest_path) +manifest_list = r.json() + +for i in manifest_list: + perform_post = False + r = s.get(url + "/api/manifest/" + str(i['id'])) + manifest = r.json() + if 'deployment' in manifest: + deployment = manifest['deployment'] + if 'alerts' in deployment: + alerts = deployment['alerts'] + for alert_type, alert_list in alerts.items(): + for alert in alert_list: + if isinstance(alert, dict) and 'threshold' in alert and isinstance(alert['threshold'], str) and alert['threshold'].isdigit(): + alert['threshold'] = int(alert['threshold']) + + if 'elasticSearch' in deployment: + elasticSearch = deployment['elasticSearch'] + if 'instance' in elasticSearch: + instance = elasticSearch['instance'] + instance['cpu'] = int(instance['cpu']) + + if manifest['metadata']['disasterRecovery'] == "Yes": + manifest['metadata']['disasterRecovery'] = "True" + + if manifest['metadata']['disasterRecovery'] == "No": + manifest['metadata']['disasterRecovery'] = "False" + + response = s.post(url + "/api/manifest", json=manifest) + print("{} response of post is {}".format(i['id'], response.text)) + time.sleep(2) diff --git a/scripts/update_threshold_value_to_numbers.py b/scripts/update_threshold_value_to_numbers.py deleted file mode 100644 index 83e5ced9..00000000 --- a/scripts/update_threshold_value_to_numbers.py +++ /dev/null @@ -1,37 +0,0 @@ -import time -import requests - - - -url = "" #deployment portal url -s = requests.Session() -cookie = "" #cookie -x_xsrf_token = "" # token -s.headers.update({'cookie': cookie, 'x-xsrf-token': x_xsrf_token}) -list_manifest_path = "/api/manifest/list" -r = s.get(url + list_manifest_path) -manifest_list = r.json() - -for i in manifest_list: - perform_post = False - r = s.get(url + "/api/manifest/" + str(i['id'])) - manifest = r.json() - if manifest['name'] == 'deployment-test': - if 'deployment' in manifest: - deployment = manifest['deployment'] - if 'alerts' in deployment: - alerts = deployment['alerts'] - for alert_type, alert_list in alerts.items(): - for alert in alert_list: - if isinstance(alert, dict) and 'threshold' in alert and isinstance(alert['threshold'], str) and alert['threshold'].isdigit(): - alert['threshold'] = int(alert['threshold']) - - if 'elasticSearch' in deployment: - elasticSearch = deployment['elasticSearch'] - if 'instance' in elasticSearch: - instance = elasticSearch['instance'] - instance['cpu'] = int(instance['cpu']) - - response = s.post(url + "/api/manifest", json=manifest) - print("{} response of post is {}".format(i['id'], response.text)) - time.sleep(2)