class UpdateProfileForm(forms.SelfHandlingForm): profile_id = forms.CharField(widget=forms.HiddenInput()) name = forms.CharField(max_length=255, label=_("Name")) spec = forms.CharField( label=_("Spec"), widget=forms.Textarea( attrs={'rows': 6, 'readonly': 'readonly'}), help_text=_('Update the spec of a profile is not allowed')) metadata = forms.CharField( label=_("Metadata"), required=False, widget=forms.Textarea(attrs={'rows': 4}), help_text=_("YAML formatted metadata.")) def handle(self, request, data): opts = _populate_profile_params( name=data.get('name'), spec=None, metadata=data.get('metadata', {}) ) del opts['spec'] try: senlin.profile_update(request, data.get('profile_id'), **opts) messages.success(request, _('Your profile %s has been updated.') % opts['name']) return True except ValidationError as e: self.api_error(e.messages[0]) return False except Exception: redirect = reverse(INDEX_URL) msg = _('Unable to update profile') exceptions.handle(request, msg, redirect=redirect) return False
class CreateSfc(forms.SelfHandlingForm): sfc_name = forms.CharField(max_length=255, label=_('SFC Name')) is_symmetric = forms.BooleanField(required=False, label=_('Symmetric')) sfcr_ids = forms.CharField(widget=forms.Textarea( attrs={"placeholder": '[\n"sfcr_id_1",\n"sfcr_id_2"\n]'}), max_length=1024, label=_(' IDs')) vnf_instance_ids = forms.CharField(widget=forms.Textarea( attrs={ "placeholder": '[\n["vnf_id_1", "vnf_id_2"],\n["vnf_id_3", "vnf_id_4"]\n]' }), max_length=1024, label=_('VNF IDs')) def handle(self, request, data): try: sfc_spec = ni_nfvo_client.SfcSpec( sfc_name=data['sfc_name'], sfcr_ids=json.loads(data['sfcr_ids']), vnf_instance_ids=json.loads(data['vnf_instance_ids']), is_symmetric=data['is_symmetric']) sfc_id = ni_nfvo_sfc_api.set_sfc(sfc_spec) sfcs = ni_nfvo_sfc_api.get_sfcs() for sfc in sfcs: if sfc.id == sfc_id: return sfc raise Exception() except Exception as e: exceptions.handle(request, str(e))
class UpdateCertificate(forms.SelfHandlingForm): id = forms.CharField( label=_("ID"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) name = forms.CharField(label=_("Name"), min_length=1, max_length=255, required=True) description = forms.CharField(label=_("Description"), min_length=1, max_length=255, required=True) cert_data = forms.CharField(label=_("Data"), min_length=1, max_length=1024, required=True) key_data = forms.CharField(label=_("Key Data"), min_length=1, max_length=8000, widget=forms.Textarea(attrs={ 'cols': 80, 'rows': 15 }), required=True) password = forms.CharField(label=_("Password"), min_length=1, max_length=1024, widget=forms.PasswordInput(render_value=False), required=False) intermediate_data = forms.CharField( label=_("Intermediate Certificate Data"), min_length=1, max_length=8000, widget=forms.Textarea(attrs={ 'cols': 80, 'rows': 15 }), required=False) failure_url = 'horizon:project:a10ssl:index' def handle(self, request, context): LOG.debug("UpdateCertificate:handle(): context" % context) try: certificate = api.certificate_update(request, **context) msg = _('Certificate {0} was successfully updated.').format( context['id']) LOG.debug(msg) messages.success(request, msg) return certificate except Exception: msg = _('Failed to update certificate %s') % context['id'] LOG.exception(msg) redirect = reverse(self.failure_url) exceptions.handle(request, msg, redirect=redirect)
class CreatePluginForm(forms.SelfHandlingForm): name = forms.CharField(label=_("Plugin Name")) """ public = forms.ChoiceField( label=_("Public"), choices =[('false', _('False')), ('true', _('True'))], widget=forms.Select( attrs={'class': 'switchable', 'data-slug': 'slug-public'}, ) ) """ public = forms.BooleanField(label=_("Public"), required=False) callable = forms.BooleanField(label=_("Callable"), required=False) code = forms.CharField( label=_("Code"), widget=forms.Textarea( attrs={'class': 'switchable', 'data-slug': 'slug-code'}) ) parameters = forms.CharField( label=_("Parameters"), required=False, widget=forms.Textarea( attrs={'class': 'switchable', 'data-slug': 'slug-parameters-create'}), help_text=_("Plugin parameters") ) def handle(self, request, data): if not data["parameters"]: data["parameters"] = {} else: data["parameters"] = json.loads(data["parameters"]) try: plugin = iotronic.plugin_create(request, data["name"], data["public"], data["callable"], data["code"], data["parameters"]) LOG.debug("API REQ: %s", request) messages.success(request, _("Plugin created successfully.")) return plugin # except iot_exceptions.ClientException: except Exception: # LOG.debug("API REQ EXC: %s", request) # LOG.debug("API REQ (DICT): %s", exceptions.__dict__) exceptions.handle(request, _('Unable to create plugin.'))
class CreateVolumeType(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Name")) vol_type_description = forms.CharField( max_length=255, widget=forms.Textarea(attrs={ 'class': 'modal-body-fixed-width', 'rows': 4 }), label=_("Description"), required=False) def clean_name(self): cleaned_name = self.cleaned_data['name'] if len(cleaned_name.strip()) == 0: raise ValidationError(_('Volume type name can not be empty.')) return cleaned_name def handle(self, request, data): try: # Remove any new lines in the public key volume_type = cinder.volume_type_create( request, data['name'], data['vol_type_description']) messages.success( request, _('Successfully created volume type: %s') % data['name']) return volume_type except Exception: redirect = reverse("horizon:admin:volumes:index") exceptions.handle(request, _('Unable to create volume type.'), redirect=redirect)
class GroupBase(forms.SelfHandlingForm): """Base class to handle creation and update of security groups. Children classes must define two attributes: .. attribute:: success_message A success message containing the placeholder %s, which will be replaced by the group name. .. attribute:: error_message An error message containing the placeholder %s, which will be replaced by the error message. """ name = forms.CharField(label=_("Name"), max_length=255) description = forms.CharField(label=_("Description"), required=False, widget=forms.Textarea(attrs={'rows': 4})) def _call_network_api(self, request, data): """Call the underlying network API: Nova-network or Neutron. Used in children classes to create or update a group. """ raise NotImplementedError() def handle(self, request, data): try: sg = self._call_network_api(request, data) messages.success(request, self.success_message % sg.name) return sg except Exception: redirect = reverse("horizon:project:security_groups:index") exceptions.handle(request, self.error_message, redirect=redirect)
class TenantsTable(tables.DataTable): name = tables.Column('name', verbose_name=_('Name'), link=("horizon:identity:projects:detail"), form_field=forms.CharField(max_length=64), update_action=UpdateCell) description = tables.Column(lambda obj: getattr(obj, 'description', None), verbose_name=_('Description'), form_field=forms.CharField( widget=forms.Textarea(attrs={'rows': 4}), required=False), update_action=UpdateCell) id = tables.Column('id', verbose_name=_('Project ID')) enabled = tables.Column('enabled', verbose_name=_('Enabled'), status=True, filters=(filters.yesno, filters.capfirst), form_field=forms.BooleanField(label=_('Enabled'), required=False), update_action=UpdateCell) class Meta(object): name = "tenants" verbose_name = _("Projects") row_class = UpdateRow row_actions = (UpdateMembersLink, UpdateGroupsLink, UpdateProject, UsageLink, ModifyQuotas, DeleteTenantsAction, RescopeTokenToProject) table_actions = (TenantFilterAction, CreateProject, DeleteTenantsAction) pagination_param = "tenant_marker"
class UpdateForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Volume Name"), required=False) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def handle(self, request, data): volume_id = self.initial['volume_id'] try: sg_api.volume_update(request, volume_id, name=data['name'], description=data['description']) except Exception: redirect = reverse("horizon:storage-gateway:volumes:index") exceptions.handle(request, _('Unable to update volume.'), redirect=redirect) message = _('Updating volume "%s"') % data['name'] messages.info(request, message) return True
class CreateSnapshotForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Snapshot Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def handle(self, request, data): group_id = self.initial['group_id'] try: message = _('Creating group snapshot "%s".') \ % data['name'] snapshot = cinder.group_snapshot_create(request, group_id, data['name'], data['description']) messages.info(request, message) return snapshot except Exception as e: redirect = reverse("horizon:project:volume_groups:index") msg = _('Unable to create group snapshot.') if e.code == 413: msg = _('Requested snapshot would exceed the allowed quota.') else: search_opts = {'group_id': group_id} volumes = cinder.volume_list(request, search_opts=search_opts) if len(volumes) == 0: msg = _('Unable to create snapshot. ' 'group must contain volumes.') exceptions.handle(request, msg, redirect=redirect)
class EditVolumeType(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def clean_name(self): cleaned_name = self.cleaned_data['name'] if len(cleaned_name.strip()) == 0: msg = _('New name cannot be empty.') self._errors['name'] = self.error_class([msg]) return cleaned_name def handle(self, request, data): volume_type_id = self.initial['id'] try: cinder.volume_type_update(request, volume_type_id, data['name'], data['description']) message = _('Successfully updated volume type.') messages.success(request, message) return True except Exception as ex: redirect = reverse("horizon:admin:volumes:index") if ex.code == 409: error_message = _('New name conflicts with another ' 'volume type.') else: error_message = _('Unable to update volume type.') exceptions.handle(request, error_message, redirect=redirect)
class ImageForm(forms.SelfHandlingForm): image_id = forms.CharField(widget=forms.HiddenInput()) tags_list = forms.CharField(widget=forms.HiddenInput()) user_name = forms.CharField(max_length=80, label=_("User Name")) description = forms.CharField(max_length=80, label=_("Description"), required=False, widget=forms.Textarea(attrs={'rows': 4})) def handle(self, request, data): try: image_id = data['image_id'] user_name = data['user_name'] desc = data['description'] saharaclient.image_update(request, image_id, user_name, desc) image_tags = json.loads(data["tags_list"]) saharaclient.image_tags_update(request, image_id, image_tags) updated_image = saharaclient.image_get(request, image_id) messages.success(request, _("Successfully updated image.")) return updated_image except Exception: exceptions.handle(request, _("Failed to update image.")) return False
class CreateCheckpointForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Checkpoint Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def __init__(self, request, *args, **kwargs): super(CreateCheckpointForm, self).__init__(request, *args, **kwargs) # populate replication_id replication_id = kwargs.get('initial', {}).get('replication_id', []) self.fields['replication_id'] = forms.CharField( widget=forms.HiddenInput(), initial=replication_id) def handle(self, request, data): try: message = _('Creating replication checkpoint "%s".') % data['name'] checkpoint = sg_api.volume_checkpoint_create( request, data['replication_id'], data['name'], data['description']) messages.info(request, message) return checkpoint except Exception: redirect = reverse("horizon:storage-gateway:replications:index") msg = _('Unable to create checkpoint.') exceptions.handle(request, msg, redirect=redirect)
class CreatePolicy(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Policy Name")) kind = forms.ChoiceField(choices=POLICY_KIND_CHOICES, label=_("Kind"), initial='nonrecursive') description = forms.CharField(label=_("Description"), required=False, widget=forms.Textarea(attrs={'rows': 4})) failure_url = 'horizon:admin:policies:index' def handle(self, request, data): policy_name = data['name'] policy_description = data.get('description') policy_kind = data.pop('kind') LOG.info('User %s creating policy "%s" of type %s in tenant %s', request.user.username, policy_name, policy_kind, request.user.tenant_name) try: params = { 'name': policy_name, 'description': policy_description, 'kind': policy_kind, } policy = congress.policy_create(request, params) msg = _('Created policy "%s"') % policy_name LOG.info(msg) messages.success(request, msg) except Exception as e: msg_args = {'policy_name': policy_name, 'error': str(e)} msg = _('Failed to create policy "%(policy_name)s": ' '%(error)s') % msg_args LOG.error(msg) messages.error(self.request, msg) redirect = reverse(self.failure_url) raise exceptions.Http302(redirect) return policy
class ImageForm(forms.SelfHandlingForm): image_id = forms.CharField(widget=forms.HiddenInput()) tags_list = forms.CharField(widget=forms.HiddenInput()) user_name = forms.CharField(max_length=80, label=_("User Name")) description = forms.CharField(max_length=80, label=_("Description"), required=False, widget=forms.Textarea(attrs={ 'cols': 80, 'rows': 20 })) def handle(self, request, data): try: sahara = saharaclient.client(request) image_id = data['image_id'] user_name = data['user_name'] desc = data['description'] sahara.images.update_image(image_id, user_name, desc) image_tags = json.loads(data["tags_list"]) sahara.images.update_tags(image_id, image_tags) messages.success(request, self.message) return True except api_base.APIException as e: messages.error(request, str(e)) return False except Exception: exceptions.handle(request)
class GeneralConfigAction(workflows.Action): data_source_name = forms.CharField(label=_("Name")) data_source_type = forms.ChoiceField( label=_("Data Source Type"), choices=[("swift", "Swift"), ("hdfs", "HDFS")], widget=forms.Select(attrs={"class": "data_source_type_choice"})) data_source_url = forms.CharField(label=_("URL")) data_source_credential_user = forms.CharField(label=_("Source username"), required=False) data_source_credential_pass = forms.CharField( widget=forms.PasswordInput(attrs={'autocomplete': 'off'}), label=_("Source password"), required=False) data_source_description = forms.CharField( label=_("Description"), required=False, widget=forms.Textarea(attrs={'rows': 4})) def __init__(self, request, *args, **kwargs): super(GeneralConfigAction, self).__init__(request, *args, **kwargs) class Meta: name = _("Create Data Source") help_text_template = ("project/data_processing.data_sources/" "_create_data_source_help.html")
class UpdateGroup(forms.SelfHandlingForm): id = forms.CharField(widget=forms.HiddenInput()) name = forms.CharField(label=_("Name"), max_length=255, error_messages={ 'required': _('This field is required.'), 'invalid': _("The string may only contain" " ASCII characters and numbers.") }, validators=[validators.validate_slug]) description = forms.CharField(label=_("Description"), required=False, widget=forms.Textarea(attrs={'rows': 4})) def handle(self, request, data): try: sg = api.network.security_group_update(request, data['id'], data['name'], data['description']) messages.success( request, _('Successfully updated security group: %s') % data['name']) return sg except Exception: redirect = reverse("horizon:project:access_and_security:index") exceptions.handle(request, _('Unable to update security group.'), redirect=redirect)
class CreateSnapshotForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Snapshot Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def __init__(self, request, *args, **kwargs): super(CreateSnapshotForm, self).__init__(request, *args, **kwargs) # populate volume_id volume_id = kwargs.get('initial', {}).get('volume_id', []) self.fields['volume_id'] = forms.CharField(widget=forms.HiddenInput(), initial=volume_id) def handle(self, request, data): try: volume = sg_api.volume_get(request, data['volume_id']) message = _('Creating volume snapshot "%s".') % data['name'] if volume.status == 'in-use': message = _('Forcing to create snapshot "%s" ' 'from attached volume.') % data['name'] snapshot = sg_api.volume_snapshot_create(request, data['volume_id'], data['name'], data['description']) messages.info(request, message) return snapshot except Exception: redirect = reverse("horizon:storage-gateway:volumes:index") msg = _('Unable to create volume snapshot.') exceptions.handle(request, msg, redirect=redirect)
class CreateBackupForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Backup Name")) description = forms.CharField(widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) container_name = forms.CharField( max_length=255, label=_("Container Name"), validators=[containers_forms.no_slash_validator], required=False) volume_id = forms.CharField(widget=forms.HiddenInput()) def handle(self, request, data): try: backup = api.cinder.volume_backup_create(request, data['volume_id'], data['container_name'], data['name'], data['description']) message = _('Creating volume backup "%s"') % data['name'] messages.info(request, message) return backup except Exception: redirect = reverse('horizon:admin:volumes:index') exceptions.handle(request, _('Unable to create volume backup.'), redirect=redirect)
class AddExtraCapsAction(workflows.Action): extra_caps = forms.CharField( label=_("Extra Capabilities"), required=False, help_text=_('Enter extra capabilities of hosts in JSON'), widget=forms.Textarea(attrs={'rows': 5}), max_length=511) class Meta(object): name = _("Extra Capabilities") slug = "add_extra_caps" def clean(self): cleaned_data = super(AddExtraCapsAction, self).clean() extra_caps = cleaned_data.get('extra_caps') if extra_caps: try: extra_caps = eval(extra_caps) cleaned_data['extra_caps'] = extra_caps except (SyntaxError, NameError): raise forms.ValidationError( _('Extra capabilities must written in JSON')) return cleaned_data
class TenantsTable(tables.DataTable): name = tables.Column('name', verbose_name=_('Name'), form_field=forms.CharField(max_length=64), update_action=UpdateCell) description = tables.Column(lambda obj: getattr(obj, 'description', None), verbose_name=_('Description'), form_field=forms.CharField( widget=forms.Textarea(), required=False), update_action=UpdateCell) id = tables.Column('id', verbose_name=_('Project ID')) enabled = tables.Column('enabled', verbose_name=_('Enabled'), status=True, form_field=forms.BooleanField( label=_('Enabled'), required=False), update_action=UpdateCell) class Meta: name = "tenants" verbose_name = _("Projects") row_class = UpdateRow row_actions = (ViewMembersLink, ViewGroupsLink, UpdateProject, UsageLink, ModifyQuotas, DeleteTenantsAction) table_actions = (TenantFilterAction, CreateProject, DeleteTenantsAction) pagination_param = "tenant_marker"
class ImportKeypair(forms.SelfHandlingForm): name = forms.RegexField(max_length=255, label=_("Key Pair Name"), regex=KEYPAIR_NAME_REGEX, error_messages=KEYPAIR_ERROR_MESSAGES) key_type = forms.ChoiceField(label=_("Key Type"), widget=forms.SelectWidget(), choices=[('ssh', _("SSH Key")), ('x509', _("X509 Certificate"))], initial='ssh') public_key = forms.CharField(label=_("Public Key"), widget=forms.Textarea()) def handle(self, request, data): try: # Remove any new lines in the ssh public key if data['key_type'] == 'ssh': data['public_key'] = NEW_LINES.sub("", data['public_key']) keypair = api.nova.keypair_import(request, data['name'], data['public_key'], data['key_type']) messages.success(request, _('Successfully imported public key: %s') % data['name']) return keypair except Exception: exceptions.handle(request, ignore=True) self.api_error(_('Unable to import key pair.')) return False
class DomainForm(forms.SelfHandlingForm): '''Base class for DomainCreate and DomainUpdate forms. Sets-up all of the common form fields. ''' name = forms.RegexField( label=_("Domain Name"), regex=DOMAIN_NAME_REGEX, error_messages={'invalid': _('Enter a valid domain name.')}, ) email = forms.EmailField( label=_("Email"), max_length=255, ) ttl = forms.IntegerField( label=_("TTL (seconds)"), min_value=0, max_value=MAX_TTL, required=False, ) description = forms.CharField( label=_("Description"), required=False, max_length=160, widget=forms.Textarea(), )
class GroupTypesTable(tables.DataTable): name = tables.WrappingColumn("name", verbose_name=_("Name"), form_field=forms.CharField(max_length=64)) description = tables.Column(lambda obj: getattr(obj, 'description', None), verbose_name=_('Description'), form_field=forms.CharField( widget=forms.Textarea(attrs={'rows': 4}), required=False)) public = tables.Column("is_public", verbose_name=_("Public"), filters=(filters.yesno, filters.capfirst), form_field=forms.BooleanField(label=_('Public'), required=False)) def get_object_display(self, group_type): return group_type.name def get_object_id(self, group_type): return str(group_type.id) class Meta(object): name = "group_types" verbose_name = _("Group Types") table_actions = ( GroupTypesFilterAction, CreateGroupType, DeleteGroupType, ) row_actions = (GroupTypeSpecs, EditGroupType, DeleteGroupType) row_class = UpdateRow
class UpdateInstanceInfoAction(workflows.Action): name = forms.CharField(label=_("Name"), max_length=255) description = forms.CharField( label=_("Description"), widget=forms.Textarea(attrs={'rows': 4}), max_length=255, required=False ) def __init__(self, request, *args, **kwargs): super(UpdateInstanceInfoAction, self).__init__(request, *args, **kwargs) if not api.nova.is_feature_available(request, "instance_description"): del self.fields["description"] def handle(self, request, data): try: api.nova.server_update(request, data['instance_id'], data['name'], description=data.get('description')) except Exception: exceptions.handle(request, ignore=True) return False return True class Meta(object): name = _("Information") slug = 'instance_info' help_text = _("Edit the instance details.")
class CreateNetworkTemplate(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Name"), required=True) body = forms.CharField(widget=forms.Textarea(attrs={'rows': 20}), max_length=None, label=_("Template Body"), required=True) existing_id = forms.CharField(widget=forms.HiddenInput(), required=False) template_name = "horizon/common/_detail_table.html" def handle(self, request, data): template = network_template_api.get_template_by_id(data['existing_id']) try: if template: network_template_api.update_template_by_id( data['existing_id'], data['name'], data['body']) else: network_template_api.create_network_template( data['name'], data['body']) except: messages.error( request, _("Unable to create template. " "Verify that the name is unique.")) return False messages.success(request, _("Template saved.")) return True
class UpdateForm(forms.SelfHandlingForm): name = forms.CharField(max_length=50, label=_("Snapshot Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def handle(self, request, data): snapshot_id = self.initial['snapshot_id'] try: api.cinder.volume_snapshot_update(request, snapshot_id, data['name'], data['description']) message = _('Updating volume snapshot "%s"') % data['name'] messages.info(request, message) # operation log config = _("Snap ID: %s Snap Name: %s") %(snapshot_id, data['name']) api.logger.Logger(request).create(resource_type='snapshot', action_name='Update Snapshot', resource_name='Snapshot', config=config, status='Success') return True except Exception: redirect = reverse("horizon:storage:volumes:index") exceptions.handle(request, _('Unable to update volume snapshot.'), redirect=redirect) # operation log api.logger.Logger(request).create(resource_type='snapshot', action_name='Update Snapshot', resource_name='Snapshot', config=_('Unable to update volume snapshot.'), status='Error')
class UpdateForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Snapshot Name"), required=False) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def handle(self, request, data): snapshot_id = self.initial['snapshot_id'] try: snapshot = cinder.volume_snapshot_update(request, snapshot_id, data['name'], data['description']) name_or_id = (snapshot["snapshot"]["name"] or snapshot["snapshot"]["id"]) message = _('Updating volume snapshot "%s"') % name_or_id messages.info(request, message) return True except Exception: redirect = reverse("horizon:project:snapshots:index") exceptions.handle(request, _('Unable to update volume snapshot.'), redirect=redirect)
class UpdateForm(forms.SelfHandlingForm): name = forms.CharField(max_length=255, label=_("Name")) description = forms.CharField(max_length=255, widget=forms.Textarea(attrs={'rows': 4}), label=_("Description"), required=False) def clean(self): cleaned_data = super(UpdateForm, self).clean() new_desc = cleaned_data.get('description') old_desc = self.initial['description'] if len(old_desc): if len(new_desc) == 0: error_msg = _("Description is required.") self._errors['description'] = self.error_class([error_msg]) return cleaned_data return cleaned_data def handle(self, request, data): cgroup_id = self.initial['cgroup_id'] try: cinder.volume_cgroup_update(request, cgroup_id, data['name'], data['description']) message = _('Updating volume consistency ' 'group "%s"') % data['name'] messages.info(request, message) return True except Exception: redirect = reverse("horizon:admin:volumes:index") exceptions.handle(request, _('Unable to update volume consistency group.'), redirect=redirect)
class UploadSSLAction(workflows.Action): update_cert = forms.BooleanField(label='Update SSL Certificate', required=False, widget=forms.HiddenInput()) cert_name = forms.CharField(max_length=80, label=_("Certificate Name"), required=False) cert = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}), label=_("Certificate"), required=False, help_text=_("Certificate")) private_key = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}), label=_("Private Key"), required=False, help_text=_("Private Key")) chain_cert = forms.CharField(widget=forms.Textarea(attrs={'rows': 3}), label=_("Certificate Chain (Optional)"), required=False, help_text=_("Intermediate Chain" " Certificates")) def clean(self): cleaned_data = super(UploadSSLAction, self).clean() data = self.data protocol = data.get('source_type') if protocol == 'HTTPS': use_common_cert = data.get('use_common_cert') if not use_common_cert: # check to see if ssl cert is provided cert_name = data.get('cert_name') cert = data.get('cert') private_key = data.get('private_key') if (not cert_name) \ or (not cert) \ or (not private_key): raise forms.ValidationError( _('Please provide all certificate parameters.')) return cleaned_data class Meta(object): name = _("SSL Certificate") help_text_template = ("project/loadbalancersv2/_ssl_cert_help.html")
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, ) 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, hadoop_version = whelpers\ .get_plugin_and_hadoop_version(self.request) extra["plugin_name"] = plugin extra["hadoop_version"] = 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 = ("project/data_processing.cluster_templates/" "_configure_general_help.html")