Ejemplo n.º 1
0
 def list(self, request, *args, **kwargs):
     """Obtain the list of sources."""
     response = super().list(request=request, args=args, kwargs=kwargs)
     _, tenant = self._get_account_and_tenant(request)
     for source in response.data["data"]:
         if source.get("authentication", {}).get("credentials",
                                                 {}).get("client_secret"):
             del source["authentication"]["credentials"]["client_secret"]
         try:
             manager = ProviderManager(source["uuid"])
         except ProviderManagerError:
             source["provider_linked"] = False
             source["infrastructure"] = "Unknown"
             source["cost_models"] = []
         else:
             source["provider_linked"] = True
             source["infrastructure"] = manager.get_infrastructure_name()
             connection.set_tenant(tenant)
             source["cost_models"] = [{
                 "name": model.name,
                 "uuid": model.uuid
             } for model in manager.get_cost_models(tenant)]
             connection.set_schema_to_public()
     connection.set_schema_to_public()
     return response
Ejemplo n.º 2
0
Archivo: view.py Proyecto: xJustin/koku
 def retrieve(self, request, *args, **kwargs):
     """Get a source."""
     response = super().retrieve(request=request, args=args, kwargs=kwargs)
     _, tenant = self._get_account_and_tenant(request)
     if response.data.get("authentication",
                          {}).get("credentials", {}).get("client_secret"):
         del response.data["authentication"]["credentials"]["client_secret"]
     try:
         manager = ProviderManager(response.data["uuid"])
     except ProviderManagerError:
         response.data["provider_linked"] = False
         response.data["active"] = False
         response.data["current_month_data"] = False
         response.data["infrastructure"] = "Unknown"
         response.data["cost_models"] = []
     else:
         response.data["provider_linked"] = True
         response.data["active"] = manager.get_active_status()
         response.data[
             "current_month_data"] = manager.get_current_month_data_exists(
             )
         response.data["infrastructure"] = manager.get_infrastructure_name()
         response.data["cost_models"] = [{
             "name": model.name,
             "uuid": model.uuid
         } for model in manager.get_cost_models(tenant)]
     return response
Ejemplo n.º 3
0
 def list(self, request, *args, **kwargs):
     """Obtain the list of sources."""
     response = super().list(request=request, args=args, kwargs=kwargs)
     _, tenant = self._get_account_and_tenant(request)
     for source in response.data["data"]:
         if (source.get("authentication")
                 and source.get("authentication").get("credentials")
                 and source.get("authentication").get("credentials").get(
                     "client_secret")):
             del source["authentication"]["credentials"]["client_secret"]
         try:
             manager = ProviderManager(source["uuid"])
         except ProviderManagerError:
             source["provider_linked"] = False
             source["active"] = False
             source["paused"] = False
             source["current_month_data"] = False
             source["previous_month_data"] = False
             source["has_data"] = False
             source["infrastructure"] = {}
             source["cost_models"] = []
             source["additional_context"] = {}
         else:
             source["provider_linked"] = True
             source["active"] = manager.get_active_status()
             source["paused"] = manager.get_paused_status()
             source[
                 "current_month_data"] = manager.get_current_month_data_exists(
                 )
             source[
                 "previous_month_data"] = manager.get_previous_month_data_exists(
                 )
             source["has_data"] = manager.get_any_data_exists()
             source["infrastructure"] = manager.get_infrastructure_info()
             source["cost_models"] = [{
                 "name": model.name,
                 "uuid": model.uuid
             } for model in manager.get_cost_models(tenant)]
             source["additional_context"] = manager.get_additional_context()
     return response