Ejemplo n.º 1
0
    def __init__(self, request, *args, **kwargs):
        super(UpdateiStoragePools, self).__init__(request, *args, **kwargs)
        self._tier_name = kwargs['initial']['tier_name']

        js_attrs = {
            'onchange': 'add_total_quota()',
            'onkeypress': 'this.onchange()',
            'onpaste': 'this.onchange()',
            'oninput': 'this.onchange()',
            'onload': 'this.onchange()'
        }

        self.fields['cinder_pool_gib'] = forms.IntegerField(
            label=_("Cinder Volumes Pool (GiB)"),
            required=True,
            help_text=_("Storage space allocated to cinder volumes in "
                        "gibibytes."),
            min_value=0,
            widget=forms.NumberInput(attrs=js_attrs))

        self.fields['kube_pool_gib'] = forms.IntegerField(
            label=_("Kubernetes Pool (GiB)"),
            required=True,
            help_text=_("Storage space allocated to Kubernetes in gibibytes."),
            min_value=0,
            widget=forms.NumberInput(attrs=js_attrs))

        if self._tier_name == 'storage':
            self.fields['glance_pool_gib'] = forms.IntegerField(
                label=_("Glance Image Pool (GiB)"),
                required=True,
                help_text=_("Storage space allocated to glance images in "
                            "gibibytes."),
                min_value=0,
                widget=forms.NumberInput(attrs=js_attrs))

            self.fields['ephemeral_pool_gib'] = forms.IntegerField(
                label=_("Ephemeral Storage Pool(GiB)"),
                required=True,
                help_text=_("Storage space allocated to nova ephemeral "
                            "instance disks in gibibytes."),
                min_value=0,
                widget=forms.NumberInput(attrs=js_attrs))

            self.fields['object_pool_gib'] = forms.IntegerField(
                label=_("Object Storage Pool(GiB)"),
                required=True,
                help_text=_("Storage space allocated to objects in "
                            "gibibytes."),
                min_value=0,
                widget=forms.NumberInput(attrs=js_attrs))
Ejemplo n.º 2
0
class FlavorsTable(flavors_tables.FlavorsTable):
    name = tables.Column('name', verbose_name=_('Flavor Name'))
    max_vms = tables.Column(
        "max_vms",
        auto='form_widget',
        verbose_name=_("Max. VMs"),
        form_widget=forms.NumberInput(),
        form_widget_attributes={'class': "number_input_slim"})

    class Meta:
        name = "flavors"
        verbose_name = _("Flavors")
        multi_select = True
        multi_select_name = "flavors_object_ids"
Ejemplo n.º 3
0
class CreateForm(forms.SelfHandlingForm):
    # General fields
    name = forms.CharField(label=_("Lease Name"), required=True, max_length=80)
    start_date = forms.DateTimeField(
        label=_("Start Date"),
        required=False,
        help_text=_('Enter YYYY-MM-DD HH:MM or blank for now'),
        input_formats=['%Y-%m-%d %H:%M'],
        widget=forms.DateTimeInput(
            attrs={'placeholder': 'YYYY-MM-DD HH:MM (blank for now)'}))
    end_date = forms.DateTimeField(
        label=_("End Date"),
        required=False,
        help_text=_('Enter YYYY-MM-DD HH:MM or blank for Start Date + 24h'),
        input_formats=['%Y-%m-%d %H:%M'],
        widget=forms.DateTimeInput(
            attrs={
                'placeholder': 'YYYY-MM-DD HH:MM (blank for Start Date + '
                '24h)'
            }))
    resource_type = forms.ChoiceField(
        label=_("Resource Type"),
        required=True,
        choices=(('host', _('Physical Host')), ('instance',
                                                _('Virtual Instance'))),
        widget=forms.ThemableSelectWidget(attrs={
            'class': 'switchable',
            'data-slug': 'source'
        }))

    # Fields for host reservation
    min_hosts = forms.IntegerField(
        label=_('Minimum Number of Hosts'),
        required=False,
        help_text=_('Enter the minimum number of hosts to reserve.'),
        min_value=1,
        initial=1,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-host': _('Minimum Number of Hosts')
            }))
    max_hosts = forms.IntegerField(
        label=_('Maximum Number of Hosts'),
        required=False,
        help_text=_('Enter the maximum number of hosts to reserve.'),
        min_value=1,
        initial=1,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-host': _('Maximum Number of Hosts')
            }))
    hypervisor_properties = forms.CharField(
        label=_("Hypervisor Properties"),
        required=False,
        help_text=_('Enter properties of a hypervisor to reserve.'),
        max_length=255,
        widget=forms.TextInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-host': _('Hypervisor Properties'),
                'placeholder': 'e.g. [">=", "$vcpus", "2"]'
            }))

    # Fields for instance reservation
    amount = forms.IntegerField(
        label=_('Instance Count'),
        required=False,
        help_text=_('Enter the number of instances to reserve.'),
        min_value=1,
        initial=1,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-instance': _('Instance Count')
            }))
    vcpus = forms.IntegerField(
        label=_('Number of VCPUs'),
        required=False,
        help_text=_('Enter the number of VCPUs per instance.'),
        min_value=1,
        initial=1,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-instance': _('Number of VCPUs')
            }))
    memory_mb = forms.IntegerField(
        label=_('RAM (MB)'),
        required=False,
        help_text=_('Enter the size of RAM (MB) per instance'),
        min_value=1,
        initial=1,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-instance': _('RAM (MB)')
            }))
    disk_gb = forms.IntegerField(
        label=_('Root Disk (GB)'),
        required=False,
        help_text=_('Enter the root disk size (GB) per instance'),
        min_value=0,
        initial=0,
        widget=forms.NumberInput(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-instance': _('Root Disk (GB)')
            }))
    affinity = forms.ChoiceField(
        label=_("Affinity Rule"),
        required=False,
        choices=(
            (None, _('None')),
            (True, _('Affinity')),
            (False, _('Anti-Affinity')),
        ),
        initial=None,
        widget=forms.ThemableSelectWidget(
            attrs={
                'class': 'switched',
                'data-switch-on': 'source',
                'data-source-instance': _('Affinity Rule')
            }))

    # Fields for both of host and instance reservations
    resource_properties = forms.CharField(
        label=_("Resource Properties"),
        required=False,
        help_text=_('Enter properties of a resource to reserve.'),
        max_length=255,
        widget=forms.TextInput(
            attrs={'placeholder': 'e.g. ["==", "$extra_key", "extra_value"]'}))

    def handle(self, request, data):
        if data['resource_type'] == 'host':
            reservations = [{
                'resource_type':
                'physical:host',
                'min':
                data['min_hosts'],
                'max':
                data['max_hosts'],
                'hypervisor_properties': (data['hypervisor_properties'] or ''),
                'resource_properties':
                data['resource_properties'] or ''
            }]
        elif data['resource_type'] == 'instance':
            reservations = [{
                'resource_type':
                'virtual:instance',
                'amount':
                data['amount'],
                'vcpus':
                data['vcpus'],
                'memory_mb':
                data['memory_mb'],
                'disk_gb':
                data['disk_gb'],
                'affinity':
                data['affinity'],
                'resource_properties':
                data['resource_properties'] or ''
            }]

        events = []

        try:
            api.client.lease_create(
                request, data['name'],
                data['start_date'].strftime('%Y-%m-%d %H:%M'),
                data['end_date'].strftime('%Y-%m-%d %H:%M'), reservations,
                events)
            messages.success(
                request,
                _('Lease %s was successfully '
                  'created.') % data['name'])
            return True
        except Exception as e:
            LOG.error('Error submitting lease: %s', e)
            exceptions.handle(request,
                              message='An error occurred while creating this '
                              'lease. Please try again.')

    def clean(self):
        cleaned_data = super(CreateForm, self).clean()
        local = timezone(
            self.request.session.get(
                'django_timezone',
                self.request.COOKIES.get('django_timezone', 'UTC')))

        if cleaned_data['start_date']:
            cleaned_data['start_date'] = local.localize(
                cleaned_data['start_date'].replace(tzinfo=None)).astimezone(
                    timezone('UTC'))
        else:
            cleaned_data['start_date'] = datetime.datetime.utcnow()
        if cleaned_data['end_date']:
            cleaned_data['end_date'] = local.localize(
                cleaned_data['end_date'].replace(tzinfo=None)).astimezone(
                    timezone('UTC'))
        else:
            cleaned_data['end_date'] = (cleaned_data['start_date'] +
                                        datetime.timedelta(days=1))
Ejemplo n.º 4
0
class ModifyPlanForm(forms.SelfHandlingForm):

    id = forms.CharField(label=_("ID"), widget=forms.HiddenInput())
    name = forms.CharField(max_length=255, label=_("Name"))
    code = forms.CharField(max_length=32, label=_("Code"))
    service_type = forms.ChoiceField(label = _('Service Type'), choices=[])
    rate = forms.FloatField(label=_('Rate'))
    setup_fee = forms.FloatField(label=_('Setup Fee'), required=False)
    billing_type = forms.ChoiceField(
        label = _('Billing Type'),
        choices=[],
        required=False,
        widget=forms.Select(attrs={
            'class': 'switchable',
            'data-slug': 'billing_type'
        })
    )
    ref_id = forms.ChoiceField(
        label = _('Flavor'),
        choices=[],
        required=False,
        widget=forms.Select(attrs={
            'class': 'switched',
            'data-switch-on': 'billing_type',
            'data-billing_type-1': _('Flavor')
        })
    )
    attr_instances = forms.FloatField(
        label=_("Instances"),
        required=False,
        widget=forms.NumberInput(attrs={
            'step': 1,
            'class': 'switched',
            'data-switch-on': 'billing_type',
            'data-billing_type-2': _('Instances')
        })
    )
    attr_cpu = forms.FloatField(
        label=_("CPU"),
        required=False,
        widget=forms.NumberInput(attrs={
            'step': 1,
            'class': 'switched',
            'data-switch-on': 'billing_type',
            'data-billing_type-2': _('CPU')
        })
    )
    attr_ram = forms.FloatField(
        label=_("RAM (MB)"),
        required=False,
        widget=forms.NumberInput(attrs={
            'step': 1,
            'class': 'switched',
            'data-switch-on': 'billing_type',
            'data-billing_type-2': _('RAM (GB)')
        })
    )
    attr_storage = forms.FloatField(
        label=_("Storage (GB)"),
        required=False,
        widget=forms.NumberInput(attrs={
            'step': 1,
            'class': 'switched',
            'data-switch-on': 'billing_type',
            'data-billing_type-2': _('Storage (GB)')
        })
    )
    description = forms.CharField(label = _('Description'))
    metadata_mark = forms.CharField(max_length=255, label=_("Image Mark"), required=False)

    def __init__(self, request, *args, **kwargs):
        super(ModifyPlanForm, self).__init__(request, *args, **kwargs)
        # set discount types
        self.fields['service_type'].choices = gen_service_types(request)
        self.fields['billing_type'].choices = gen_billing_types(request)
        self.fields['billing_type'].choices.append((None, '-'))
        self.fields['ref_id'].choices = gen_flavors(request)

    def handle(self, request, data):
        type_id = data.pop('id', None)
        if not type_id:
            exceptions.handle(request, _('Invalid request.'))
            return False
        try:
            attr_instances =  data.pop('attr_instances')
            attr_cpu = data.pop('attr_cpu')
            attr_ram = data.pop('attr_ram')
            attr_storage = data.pop('attr_storage')
            if int(data['billing_type']) == RAB_BILLING_TYPE_ID:
                data['attrs'] = {}
                if attr_instances:
                    data['attrs']['instances'] = attr_instances
                if attr_cpu:
                    data['attrs']['cpu'] = attr_cpu
                if attr_ram:
                    data['attrs']['ram'] = attr_ram
                if attr_storage:
                    data['attrs']['storage'] = attr_storage
            modify_plan(request, type_id, data)
            return True

        except Exception:
            exceptions.handle(request, _('Unable to modify billing plan.'))