コード例 #1
0
    def __init__(self, parameters):
        """Establish OCP report query handler.

        Args:
            parameters    (QueryParameters): parameter object for query

        """
        self._mapper = OCPProviderMap(provider=self.provider,
                                      report_type=parameters.report_type)
        self.group_by_options = self._mapper.provider_map.get(
            'group_by_options')
        self._limit = parameters.get_filter('limit')

        # super() needs to be called after _mapper and _limit is set
        super().__init__(parameters)
        # super() needs to be called before _get_group_by is called

        # Update which field is used to calculate cost by group by param.
        group_by = self._get_group_by()
        if (group_by and 'project' in group_by
                or 'project' in parameters.get('filter', {}).keys()) \
                and parameters.report_type == 'costs':
            self._report_type = parameters.report_type + '_by_project'
            self._mapper = OCPProviderMap(provider=self.provider,
                                          report_type=self._report_type)
コード例 #2
0
ファイル: query_handler.py プロジェクト: m7salam/koku
    def __init__(self, query_parameters, url_data, tenant, **kwargs):
        """Establish OCP report query handler.

        Args:
            query_parameters    (Dict): parameters for query
            url_data        (String): URL string to provide order information
            tenant    (String): the tenant to use to access CUR data
            kwargs    (Dict): A dictionary for internal query alteration based on path

        """
        provider = 'OCP'
        self._initialize_kwargs(kwargs)
        if kwargs.get('access'):
            query_parameters = update_query_parameters_for_openshift(
                query_parameters, kwargs.get('access'))

        self._mapper = OCPProviderMap(provider=provider,
                                      report_type=kwargs.get('report_type'))
        self.group_by_options = self._mapper.provider_map.get(
            'group_by_options')
        self.query_parameters = query_parameters
        self.url_data = url_data
        self._limit = self.get_query_param_data('filter', 'limit')

        # Update which field is used to calculate cost by group by param.
        group_by = self._get_group_by()
        if (group_by and 'project' in group_by
                or 'project' in self.query_parameters.get('filter', {}).keys()) \
                and kwargs.get('report_type') == 'costs':
            self._report_type = kwargs.get('report_type') + '_by_project'
            self._mapper = OCPProviderMap(provider=provider,
                                          report_type=self._report_type)

        super().__init__(query_parameters, tenant, **kwargs)
コード例 #3
0
    def __init__(self, parameters):
        """Establish AWS report query handler.

        Args:
            parameters    (QueryParameters): parameter object for query

        """
        if not hasattr(self, "_mapper"):
            self._mapper = OCPProviderMap(provider=self.provider,
                                          report_type=parameters.report_type)
        # super() needs to be called after _mapper is set
        super().__init__(parameters)
コード例 #4
0
    def __init__(self, parameters):
        """Establish OCP report query handler.

        Args:
            parameters    (QueryParameters): parameter object for query

        """
        self._mapper = OCPProviderMap(provider=self.provider,
                                      report_type=parameters.report_type)
        self.group_by_options = self._mapper.provider_map.get(
            "group_by_options")
        self._limit = parameters.get_filter("limit")

        # super() needs to be called after _mapper and _limit is set
        super().__init__(parameters)
        # super() needs to be called before _get_group_by is called

        # Update which field is used to calculate cost by group by param.
        if is_grouped_by_project(
                parameters) and parameters.report_type == "costs":
            self._report_type = parameters.report_type + "_by_project"
            self._mapper = OCPProviderMap(provider=self.provider,
                                          report_type=self._report_type)
コード例 #5
0
    def __init__(self, parameters):
        """Establish AWS report query handler.

        Args:
            parameters    (QueryParameters): parameter object for query

        """
        self._parameters = parameters
        if not hasattr(self, "_mapper"):
            self._mapper = OCPProviderMap(provider=self.provider,
                                          report_type=parameters.report_type)

        if parameters.get_filter("enabled") is None:
            parameters.set_filter(**{"enabled": True})
        # super() needs to be called after _mapper is set
        super().__init__(parameters)
コード例 #6
0
ファイル: query_handler.py プロジェクト: project-koku/koku
    def __init__(self, parameters):
        """Establish OCP report query handler.

        Args:
            parameters    (QueryParameters): parameter object for query

        """
        self._mapper = OCPProviderMap(provider=self.provider,
                                      report_type=parameters.report_type)
        self.group_by_options = self._mapper.provider_map.get(
            "group_by_options")
        self._limit = parameters.get_filter("limit")

        # We need to overwrite the default pack definitions with these
        # Order of the keys matters in how we see it in the views.
        ocp_pack_keys = {
            "infra_raw": {
                "key": "raw",
                "group": "infrastructure"
            },
            "infra_markup": {
                "key": "markup",
                "group": "infrastructure"
            },
            "infra_usage": {
                "key": "usage",
                "group": "infrastructure"
            },
            "infra_distributed": {
                "key": "distributed",
                "group": "infrastructure"
            },
            "infra_total": {
                "key": "total",
                "group": "infrastructure"
            },
            "sup_raw": {
                "key": "raw",
                "group": "supplementary"
            },
            "sup_markup": {
                "key": "markup",
                "group": "supplementary"
            },
            "sup_usage": {
                "key": "usage",
                "group": "supplementary"
            },
            "sup_distributed": {
                "key": "distributed",
                "group": "supplementary"
            },
            "sup_total": {
                "key": "total",
                "group": "supplementary"
            },
            "cost_raw": {
                "key": "raw",
                "group": "cost"
            },
            "cost_markup": {
                "key": "markup",
                "group": "cost"
            },
            "cost_usage": {
                "key": "usage",
                "group": "cost"
            },
            "cost_distributed": {
                "key": "distributed",
                "group": "cost"
            },
            "cost_total": {
                "key": "total",
                "group": "cost"
            },
        }
        ocp_pack_definitions = copy.deepcopy(self._mapper.PACK_DEFINITIONS)
        ocp_pack_definitions["cost_groups"]["keys"] = ocp_pack_keys

        # Update which field is used to calculate cost by group by param.
        if is_grouped_by_project(
                parameters) and parameters.report_type == "costs":
            self._report_type = parameters.report_type + "_by_project"
            self._mapper = OCPProviderMap(provider=self.provider,
                                          report_type=self._report_type)

        # super() needs to be called after _mapper and _limit is set
        super().__init__(parameters)
        # super() needs to be called before _get_group_by is called

        self._mapper.PACK_DEFINITIONS = ocp_pack_definitions