add dict function for services by cloud_env (#46)
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Create Weekly Analytics Stats / run-analytics (push) Successful in 9s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Create Weekly Analytics Stats / run-analytics (push) Successful in 9s
				
			Reviewed-on: #46 Reviewed-by: Gode, Sebastian <sebastian.gode@t-systems.com> Co-authored-by: tischrei <tino.schreiber@t-systems.com> Co-committed-by: tischrei <tino.schreiber@t-systems.com>
This commit is contained in:
		@ -475,3 +475,33 @@ class Services(object):
 | 
			
		||||
        res.sort(key=lambda x: x.get("service_title", "").lower())
 | 
			
		||||
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
    def all_services_by_cloud_environment_as_dict(self, cloud_environment, environments):
 | 
			
		||||
        """Retrieve all services filtered by cloud_environment
 | 
			
		||||
        Returns a dict keyed by service_type.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        res = {}
 | 
			
		||||
 | 
			
		||||
        if not (environments and cloud_environment):
 | 
			
		||||
            raise Exception(
 | 
			
		||||
                "No cloud_environment or environments specified in function all_services_by_cloud_environment."
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        for srv in self.all_services:
 | 
			
		||||
            for srv_cloud_environment in srv.get("cloud_environments", []):
 | 
			
		||||
                if srv_cloud_environment.get("name") == cloud_environment:
 | 
			
		||||
                    for environment in environments:
 | 
			
		||||
                        if srv_cloud_environment.get("visibility") == environment:
 | 
			
		||||
                            service_type = srv.get("service_type")
 | 
			
		||||
                            if service_type:
 | 
			
		||||
                                res[service_type] = srv
 | 
			
		||||
                            break
 | 
			
		||||
        res = dict(
 | 
			
		||||
            sorted(
 | 
			
		||||
                res.items(),
 | 
			
		||||
                key=lambda item: item[1].get("service_type", "").lower()
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user