From 3c4a2a73fe5c34b2ad02f8f0466b2a854f7f5cc6 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 4 Aug 2025 09:27:46 +0000 Subject: [PATCH 1/3] New service function --- otc_metadata/services.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/otc_metadata/services.py b/otc_metadata/services.py index a8e3504..0c021e8 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -13,6 +13,7 @@ import copy import warnings +import json import otc_metadata.data @@ -453,3 +454,26 @@ class Services(object): res.sort(key=lambda x: x.get("name", "").lower()) return res + + def all_services_by_cloud_environment(self, cloud_environment, environments): + """Retrieve all services filtered by cloud_environment + """ + res = [] + for srv in self.all_services: + if environments and cloud_environment: + for srv_cloud_environment in srv["cloud_environments"]: + if srv_cloud_environment["name"] == cloud_environment: + for environment in environments: + if srv_cloud_environment["visibility"] == environment: + res.append(srv) + else: + continue + else: + raise Exception("No cloud_environment or environments " \ + "specified in function all_services_by_cloud_environment.") + + + # Sort services + res.sort(key=lambda x: x.get("service_title", "").lower()) + + return res \ No newline at end of file -- 2.34.1 From 850c39e17f49ab9ffa5b1f92692012b6f0420d2e Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 4 Aug 2025 09:28:21 +0000 Subject: [PATCH 2/3] remove json --- otc_metadata/services.py | 1 - test.py | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test.py diff --git a/otc_metadata/services.py b/otc_metadata/services.py index 0c021e8..5cc9a88 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -13,7 +13,6 @@ import copy import warnings -import json import otc_metadata.data diff --git a/test.py b/test.py new file mode 100644 index 0000000..0bd42cf --- /dev/null +++ b/test.py @@ -0,0 +1,5 @@ +import otc_metadata +import json + + +print(json.dumps(otc_metadata.services.Services().all_services_by_cloud_environment(cloud_environment="eu_de",environments=["public","internal","hidden"]))) \ No newline at end of file -- 2.34.1 From ca7b7e371217a865ea84ab418388cff0a51f8ebe Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Mon, 4 Aug 2025 09:34:50 +0000 Subject: [PATCH 3/3] fix pep8 --- otc_metadata/services.py | 7 +++---- test.py | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 test.py diff --git a/otc_metadata/services.py b/otc_metadata/services.py index 5cc9a88..0016700 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -468,11 +468,10 @@ class Services(object): else: continue else: - raise Exception("No cloud_environment or environments " \ - "specified in function all_services_by_cloud_environment.") - + raise Exception("No cloud_environment or environments " + "specified in function all_services_by_cloud_environment.") # Sort services res.sort(key=lambda x: x.get("service_title", "").lower()) - return res \ No newline at end of file + return res diff --git a/test.py b/test.py deleted file mode 100644 index 0bd42cf..0000000 --- a/test.py +++ /dev/null @@ -1,5 +0,0 @@ -import otc_metadata -import json - - -print(json.dumps(otc_metadata.services.Services().all_services_by_cloud_environment(cloud_environment="eu_de",environments=["public","internal","hidden"]))) \ No newline at end of file -- 2.34.1