Esempio n. 1
0
File: ocp.py Progetto: ebpetway/koku
    def _build_tag_key_tab(self):
        """
        Generate tag_key tab component

        Returns:
            (Dict) - Tab Item
        """
        tag_key_text_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.form-text"
        tag_key_text_context = (
            "Enable your OpenShift label names to be used as tag keys for report grouping and filtering."
        )
        tag_key_text = create_plain_text(tag_key_text_name,
                                         tag_key_text_context)
        available, enabled = self._obtain_tag_keys()
        avail_objs = [{
            "value": tag_key,
            "label": tag_key
        } for tag_key in available]
        dual_list_options = {
            "options": avail_objs,
            "leftTitle": "Available Tag Keys",
            "rightTitle": "Enabled Tag Keys",
            "noValueTitle": "No enabled tag keys",
            "noOptionsTitle": "No available tag keys",
            "filterOptionsTitle": "Filter available",
            "filterValueTitle": "Filter enabled",
            "filterValueText":
            "Remove your filter to see all enabled tag keys",
            "filterOptionsText":
            "Remove your filter to see all available tag keys",
            "initialValue": enabled,
        }
        tab_dual_list_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.enabled"
        tab_dual_list_select = create_dual_list_select(tab_dual_list_name,
                                                       **dual_list_options)
        tab_sub_form_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.subform"
        tab_sub_form_title = "Tag Key Enablement"
        tab_sub_form_fields = [tag_key_text, tab_dual_list_select]
        tab_sub_form = create_subform(tab_sub_form_name, tab_sub_form_title,
                                      tab_sub_form_fields)

        tab_item_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.tab-item"
        tab_item_title = "OpenShift Tag Management"
        tab_item_description = "OpenShift Tag Management Setting tab"
        tab_item_fields = tab_sub_form
        tab_item = create_tab_item(tab_item_name, tab_item_title,
                                   tab_item_description, tab_item_fields)
        return tab_item
Esempio n. 2
0
    def _build_tag_key(self):
        """
        Generate tag management form component

        Returns:
            (Dict) - Tab Item
        """
        tag_key_text_name = f"{SETTINGS_PREFIX}.tag_management.form-text"
        tag_key_text_context = (
            "Enable your data source labels to be used as tag keys for report grouping and filtering."
            + " Changes will be reflected within 24 hours. <link>Learn more</link>"
        )
        doc_link = dict(
            href=generate_doc_link("managing_cost_data_using_tagging/configuring_tags_and_labels_in_cost_management")
        )
        tag_key_text = create_plain_text_with_doc(tag_key_text_name, tag_key_text_context, doc_link)
        components = []
        for providerName in obtainTagKeysProvidersParams:
            tag_view = obtainTagKeysProvidersParams[providerName]["tag_view"]
            query_handler = obtainTagKeysProvidersParams[providerName]["query_handler"]
            enabled_tag_keys = obtainTagKeysProvidersParams[providerName]["enabled_tag_keys"]
            available, enabled = self._obtain_tag_keys(tag_view, query_handler, enabled_tag_keys)
            avail_objs = [{"value": tag_key, "label": tag_key} for tag_key in available]
            dual_list_options = {
                "options": avail_objs,
                "leftTitle": obtainTagKeysProvidersParams[providerName]["leftLabel"],
                "rightTitle": obtainTagKeysProvidersParams[providerName]["rightLabel"],
                "noValueTitle": "No enabled tag keys",
                "noOptionsTitle": "No available tag keys",
                "filterOptionsTitle": "Filter by available tag keys",
                "filterValueTitle": "Filter by enabled tag keys",
                "filterValueText": "Remove your filter to see all enabled tag keys",
                "filterOptionsText": "Remove your filter to see all available tag keys",
                "initialValue": enabled,
                "clearedValue": [],
            }
            dual_list_name = f"{self._get_tag_management_prefix(providerName)}.enabled"
            dual_list_title = obtainTagKeysProvidersParams[providerName]["title"]
            components.append(create_plain_text(f"{SETTINGS_PREFIX}.{providerName}.title", dual_list_title, "h2"))
            components.append(create_dual_list_select(dual_list_name, **dual_list_options))
        sub_form_name = f"{SETTINGS_PREFIX}.tag_managment.subform"
        sub_form_title = "Enable tags and labels"
        sub_form_fields = [tag_key_text]
        sub_form_fields.extend(components)
        sub_form = create_subform(sub_form_name, sub_form_title, sub_form_fields)

        return sub_form
Esempio n. 3
0
File: ocp.py Progetto: dccurtis/koku
    def _build_tag_key(self):
        """
        Generate tag_key tab component

        Returns:
            (Dict) - Tab Item
        """
        tag_key_text_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.form-text"
        tag_key_text_context = (
            "Enable your OpenShift label names to be used as tag keys for report grouping and filtering."
        )
        tag_key_text = create_plain_text(tag_key_text_name,
                                         tag_key_text_context)
        available, enabled = self._obtain_tag_keys()
        avail_objs = [{
            "value": tag_key,
            "label": tag_key
        } for tag_key in available]
        dual_list_options = {
            "options": avail_objs,
            "leftTitle": "Available tags",
            "rightTitle": "Enabled tags",
            "noValueTitle": "No enabled tag keys",
            "noOptionsTitle": "No available tag keys",
            "filterOptionsTitle": "Filter by available tag keys",
            "filterValueTitle": "Filter by enabled tag keys",
            "filterValueText":
            "Remove your filter to see all enabled tag keys",
            "filterOptionsText":
            "Remove your filter to see all available tag keys",
            "initialValue": enabled,
        }
        dual_list_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.enabled"
        dual_list_select = create_dual_list_select(dual_list_name,
                                                   **dual_list_options)
        sub_form_name = f"{OPENSHIFT_TAG_MGMT_SETTINGS_PREFIX}.subform"
        sub_form_title = "Enable OpenShift labels"
        sub_form_fields = [tag_key_text, dual_list_select]
        sub_form = create_subform(sub_form_name, sub_form_title,
                                  sub_form_fields)

        return sub_form
Esempio n. 4
0
    def _build_components(self):
        """
        Generate cost management form component
        """
        tag_key_text_name = f"{SETTINGS_PREFIX}.tag_management.form-text"
        enable_tags_title = create_plain_text(tag_key_text_name,
                                              "Enable tags and labels", "h2")
        tag_key_text_context = (
            "Enable your data source labels to be used as tag keys for report grouping and filtering."
            +
            " Changes will be reflected within 24 hours. <link>Learn more</link>"
        )
        doc_link = dict(href=generate_doc_link(
            "html-single/managing_cost_data_using_tagging/index" +
            "#assembly-configuring-tags-and-labels-in-cost-management"))
        tag_key_text = create_plain_text_with_doc(tag_key_text_name,
                                                  tag_key_text_context,
                                                  doc_link)

        sub_form_fields = []
        avail_objs = []
        enabled_objs = []
        for providerName in obtainTagKeysProvidersParams:
            tag_view = obtainTagKeysProvidersParams[providerName]["tag_view"]
            query_handler = obtainTagKeysProvidersParams[providerName][
                "query_handler"]
            enabled_tag_keys = obtainTagKeysProvidersParams[providerName][
                "enabled_tag_keys"]
            available, enabled = self._obtain_tag_keys(tag_view, query_handler,
                                                       enabled_tag_keys)
            avail_objs.append({
                "label":
                obtainTagKeysProvidersParams[providerName]["title"],
                "hasBadge":
                "true",
                "children": [{
                    "value": "".join([providerName, "-", tag_key]),
                    "label": tag_key
                } for tag_key in available],
            })
            if enabled:
                enabled_objs.extend("".join([providerName, "-", tag_key])
                                    for tag_key in enabled)

        dual_list_options = {
            "isTree": "true",
            "options": avail_objs,
            "leftTitle": "Disabled tags/labels",
            "rightTitle": "Enabled tags/labels",
            "initialValue": enabled_objs,
            "clearedValue": [],
        }

        dual_list_name = f'{"api.settings.tag-management.enabled"}'
        tags_and_labels = create_dual_list_select(dual_list_name,
                                                  **dual_list_options)

        for field in enable_tags_title, tag_key_text, tags_and_labels:
            sub_form_fields.append(field)

        # currency settings TODO: only show in dev mode right now
        if settings.DEVELOPMENT:
            currency_select_name = f'{"api.settings.currency"}'
            currency_text_context = "Select the preferred currency view for your organization."
            currency_title = create_plain_text(currency_select_name,
                                               "Currency", "h2")
            currency_select_text = create_plain_text(currency_select_name,
                                                     currency_text_context,
                                                     "p")
            currency_options = {
                "options": get_currency_options(),
                "initialValue": get_selected_currency_or_setup(self.schema),
                "FormGroupProps": {
                    "style": {
                        "width": "400px"
                    }
                },
            }
            currency = create_select(currency_select_name, **currency_options)

            idx = 0
            for field in currency_title, currency_select_text, currency:
                sub_form_fields.insert(idx, field)
                idx += 1

        customer = self.request.user.customer
        customer_specific_providers = Provider.objects.filter(
            customer=customer)
        has_aws_providers = customer_specific_providers.filter(
            type__icontains=Provider.PROVIDER_AWS).exists()

        # cost_type plan settings
        if has_aws_providers:
            cost_type_select_name = f'{"api.settings.cost_type"}'
            cost_type_text_context = (
                "Select the preferred way of calculating upfront costs, either through savings "
                "plans or subscription fees. This feature is available for Amazon Web Services cost only."
            )
            cost_type_title = create_plain_text(
                cost_type_select_name,
                "Show cost as (Amazon Web Services Only)", "h2")
            cost_type_select_text = create_plain_text(cost_type_select_name,
                                                      cost_type_text_context,
                                                      "p")
            cost_type_options = {
                "options": get_cost_type_options(),
                "initialValue": get_selected_cost_type_or_setup(self.schema),
                "FormGroupProps": {
                    "style": {
                        "width": "400px"
                    }
                },
            }
            cost_type = create_select(cost_type_select_name,
                                      **cost_type_options)

            for field in cost_type_title, cost_type_select_text, cost_type:
                sub_form_fields.append(field)

        sub_form_name = f"{SETTINGS_PREFIX}.settings.subform"
        sub_form_title = ""
        sub_form = create_subform(sub_form_name, sub_form_title,
                                  sub_form_fields)

        return sub_form