class UpdateTenant(forms.SelfHandlingForm): id = forms.CharField( label=_("ID"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) name = forms.CharField( label=_("Name"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) description = forms.CharField(required=False, widget=forms.widgets.Textarea(), label=_("Description")) enabled = forms.BooleanField(required=False, label=_("Enabled")) def handle(self, request, data): try: LOG.info('Updating tenant with id "%s"' % data['id']) api.tenant_update(request, data['id'], data['name'], data['description'] or '', data['enabled']) messages.success(request, _('%s was successfully updated.') % data['name']) except api_exceptions.ApiException, e: LOG.exception( 'ApiException while updating tenant\n' 'Id: "%s", Name: "%s", Description: "%s", Enabled "%s"' % (data['id'], data['name'], data['description'], data['enabled'])) messages.error(request, _('Unable to update tenant: %s') % e.message) return shortcuts.redirect('steer:syspanel:tenants:index')
class CreateSnapshot(forms.SelfHandlingForm): tenant_id = forms.CharField(widget=forms.HiddenInput()) instance_id = forms.CharField(widget=forms.TextInput( attrs={'readonly': 'readonly'})) name = forms.CharField(max_length="20", label=_("Snapshot Name")) def handle(self, request, data): try: LOG.info('Creating snapshot "%s"' % data['name']) snapshot = api.snapshot_create(request, data['instance_id'], data['name']) instance = api.server_get(request, data['instance_id']) messages.info( request, _('Snapshot "%(name)s" created for instance "%(inst)s"') % { "name": data['name'], "inst": instance.name }) return shortcuts.redirect('steer:engine:images_and_snapshots' ':snapshots:index') except api_exceptions.ApiException, e: msg = _('Error Creating Snapshot: %s') % e.message LOG.exception(msg) messages.error(request, msg) return shortcuts.redirect(request.build_absolute_uri())
class UpdateUserForm(BaseUserForm): id = forms.CharField( label=_("ID"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) # FIXME: keystone doesn't return the username from a get API call. #name = forms.CharField(label=_("Name")) email = forms.CharField(label=_("Email")) password = forms.CharField(label=_("Password"), widget=forms.PasswordInput(render_value=False), required=False) tenant_id = forms.ChoiceField(label=_("Primary Tenant")) def handle(self, request, data): updated = [] if data['email']: updated.append('email') api.user_update_email(request, data['id'], data['email']) if data['password']: updated.append('password') api.user_update_password(request, data['id'], data['password']) if data['tenant_id']: updated.append('tenant') api.user_update_tenant(request, data['id'], data['tenant_id']) messages.success( request, _('Updated %(attrib)s for %(user)s.') % { "attrib": ', '.join(updated), "user": data['id'] }) return shortcuts.redirect('steer:syspanel:users:index')
class FloatingIpAssociate(forms.SelfHandlingForm): floating_ip_id = forms.CharField(widget=forms.HiddenInput()) floating_ip = forms.CharField(widget=forms.TextInput( attrs={'readonly': 'readonly'})) instance_id = forms.ChoiceField() def __init__(self, *args, **kwargs): super(FloatingIpAssociate, self).__init__(*args, **kwargs) instancelist = kwargs.get('initial', {}).get('instances', []) self.fields['instance_id'] = forms.ChoiceField(choices=instancelist, label=_("Instance")) def handle(self, request, data): try: api.server_add_floating_ip(request, data['instance_id'], data['floating_ip_id']) LOG.info('Associating Floating IP "%s" with Instance "%s"' % (data['floating_ip'], data['instance_id'])) messages.info( request, _('Successfully associated Floating IP \ %(ip)s with Instance: %(inst)s' % { "ip": data['floating_ip'], "inst": data['instance_id'] })) except engineclient_exceptions.ClientException, e: LOG.exception("ClientException in FloatingIpAssociate") messages.error(request, _('Error associating Floating IP: %s') % e) return shortcuts.redirect('steer:engine:access_and_security:index')
class LoginWithTenant(Login): """ Exactly like :class:`.Login` but includes the tenant id as a field so that the process of choosing a default tenant is bypassed. """ username = forms.CharField( max_length="20", widget=forms.TextInput(attrs={'readonly': 'readonly'})) tenant = forms.CharField(widget=forms.HiddenInput())
class UpdateQuotas(forms.SelfHandlingForm): tenant_id = forms.CharField( label=_("ID (name)"), widget=forms.TextInput(attrs={'readonly': 'readonly'})) metadata_items = forms.CharField(label=_("Metadata Items")) injected_files = forms.CharField(label=_("Injected Files")) injected_file_content_bytes = forms.CharField(label=_("Injected File " "Content Bytes")) cores = forms.CharField(label=_("VCPUs")) instances = forms.CharField(label=_("Instances")) volumes = forms.CharField(label=_("Volumes")) gigabytes = forms.CharField(label=_("Gigabytes")) ram = forms.CharField(label=_("RAM (in MB)")) floating_ips = forms.CharField(label=_("Floating IPs")) def handle(self, request, data): try: api.admin_api(request).quota_sets.update( data['tenant_id'], metadata_items=data['metadata_items'], injected_file_content_bytes=data[ 'injected_file_content_bytes'], volumes=data['volumes'], gigabytes=data['gigabytes'], ram=int(data['ram']), floating_ips=data['floating_ips'], instances=data['instances'], injected_files=data['injected_files'], cores=data['cores'], ) messages.success( request, _('Quotas for %s were successfully updated.') % data['tenant_id']) except api_exceptions.ApiException, e: messages.error(request, _('Unable to update quotas: %s') % e.message) return shortcuts.redirect('steer:syspanel:tenants:index')