diff --git a/otc_metadata/services.py b/otc_metadata/services.py index a8e3504..0016700 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -453,3 +453,25 @@ 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