Ejemplo n.º 1
0
    def _get_floating_ip_pool_name(self, request, pool_id):
        pools = [
            pool for pool in neutron.floating_ip_pools_list(request)
            if pool.id == pool_id
        ]

        return pools[0].name if pools else pool_id
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        try:
            request = args[0]
            template_string = ""

            if "template_upload" in kwargs:
                template_upload = kwargs.pop('template_upload')
                super(ImportNodegroupTemplateDetailsForm, self).__init__(
                    *args, **kwargs)

                template_string = template_upload.read()
                self.fields["template"].initial = template_string

            else:
                super(ImportNodegroupTemplateDetailsForm, self).__init__(
                    *args, **kwargs)
                template_string = self.data["template"]

            template_json = json.loads(template_string)
            template_json = template_json["node_group_template"]

            security_group_list = neutron.security_group_list(request)
            security_group_choices = \
                [(sg.id, sg.name) for sg in security_group_list]
            self.fields["security_groups"].choices = security_group_choices

            pools = neutron.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))
            self.fields["floating_ip_pool"].choices = pool_choices

            flavors = nova_utils.flavor_list(request)
            if flavors:
                self.fields["flavor"].choices = nova_utils.sort_flavor_list(
                    request, flavors)
            else:
                self.fields["flavor"].choices = []

            version = (template_json.get("hadoop_version", None) or
                       template_json["plugin_version"])
            self.fields["image_id"].choices = \
                self._populate_image_choices(request,
                                             template_json["plugin_name"],
                                             version)
        except (ValueError, KeyError):
            raise exceptions.BadRequest(_("Could not parse template"))
        except Exception:
            exceptions.handle(request)
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        try:
            request = args[0]
            template_string = ""

            if "template_upload" in kwargs:
                template_upload = kwargs.pop('template_upload')
                super(ImportNodegroupTemplateDetailsForm,
                      self).__init__(*args, **kwargs)

                template_string = template_upload.read()
                self.fields["template"].initial = template_string

            else:
                super(ImportNodegroupTemplateDetailsForm,
                      self).__init__(*args, **kwargs)
                template_string = self.data["template"]

            template_json = json.loads(template_string)
            template_json = template_json["node_group_template"]

            security_group_list = neutron.security_group_list(request)
            security_group_choices = \
                [(sg.id, sg.name) for sg in security_group_list]
            self.fields["security_groups"].choices = security_group_choices

            pools = neutron.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))
            self.fields["floating_ip_pool"].choices = pool_choices

            flavors = nova_utils.flavor_list(request)
            if flavors:
                self.fields["flavor"].choices = nova_utils.sort_flavor_list(
                    request, flavors)
            else:
                self.fields["flavor"].choices = []

            version = (template_json.get("hadoop_version", None)
                       or template_json["plugin_version"])
            self.fields["image_id"].choices = \
                self._populate_image_choices(request,
                                             template_json["plugin_name"],
                                             version)
        except (ValueError, KeyError):
            raise exceptions.BadRequest(_("Could not parse template"))
        except Exception:
            exceptions.handle(request)
Ejemplo n.º 4
0
    def _get_floating_ip_pool_name(self, request, pool_id):
        pools = [pool for pool in neutron.floating_ip_pools_list(
            request) if pool.id == pool_id]

        return pools[0].name if pools else pool_id
Ejemplo n.º 5
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        hlps = helpers.Helpers(request)

        plugin, hadoop_version = (
            workflow_helpers.get_plugin_and_hadoop_version(request))

        if not saharaclient.SAHARA_AUTO_IP_ALLOCATION_ENABLED:
            pools = neutron.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))

            self.fields['floating_ip_pool'] = forms.ChoiceField(
                label=_("Floating IP Pool"),
                choices=pool_choices,
                required=False)

        self.fields["use_autoconfig"] = forms.BooleanField(
            label=_("Auto-configure"),
            help_text=_("If selected, instances of a node group will be "
                        "automatically configured during cluster "
                        "creation. Otherwise you should manually specify "
                        "configuration values."),
            required=False,
            widget=forms.CheckboxInput(),
            initial=True,
        )

        self.fields["proxygateway"] = forms.BooleanField(
            label=_("Proxy Gateway"),
            widget=forms.CheckboxInput(),
            help_text=_("Sahara will use instances of this node group to "
                        "access other cluster instances."),
            required=False)

        self.fields['is_public'] = acl_utils.get_is_public_form(
            _("node group template"))
        self.fields['is_protected'] = acl_utils.get_is_protected_form(
            _("node group template"))

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(), initial=plugin)
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(), initial=hadoop_version)

        self.fields["storage"].choices = storage_choices(request)

        node_parameters = hlps.get_general_node_group_configs(
            plugin, hadoop_version)
        for param in node_parameters:
            self.fields[param.name] = workflow_helpers.build_control(param)

        # when we copy or edit a node group template then
        # request contains valuable info in both GET and POST methods
        req = request.GET.copy()
        req.update(request.POST)
        if req.get("guide_template_type"):
            self.fields["guide_template_type"] = forms.CharField(
                required=False,
                widget=forms.HiddenInput(),
                initial=req.get("guide_template_type"))

        if is_cinder_enabled(request):
            volume_types = cinder.volume_type_list(request)
        else:
            volume_types = []

        self.fields['volume_type'].choices = [(None, _("No volume type"))] + \
                                             [(type.name, type.name)
                                              for type in volume_types]
Ejemplo n.º 6
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        hlps = helpers.Helpers(request)

        plugin, hadoop_version = (
            workflow_helpers.get_plugin_and_hadoop_version(request))

        if not saharaclient.SAHARA_FLOATING_IP_DISABLED:
            pools = neutron.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))

            self.fields['floating_ip_pool'] = forms.ChoiceField(
                label=_("Floating IP Pool"),
                choices=pool_choices,
                required=False)

        self.fields["use_autoconfig"] = forms.BooleanField(
            label=_("Auto-configure"),
            help_text=_("If selected, instances of a node group will be "
                        "automatically configured during cluster "
                        "creation. Otherwise you should manually specify "
                        "configuration values."),
            required=False,
            widget=forms.CheckboxInput(),
            initial=True,
        )

        self.fields["proxygateway"] = forms.BooleanField(
            label=_("Proxy Gateway"),
            widget=forms.CheckboxInput(),
            help_text=_("Sahara will use instances of this node group to "
                        "access other cluster instances."),
            required=False)

        self.fields['is_public'] = acl_utils.get_is_public_form(
            _("node group template"))
        self.fields['is_protected'] = acl_utils.get_is_protected_form(
            _("node group template"))

        if saharaclient.VERSIONS.active == '2':
            self.fields['boot_storage'] = forms.ChoiceField(
                label=_("Boot storage location"),
                help_text=_("Choose a boot mode"),
                choices=storage_choices(request),
                widget=forms.Select(
                    attrs={
                        "class": "boot_storage_field switchable",
                        'data-slug': 'boot_storage_loc'
                    }))

            self.fields['boot_volume_type'] = forms.ChoiceField(
                label=_("Boot volume type"),
                required=False,
                widget=forms.Select(
                    attrs={
                        "class":
                        "boot_volume_type_field switched",
                        "data-switch-on":
                        "boot_storage_loc",
                        "data-boot_storage_loc-cinder_volume":
                        _('Boot volume type')
                    }))

            self.fields['boot_volume_local_to_instance'] = forms.BooleanField(
                label=_("Boot volume local to instance"),
                required=False,
                help_text=_("Boot volume locality"),
                widget=forms.CheckboxInput(
                    attrs={
                        "class":
                        "boot_volume_local_to_instance_field switched",
                        "data-switch-on":
                        "boot_storage_loc",
                        "data-boot_storage_loc-cinder_volume":
                        _('Boot volume local to instance')
                    }))

            self.fields['boot_volume_availability_zone'] = forms.ChoiceField(
                label=_("Boot volume availability Zone"),
                choices=self.populate_volumes_availability_zone_choices(
                    request, None),
                help_text=_("Create boot volume in this availability zone."),
                required=False,
                widget=forms.Select(
                    attrs={
                        "class":
                        "boot_volume_availability_zone_field switched",
                        "data-switch-on":
                        "boot_storage_loc",
                        "data-boot_storage_loc-cinder_volume":
                        _('Boot volume availability zone')
                    }))

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(), initial=plugin)
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(), initial=hadoop_version)

        self.fields["storage"].choices = storage_choices(request)

        node_parameters = hlps.get_general_node_group_configs(
            plugin, hadoop_version)
        for param in node_parameters:
            self.fields[param.name] = workflow_helpers.build_control(param)

        # when we copy or edit a node group template then
        # request contains valuable info in both GET and POST methods
        req = request.GET.copy()
        req.update(request.POST)
        if req.get("guide_template_type"):
            self.fields["guide_template_type"] = forms.CharField(
                required=False,
                widget=forms.HiddenInput(),
                initial=req.get("guide_template_type"))

        if is_cinder_enabled(request):
            volume_types = cinder.volume_type_list(request)
        else:
            volume_types = []

        self.fields['volume_type'].choices = [(None, _("No volume type"))] + \
                                             [(type.name, type.name)
                                              for type in volume_types]

        if saharaclient.VERSIONS.active == '2':
            self.fields['boot_volume_type'].choices = (
                self.fields['volume_type'].choices)
Ejemplo n.º 7
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        hlps = helpers.Helpers(request)

        plugin, hadoop_version = (
            workflow_helpers.get_plugin_and_hadoop_version(request))

        if not saharaclient.SAHARA_FLOATING_IP_DISABLED:
            pools = neutron.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))

            self.fields['floating_ip_pool'] = forms.ChoiceField(
                label=_("Floating IP Pool"),
                choices=pool_choices,
                required=False)

        self.fields["use_autoconfig"] = forms.BooleanField(
            label=_("Auto-configure"),
            help_text=_("If selected, instances of a node group will be "
                        "automatically configured during cluster "
                        "creation. Otherwise you should manually specify "
                        "configuration values."),
            required=False,
            widget=forms.CheckboxInput(),
            initial=True,
        )

        self.fields["proxygateway"] = forms.BooleanField(
            label=_("Proxy Gateway"),
            widget=forms.CheckboxInput(),
            help_text=_("Sahara will use instances of this node group to "
                        "access other cluster instances."),
            required=False)

        self.fields['is_public'] = acl_utils.get_is_public_form(
            _("node group template"))
        self.fields['is_protected'] = acl_utils.get_is_protected_form(
            _("node group template"))

        if saharaclient.VERSIONS.active == '2':
            self.fields['boot_storage'] = forms.ChoiceField(
                label=_("Boot storage location"),
                help_text=_("Choose a boot mode"),
                choices=storage_choices(request),
                widget=forms.Select(attrs={
                    "class": "boot_storage_field switchable",
                    'data-slug': 'boot_storage_loc'
                }))

            self.fields['boot_volume_type'] = forms.ChoiceField(
                label=_("Boot volume type"),
                required=False,
                widget=forms.Select(attrs={
                    "class": "boot_volume_type_field switched",
                    "data-switch-on": "boot_storage_loc",
                    "data-boot_storage_loc-cinder_volume":
                        _('Boot volume type')
                })
            )

            self.fields['boot_volume_local_to_instance'] = forms.BooleanField(
                label=_("Boot volume local to instance"),
                required=False,
                help_text=_("Boot volume locality"),
                widget=forms.CheckboxInput(attrs={
                    "class": "boot_volume_local_to_instance_field switched",
                    "data-switch-on": "boot_storage_loc",
                    "data-boot_storage_loc-cinder_volume":
                        _('Boot volume local to instance')
                })
            )

            self.fields['boot_volume_availability_zone'] = forms.ChoiceField(
                label=_("Boot volume availability Zone"),
                choices=self.populate_volumes_availability_zone_choices(
                    request, None),
                help_text=_("Create boot volume in this availability zone."),
                required=False,
                widget=forms.Select(attrs={
                    "class": "boot_volume_availability_zone_field switched",
                    "data-switch-on": "boot_storage_loc",
                    "data-boot_storage_loc-cinder_volume":
                        _('Boot volume availability zone')
                })
            )

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=plugin
        )
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=hadoop_version
        )

        self.fields["storage"].choices = storage_choices(request)

        node_parameters = hlps.get_general_node_group_configs(plugin,
                                                              hadoop_version)
        for param in node_parameters:
            self.fields[param.name] = workflow_helpers.build_control(param)

        # when we copy or edit a node group template then
        # request contains valuable info in both GET and POST methods
        req = request.GET.copy()
        req.update(request.POST)
        if req.get("guide_template_type"):
            self.fields["guide_template_type"] = forms.CharField(
                required=False,
                widget=forms.HiddenInput(),
                initial=req.get("guide_template_type"))

        if is_cinder_enabled(request):
            volume_types = cinder.volume_type_list(request)
        else:
            volume_types = []

        self.fields['volume_type'].choices = [(None, _("No volume type"))] + \
                                             [(type.name, type.name)
                                              for type in volume_types]

        if saharaclient.VERSIONS.active == '2':
            self.fields['boot_volume_type'].choices = (
                self.fields['volume_type'].choices)