def __init__(self, request, *args, **kwargs):
        super(UploadFileForm, self).__init__(request, *args, **kwargs)

        sahara = saharaclient.client(request)
        self._generate_plugin_version_fields(sahara)

        self.fields['template_file'] = forms.FileField(label=_("Template"))
Exemple #2
0
    def get_context_data(self, request):
        cluster_id = self.tab_group.kwargs['cluster_id']
        try:
            sahara = saharaclient.client(request)
            cluster = sahara.clusters.get(cluster_id)
            for ng in cluster.node_groups:
                if ng["flavor_id"]:
                    ng["flavor_name"] = (nova.flavor_get(
                        request, ng["flavor_id"]).name)
                if ng["floating_ip_pool"]:
                    ng["floating_ip_pool_name"] = (
                        self._get_floating_ip_pool_name(
                            request, ng["floating_ip_pool"]))

                if ng.get("node_group_template_id", None):
                    ng["node_group_template"] = saharaclient.safe_call(
                        sahara.node_group_templates.get,
                        ng["node_group_template_id"])

                ng["security_groups_full"] = helpers.get_security_groups(
                    request, ng["security_groups"])
        except Exception:
            cluster = {}
            exceptions.handle(request, _("Unable to get node group details."))

        return {"cluster": cluster}
Exemple #3
0
    def _generate_plugin_version_fields(self, request):
        sahara = saharaclient.client(request)
        plugins = sahara.plugins.list()
        plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]

        self.fields["plugin_name"] = forms.ChoiceField(
            label=_("Plugin Name"),
            choices=plugin_choices,
            widget=forms.Select(attrs={
                "class": "switchable",
                "data-slug": "plugin"
            }))

        for plugin in plugins:
            field_name = plugin.name + "_version"
            choice_field = forms.ChoiceField(
                label=_("Version"),
                required=False,
                choices=[(version, version) for version in plugin.versions],
                widget=forms.Select(
                    attrs={
                        "class": "switched",
                        "data-switch-on": "plugin",
                        "data-plugin-" + plugin.name: plugin.title
                    }))
            self.fields[field_name] = choice_field
Exemple #4
0
    def __init__(self, request, *args, **kwargs):
        super(UploadFileForm, self).__init__(request, *args, **kwargs)

        sahara = saharaclient.client(request)
        self._generate_plugin_version_fields(sahara)

        self.fields['template_file'] = forms.FileField(label=_("Template"))
Exemple #5
0
    def get_context_data(self, request):
        cluster_id = self.tab_group.kwargs['cluster_id']
        try:
            sahara = saharaclient.client(request)
            cluster = sahara.clusters.get(cluster_id)
            for ng in cluster.node_groups:
                if ng["flavor_id"]:
                    ng["flavor_name"] = (
                        nova.flavor_get(request, ng["flavor_id"]).name)
                if ng["floating_ip_pool"]:
                    ng["floating_ip_pool_name"] = (
                        self._get_floating_ip_pool_name(
                            request, ng["floating_ip_pool"]))

                if ng.get("node_group_template_id", None):
                    ng["node_group_template"] = saharaclient.safe_call(
                        sahara.node_group_templates.get,
                        ng["node_group_template_id"])

                ng["security_groups_full"] = helpers.get_security_groups(
                    request, ng["security_groups"])
        except Exception:
            cluster = {}
            exceptions.handle(request,
                              _("Unable to get node group details."))

        return {"cluster": cluster}
def populate_anti_affinity_choices(self, request, context):
    try:
        sahara = saharaclient.client(request)
        plugin, version = whelpers.get_plugin_and_hadoop_version(request)

        version_details = sahara.plugins.get_version_details(plugin, version)
        process_choices = []
        for processes in version_details.node_processes.values():
            for process in processes:
                process_choices.append((process, process))

        cluster_template_id = request.REQUEST.get("cluster_template_id", None)
        if cluster_template_id is None:
            selected_processes = request.REQUEST.get("aa_groups", [])
        else:
            cluster_template = (
                sahara.cluster_templates.get(cluster_template_id))
            selected_processes = cluster_template.anti_affinity

        checked_dict = dict()

        for process in selected_processes:
            checked_dict[process] = process

        self.fields['anti_affinity'].initial = checked_dict
    except Exception:
        process_choices = []
        exceptions.handle(request,
                          _("Unable to populate anti-affinity processes."))
    return process_choices
Exemple #7
0
    def _generate_plugin_version_fields(self, request):
        sahara = saharaclient.client(request)
        plugins = sahara.plugins.list()
        plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]

        self.fields["plugin_name"] = forms.ChoiceField(
            label=_("Plugin Name"),
            choices=plugin_choices,
            widget=forms.Select(attrs={"class": "switchable", "data-slug": "plugin"}),
        )

        for plugin in plugins:
            field_name = plugin.name + "_version"
            choice_field = forms.ChoiceField(
                label=_("Version"),
                required=False,
                choices=[(version, version) for version in plugin.versions],
                widget=forms.Select(
                    attrs={"class": "switched", "data-switch-on": "plugin", "data-plugin-" + plugin.name: plugin.title}
                ),
            )
            self.fields[field_name] = choice_field
Exemple #8
0
    def get_cluster_instances_data(self):
        cluster_id = self.tab_group.kwargs['cluster_id']

        try:
            sahara = saharaclient.client(self.request)
            cluster = sahara.clusters.get(cluster_id)

            instances = []
            for ng in cluster.node_groups:
                for instance in ng["instances"]:
                    instances.append(Instance(
                        name=instance["instance_name"],
                        id=instance["instance_id"],
                        internal_ip=instance.get("internal_ip",
                                                 "Not assigned"),
                        management_ip=instance.get("management_ip",
                                                   "Not assigned")))
        except Exception:
            instances = []
            exceptions.handle(self.request,
                              _("Unable to fetch instance details."))
        return instances
Exemple #9
0
    def get_cluster_instances_data(self):
        cluster_id = self.tab_group.kwargs['cluster_id']

        try:
            sahara = saharaclient.client(self.request)
            cluster = sahara.clusters.get(cluster_id)

            instances = []
            for ng in cluster.node_groups:
                for instance in ng["instances"]:
                    instances.append(
                        Instance(
                            name=instance["instance_name"],
                            id=instance["instance_id"],
                            internal_ip=instance.get("internal_ip",
                                                     "Not assigned"),
                            management_ip=instance.get("management_ip",
                                                       "Not assigned")))
        except Exception:
            instances = []
            exceptions.handle(self.request,
                              _("Unable to fetch instance details."))
        return instances
Exemple #10
0
    def get_context_data(self, request):
        cluster_id = self.tab_group.kwargs['cluster_id']
        cluster_info = {}
        try:
            sahara = saharaclient.client(request)
            cluster = sahara.clusters.get(cluster_id)

            for info_key, info_val in cluster.info.items():
                for key, val in info_val.items():
                    if str(val).startswith(('http://', 'https://')):
                        cluster.info[info_key][key] = build_link(val)

            base_image = glance.image_get(request, cluster.default_image_id)

            if getattr(cluster, 'cluster_template_id', None):
                cluster_template = saharaclient.safe_call(
                    sahara.cluster_templates.get, cluster.cluster_template_id)
            else:
                cluster_template = None

            if getattr(cluster, 'neutron_management_network', None):
                net_id = cluster.neutron_management_network
                network = neutron.network_get(request, net_id)
                net_name = network.name_or_id
            else:
                net_name = None

            cluster_info.update({
                "cluster": cluster,
                "base_image": base_image,
                "cluster_template": cluster_template,
                "network": net_name
            })
        except Exception as e:
            LOG.error("Unable to fetch cluster details: %s" % str(e))

        return cluster_info
Exemple #11
0
    def get_context_data(self, request):
        cluster_id = self.tab_group.kwargs['cluster_id']
        cluster_info = {}
        try:
            sahara = saharaclient.client(request)
            cluster = sahara.clusters.get(cluster_id)

            for info_key, info_val in cluster.info.items():
                for key, val in info_val.items():
                    if str(val).startswith(('http://', 'https://')):
                        cluster.info[info_key][key] = build_link(val)

            base_image = glance.image_get(request,
                                          cluster.default_image_id)

            if getattr(cluster, 'cluster_template_id', None):
                cluster_template = saharaclient.safe_call(
                    sahara.cluster_templates.get,
                    cluster.cluster_template_id)
            else:
                cluster_template = None

            if getattr(cluster, 'neutron_management_network', None):
                net_id = cluster.neutron_management_network
                network = neutron.network_get(request, net_id)
                net_name = network.name_or_id
            else:
                net_name = None

            cluster_info.update({"cluster": cluster,
                                 "base_image": base_image,
                                 "cluster_template": cluster_template,
                                 "network": net_name})
        except Exception as e:
            LOG.error("Unable to fetch cluster details: %s" % str(e))

        return cluster_info
Exemple #12
0
    def __init__(self, request, *args, **kwargs):
        super(SelectPluginAction, self).__init__(request, *args, **kwargs)

        sahara = saharaclient.client(request)
        self._generate_plugin_version_fields(sahara)
Exemple #13
0
    def __init__(self, request, *args, **kwargs):
        super(SelectPluginAction, self).__init__(request, *args, **kwargs)

        sahara = saharaclient.client(request)
        self._generate_plugin_version_fields(sahara)