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 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 _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
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
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.GET.get("cluster_template_id", None) if cluster_template_id is None: selected_processes = request.GET.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
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" version_choices = (sorted( [(version, version) for version in plugin.versions], reverse=True, key=lambda v: utils.smart_sort_helper(v[0])) ) choice_field = forms.ChoiceField( label=_("Version"), required=False, choices=version_choices, widget=forms.Select( attrs={"class": "switched", "data-switch-on": "plugin", "data-plugin-" + plugin.name: plugin.title}) ) self.fields[field_name] = choice_field
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"))
def get_context_data(self, request): cluster_id = self.tab_group.kwargs['cluster_id'] cluster = {} try: sahara = saharaclient.client(request) cluster = sahara.clusters.get(cluster_id) except Exception as e: LOG.error("Unable to fetch cluster details: %s" % str(e)) return {'cluster': cluster}
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) try: base_image = glance.image_get(request, cluster.default_image_id) except Exception: exceptions.handle( request, _("Unable to fetch base image details")) base_image = {} if getattr(cluster, 'cluster_template_id', None): cluster_template = saharaclient.safe_call( sahara.cluster_templates.get, cluster.cluster_template_id) else: cluster_template = None try: 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 except Exception: exceptions.handle( request, _("Unable to fetch network details")) net_name = None cluster_info.update({"cluster": cluster, "base_image": base_image, "cluster_template": cluster_template, "network": net_name}) if saharaclient.VERSIONS.active == '2': cluster_info["cluster"].hadoop_version = ( cluster_info["cluster"].plugin_version ) except Exception as e: LOG.error("Unable to fetch cluster details: %s" % str(e)) return cluster_info
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) try: base_image = glance.image_get(request, cluster.default_image_id) except Exception: exceptions.handle(request, _("Unable to fetch base image details")) base_image = {} if getattr(cluster, 'cluster_template_id', None): cluster_template = saharaclient.safe_call( sahara.cluster_templates.get, cluster.cluster_template_id) else: cluster_template = None try: 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 except Exception: exceptions.handle(request, _("Unable to fetch network details")) net_name = None cluster_info.update({ "cluster": cluster, "base_image": base_image, "cluster_template": cluster_template, "network": net_name }) if saharaclient.VERSIONS.active == '2': cluster_info["cluster"].hadoop_version = ( cluster_info["cluster"].plugin_version) except Exception as e: LOG.error("Unable to fetch cluster details: %s" % str(e)) return cluster_info
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
def __init__(self, request, *args, **kwargs): super(SelectPluginAction, self).__init__(request, *args, **kwargs) sahara = saharaclient.client(request) self._generate_plugin_version_fields(sahara)