Exemple #1
0
class JobExecutionExistingGeneralConfigAction(JobExecutionGeneralConfigAction):
    cluster = forms.ChoiceField(
        label=_("Cluster"),
        initial=(None, "None"),
        widget=forms.Select(attrs={"class": "cluster_choice"}))

    is_public = acl_utils.get_is_public_form(_("job"))
    is_protected = acl_utils.get_is_protected_form(_("job"))

    def populate_cluster_choices(self, request, context):
        try:
            clusters = saharaclient.cluster_list(request)
        except Exception:
            clusters = []
            exceptions.handle(request,
                              _("Unable to fetch clusters."))
        choices = [(cl.id, "%s %s" % (cl.name,
                                      helpers.ALLOWED_STATUSES.get(cl.status)))
                   for cl in clusters if cl.status in helpers.ALLOWED_STATUSES]
        if not choices:
            choices = [(None, _("No clusters available"))]
        return choices

    class Meta(object):
        name = _("Job")
        help_text_template = "job_templates/_launch_job_help.html"
Exemple #2
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        plugin, hadoop_version = whelpers.\
            get_plugin_and_hadoop_version(request)

        if saharaclient.base.is_service_enabled(request, 'network'):
            self.fields["neutron_management_network"] = forms.ChoiceField(
                label=_("Neutron Management Network"),
                choices=self.populate_neutron_management_network_choices(
                    request, {})
            )

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

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=plugin
        )
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=hadoop_version
        )
class JobExecutionGeneralConfigAction(workflows.Action):
    job_input = forms.DynamicChoiceField(label=_("Input"),
                                         initial=(None, "None"),
                                         add_item_link=DATA_SOURCE_CREATE_URL,
                                         required=False)

    job_output = forms.DynamicChoiceField(label=_("Output"),
                                          initial=(None, "None"),
                                          add_item_link=DATA_SOURCE_CREATE_URL,
                                          required=False)

    is_public = acl_utils.get_is_public_form(_("job"))
    is_protected = acl_utils.get_is_protected_form(_("job"))

    def __init__(self, request, *args, **kwargs):
        super(JobExecutionGeneralConfigAction,
              self).__init__(request, *args, **kwargs)
        req = request.GET or request.POST
        if req.get("job_id", None) is None:
            self.fields["job"] = forms.ChoiceField(label=_("Job"))
            self.fields["job"].choices = self.populate_job_choices(request)
        else:
            self.fields["job"] = forms.CharField(widget=forms.HiddenInput(),
                                                 initial=req.get(
                                                     "job_id", None))

    def populate_job_input_choices(self, request, context):
        return self.get_data_source_choices(request, context)

    def populate_job_output_choices(self, request, context):
        return self.get_data_source_choices(request, context)

    def get_data_source_choices(self, request, context):
        try:
            data_sources = saharaclient.data_source_list(request)
        except Exception:
            data_sources = []
            exceptions.handle(request, _("Unable to fetch data sources."))

        choices = [(data_source.id, data_source.name)
                   for data_source in data_sources]
        choices.insert(0, (None, 'None'))

        return choices

    def populate_job_choices(self, request):
        try:
            jobs = saharaclient.job_list(request)
        except Exception:
            jobs = []
            exceptions.handle(request, _("Unable to fetch jobs."))

        choices = [(job.id, job.name) for job in jobs]

        return choices

    class Meta(object):
        name = _("Job")
        help_text_template = "job_templates/_launch_job_help.html"
Exemple #4
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        plugin, hadoop_version = whelpers.\
            get_plugin_and_hadoop_version(request)

        if saharaclient.base.is_service_enabled(request, 'network'):
            self.fields["neutron_management_network"] = forms.ChoiceField(
                label=_("Neutron Management Network"),
                choices=self.populate_neutron_management_network_choices(
                    request, {}))

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

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(), initial=plugin)
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(), initial=hadoop_version)
Exemple #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]
Exemple #6
0
    def __init__(self, request, *args, **kwargs):
        super(JobBinaryCreateForm, self).__init__(request, *args, **kwargs)

        self.help_text_template = "job_binaries/_create_job_binary_help.html"

        self.fields["job_binary_name"] = forms.CharField(label=_("Name"))

        self.fields["job_binary_type"] = forms.ChoiceField(
            label=_("Storage type"),
            widget=forms.Select(attrs={
                'class': 'switchable',
                'data-slug': 'jb_type'
            }))

        self.fields["job_binary_url"] = forms.CharField(
            label=_("URL"),
            required=False,
            widget=LabeledInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('URL')
                }))

        self.fields["job_binary_manila_share"] = forms.ChoiceField(
            label=_("Share"),
            required=False,
            widget=forms.Select(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-manila': _('Share')
                }))

        self.fields["job_binary_manila_path"] = forms.CharField(
            label=_("Path"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-manila': _('Path')
                }))

        self.fields["job_binary_internal"] = forms.ChoiceField(
            label=_("Internal binary"),
            required=False,
            widget=forms.Select(
                attrs={
                    'class': 'switched switchable',
                    'data-slug': 'jb_internal',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-internal-db': _('Internal Binary')
                }))

        self.fields["job_binary_file"] = forms.FileField(
            label=_("Upload File"),
            required=False,
            widget=forms.ClearableFileInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-uploadfile': _("Upload File")
                }))

        self.fields["job_binary_script_name"] = forms.CharField(
            label=_("Script name"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-newscript': _("Script name")
                }))

        self.fields["job_binary_script"] = forms.CharField(
            label=_("Script text"),
            required=False,
            widget=forms.Textarea(
                attrs={
                    'rows': 4,
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-newscript': _("Script text")
                }))

        self.fields["job_binary_username"] = forms.CharField(
            label=_("Username"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('Username')
                }))

        self.fields["job_binary_password"] = forms.CharField(
            label=_("Password"),
            required=False,
            widget=forms.PasswordInput(
                attrs={
                    'autocomplete': 'off',
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('Password')
                }))

        self.fields["job_binary_description"] = (forms.CharField(
            label=_("Description"), required=False, widget=forms.Textarea()))

        self.fields["is_public"] = acl_utils.get_is_public_form(
            _("job binary"))
        self.fields["is_protected"] = acl_utils.get_is_protected_form(
            _("job binary"))

        self.fields["job_binary_type"].choices =\
            [("internal-db", "Internal database"),
             ("swift", "Swift")]

        self.fields["job_binary_internal"].choices =\
            self.populate_job_binary_internal_choices(request)

        if saharaclient.base.is_service_enabled(request, 'share'):
            self.fields["job_binary_type"].choices.append(("manila", "Manila"))
            self.fields["job_binary_manila_share"].choices = (
                self.populate_job_binary_manila_share_choices(request))

        self.load_form_values()
Exemple #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)
Exemple #8
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 = network.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
        )
        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"))

        try:
            volume_types = cinder.volume_type_list(request)
        except Exception:
            exceptions.handle(request,
                              _("Unable to get volume type list."))

        self.fields['volume_type'].choices = [(None, _("No volume type"))] + \
                                             [(type.name, type.name)
                                              for type in volume_types]
class GeneralConfigAction(workflows.Action):
    hidden_configure_field = forms.CharField(
        required=False,
        widget=forms.HiddenInput(attrs={"class": "hidden_configure_field"}))

    hidden_to_delete_field = forms.CharField(
        required=False,
        widget=forms.HiddenInput(attrs={"class": "hidden_to_delete_field"}))

    cluster_template_name = forms.CharField(label=_("Template Name"))

    description = forms.CharField(label=_("Description"),
                                  required=False,
                                  widget=forms.Textarea(attrs={'rows': 4}))

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

    is_public = acl_utils.get_is_public_form(_("cluster template"))
    is_protected = acl_utils.get_is_protected_form(_("cluster template"))

    anti_affinity = aa.anti_affinity_field()

    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)
        plugin, hadoop_version = whelpers.\
            get_plugin_and_hadoop_version(request)

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

    populate_anti_affinity_choices = aa.populate_anti_affinity_choices

    def get_help_text(self):
        extra = dict()
        plugin_name, hadoop_version = whelpers\
            .get_plugin_and_hadoop_version(self.request)

        extra["plugin_name"] = plugin_name
        extra["hadoop_version"] = hadoop_version

        plugin = saharaclient.plugin_get_version_details(
            self.request, plugin_name, hadoop_version)
        extra["deprecated"] = whelpers.is_version_of_plugin_deprecated(
            plugin, hadoop_version)
        return super(GeneralConfigAction, self).get_help_text(extra)

    def clean(self):
        cleaned_data = super(GeneralConfigAction, self).clean()
        if cleaned_data.get("hidden_configure_field", None) \
                == "create_nodegroup":
            self._errors = dict()
        return cleaned_data

    class Meta(object):
        name = _("Details")
        help_text_template = ("cluster_templates/_configure_general_help.html")
class GeneralConfigAction(workflows.Action):
    data_source_name = forms.CharField(label=_("Name"))

    data_source_type = forms.ChoiceField(
        label=_("Data Source Type"),
        widget=forms.Select(attrs={
            "class": "switchable",
            "data-slug": "ds_type"
        }))

    data_source_manila_share = forms.ChoiceField(
        label=_("Manila share"),
        required=False,
        widget=forms.Select(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-manila": _("Manila share")
            }))

    data_source_url = forms.CharField(
        label=_("URL"),
        widget=forms.TextInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-manila": _("Path on share"),
                "data-ds_type-swift": _("URL"),
                "data-ds_type-hdfs": _("URL"),
                "data-ds_type-maprfs": _("URL"),
                "data-ds_type-s3": _("URL"),
            }))

    data_source_credential_user = forms.CharField(
        label=_("Source username"),
        required=False,
        widget=forms.TextInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-swift": _("Source username")
            }))

    data_source_credential_pass = forms.CharField(widget=forms.PasswordInput(
        attrs={
            'class': 'switched',
            'data-switch-on': 'ds_type',
            'data-ds_type-swift': _("Source password"),
            'autocomplete': 'off'
        }),
                                                  label=_("Source password"),
                                                  required=False)

    data_source_credential_accesskey = forms.CharField(
        label=_("S3 accsss key"),
        required=False,
        widget=forms.TextInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-s3": _("S3 access key")
            }))

    data_source_credential_secretkey = forms.CharField(
        widget=forms.PasswordInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'ds_type',
                'data-ds_type-s3': _("S3 secret key"),
                'autocomplete': 'off'
            }),
        label=_("S3 secret key"),
        required=False)

    data_source_credential_endpoint = forms.CharField(
        label=_("S3 endpoint"),
        required=False,
        help_text=_("Endpoint should be specified without protocol"),
        widget=forms.TextInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-s3": _("S3 endpoint")
            }))

    data_source_credential_s3_ssl = forms.BooleanField(
        label=_("Use SSL"),
        required=False,
        initial=False,
        widget=forms.CheckboxInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-s3": _("Use SSL")
            }))

    data_source_credential_s3_bucket_in_path = forms.BooleanField(
        label=_("Use bucket in path"),
        required=False,
        initial=True,
        help_text=_("If checked, bucket will be in path instead of host"),
        widget=forms.CheckboxInput(
            attrs={
                "class": "switched",
                "data-switch-on": "ds_type",
                "data-ds_type-s3": _("Use bucket in path")
            }))

    data_source_description = forms.CharField(
        label=_("Description"),
        required=False,
        widget=forms.Textarea(attrs={'rows': 4}))

    is_public = acl_utils.get_is_public_form(_("data source"))
    is_protected = acl_utils.get_is_protected_form(_("data source"))

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

        self.fields["data_source_type"].choices = [("swift", "Swift"),
                                                   ("hdfs", "HDFS"),
                                                   ("maprfs", "MapR FS"),
                                                   ("s3", "S3")]
        # If Manila is running, enable it as a choice for a data source
        if saharaclient.base.is_service_enabled(request, 'share'):
            self.fields["data_source_type"].choices.append(
                ("manila", "Manila"))
            self.fields["data_source_manila_share"].choices = (
                self.populate_manila_share_choices(request))

    def populate_manila_share_choices(self, request):
        try:
            shares = manilaclient.share_list(request)
            choices = [(s.id, s.name) for s in shares]
        except Exception:
            exceptions.handle(request, _("Failed to get list of shares"))
            choices = []
        return choices

    class Meta(object):
        name = _("Create Data Source")
        help_text_template = "data_sources/_create_data_source_help.html"
Exemple #11
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)
Exemple #12
0
    def __init__(self, request, *args, **kwargs):
        super(JobBinaryCreateForm, self).__init__(request, *args, **kwargs)

        self.help_text_template = "job_binaries/_create_job_binary_help.html"

        self.fields["job_binary_name"] = forms.CharField(label=_("Name"))

        self.fields["job_binary_type"] = forms.ChoiceField(
            label=_("Storage type"),
            widget=forms.Select(
                attrs={
                    'class': 'switchable',
                    'data-slug': 'jb_type'
                }))

        self.fields["job_binary_url"] = forms.CharField(
            label=_("URL"),
            required=False,
            widget=LabeledInput(
                "swift",
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('URL')
                }))

        self.fields["job_binary_manila_share"] = forms.ChoiceField(
            label=_("Share"),
            required=False,
            widget=forms.Select(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-manila': _('Share')
                }))

        self.fields["job_binary_manila_path"] = forms.CharField(
            label=_("Path"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-manila': _('Path')
                }))

        self.fields["job_binary_internal"] = forms.ChoiceField(
            label=_("Internal binary"),
            required=False,
            widget=forms.Select(
                attrs={
                    'class': 'switched switchable',
                    'data-slug': 'jb_internal',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-internal-db': _('Internal Binary')
                }))

        self.fields["job_binary_file"] = forms.FileField(
            label=_("Upload File"),
            required=False,
            widget=forms.ClearableFileInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-uploadfile': _("Upload File")
                }))

        self.fields["job_binary_script_name"] = forms.CharField(
            label=_("Script name"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-newscript': _("Script name")
                }))

        self.fields["job_binary_script"] = forms.CharField(
            label=_("Script text"),
            required=False,
            widget=forms.Textarea(
                attrs={
                    'rows': 4,
                    'class': 'switched',
                    'data-switch-on': 'jb_internal',
                    'data-jb_internal-newscript': _("Script text")
                }))

        self.fields["job_binary_username"] = forms.CharField(
            label=_("Username"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('Username')
                }))

        self.fields["job_binary_password"] = forms.CharField(
            label=_("Password"),
            required=False,
            widget=forms.PasswordInput(
                attrs={
                    'autocomplete': 'off',
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-swift': _('Password')
                }))

        self.fields["job_binary_s3_url"] = forms.CharField(
            label=_("URL"),
            required=False,
            widget=LabeledInput(
                "s3",
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-s3': _('URL')
                }))

        self.fields["job_binary_s3_endpoint"] = forms.CharField(
            label=_("S3 Endpoint"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-s3': _('S3 Endpoint')
                }))

        self.fields["job_binary_access_key"] = forms.CharField(
            label=_("Access Key"),
            required=False,
            widget=forms.TextInput(
                attrs={
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-s3': _('Access Key')
                }))

        self.fields["job_binary_secret_key"] = forms.CharField(
            label=_("Secret Key"),
            required=False,
            widget=forms.PasswordInput(
                attrs={
                    'autocomplete': 'off',
                    'class': 'switched',
                    'data-switch-on': 'jb_type',
                    'data-jb_type-s3': _('Secret Key')
                }))

        self.fields["job_binary_description"] = (
            forms.CharField(label=_("Description"),
                            required=False,
                            widget=forms.Textarea()))

        self.fields["is_public"] = acl_utils.get_is_public_form(
            _("job binary"))
        self.fields["is_protected"] = acl_utils.get_is_protected_form(
            _("job binary"))

        self.fields["job_binary_type"].choices =\
            [("swift", "Swift"),
             ("s3", "S3")]

        if saharaclient.VERSIONS.active == '1.1':
            self.fields["job_binary_type"].choices.append(
                ("internal-db", "Internal database")
            )
            self.fields["job_binary_internal"].choices =\
                self.populate_job_binary_internal_choices(request)

        if saharaclient.base.is_service_enabled(request, 'share'):
            self.fields["job_binary_type"].choices.append(("manila", "Manila"))
            self.fields["job_binary_manila_share"].choices = (
                self.populate_job_binary_manila_share_choices(request))

        self.load_form_values()
Exemple #13
0
class GeneralConfigAction(workflows.Action):
    job_name = forms.CharField(label=_("Name"))

    job_type = forms.ChoiceField(label=_("Job Type"),
                                 widget=forms.Select(attrs={
                                     'class': 'switchable',
                                     'data-slug': 'jobtype'
                                 }))

    main_binary = forms.DynamicChoiceField(
        label=_("Choose a main binary"),
        required=False,
        help_text=_("Choose the binary which "
                    "should be used in this Job."),
        add_item_link=JOB_BINARY_CREATE_URL,
        widget=fields.DynamicSelectWidget(
            attrs={
                'class': 'switched',
                'data-switch-on': 'jobtype',
                'data-jobtype-pig': _("Choose a main binary"),
                'data-jobtype-hive': _("Choose a main binary"),
                'data-jobtype-shell': _("Choose a shell script"),
                'data-jobtype-spark': _("Choose a main binary"),
                'data-jobtype-storm': _("Choose a main binary"),
                'data-jobtype-mapreduce.streaming': _("Choose a main binary")
            }))

    job_description = forms.CharField(label=_("Description"),
                                      required=False,
                                      widget=forms.Textarea(attrs={'rows': 4}))
    is_public = acl_utils.get_is_public_form(_("job"))
    is_protected = acl_utils.get_is_protected_form(_("job"))

    def __init__(self, request, context, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, context, *args,
                                                  **kwargs)
        req = request.GET or request.POST
        if req.get("guide_job_type"):
            self.fields["job_type"].initial = (
                req.get("guide_job_type").lower())

    def populate_job_type_choices(self, request, context):
        choices = []
        choices_list = saharaclient.job_types_list(request)

        for choice in choices_list:
            job_type = choice.name.lower()
            if job_type in helpers.JOB_TYPE_MAP:
                choices.append((job_type, helpers.JOB_TYPE_MAP[job_type][0]))
        return choices

    def populate_main_binary_choices(self, request, context):
        job_binaries = saharaclient.job_binary_list(request)

        choices = [(job_binary.id, job_binary.name)
                   for job_binary in job_binaries]
        choices.insert(0, ('', _("-- not selected --")))
        return choices

    def clean(self):
        cleaned_data = super(workflows.Action, self).clean()
        job_type = cleaned_data.get("job_type", "")

        if job_type in ["Java", "MapReduce"]:
            cleaned_data['main_binary'] = None

        return cleaned_data

    class Meta(object):
        name = _("Create Job Template")
        help_text_template = "job_templates/_create_job_help.html"