~ubuntu-branches/ubuntu/trusty/horizon/trusty-updates

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/admin/defaults/workflows.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-09-06 11:59:43 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20130906115943-h3td0l7tp16mb9oc
Tags: 1:2013.2~b3-0ubuntu1
* New upstream release.
* debian/control: Minimum python-openstack-auth version >= 1.1.1.
* debian/control: Add python-troveclient.
* debian/static: Refresh static assets for 2013.2~b3.
* debian/patches: ubuntu_local_settings.patch -> ubuntu_settings.patch, also
  patch location of secret key in openstack_dashboard/settings.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2013 Kylin, Inc.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
 
 
18
from django.utils.translation import ugettext_lazy as _  # noqa
 
19
 
 
20
from horizon import exceptions
 
21
from horizon import forms
 
22
from horizon import workflows
 
23
 
 
24
from openstack_dashboard.api import base
 
25
from openstack_dashboard.api import cinder
 
26
from openstack_dashboard.api import nova
 
27
from openstack_dashboard.usage import quotas
 
28
 
 
29
ALL_NOVA_QUOTA_FIELDS = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS
 
30
 
 
31
 
 
32
class UpdateDefaultQuotasAction(workflows.Action):
 
33
    ifcb_label = _("Injected File Content Bytes")
 
34
    ifpb_label = _("Injected File Path Bytes")
 
35
    metadata_items = forms.IntegerField(min_value=-1,
 
36
                                        label=_("Metadata Items"))
 
37
    cores = forms.IntegerField(min_value=-1, label=_("VCPUs"))
 
38
    instances = forms.IntegerField(min_value=-1, label=_("Instances"))
 
39
    injected_files = forms.IntegerField(min_value=-1,
 
40
                                        label=_("Injected Files"))
 
41
    injected_file_content_bytes = forms.IntegerField(min_value=-1,
 
42
                                                     label=ifcb_label)
 
43
    injected_file_path_bytes = forms.IntegerField(min_value=-1,
 
44
                                                  label=ifpb_label)
 
45
    volumes = forms.IntegerField(min_value=-1, label=_("Volumes"))
 
46
    snapshots = forms.IntegerField(min_value=-1, label=_("Snapshots"))
 
47
    gigabytes = forms.IntegerField(min_value=-1, label=_("Gigabytes"))
 
48
    ram = forms.IntegerField(min_value=-1, label=_("RAM (MB)"))
 
49
    floating_ips = forms.IntegerField(min_value=-1, label=_("Floating IPs"))
 
50
    security_groups = forms.IntegerField(min_value=-1,
 
51
                                         label=_("Security Groups"))
 
52
    security_group_rules = forms.IntegerField(min_value=-1,
 
53
                                              label=_("Security Group Rules"))
 
54
    key_pairs = forms.IntegerField(min_value=-1, label=_("Key Pairs"))
 
55
 
 
56
    def __init__(self, request, *args, **kwargs):
 
57
        super(UpdateDefaultQuotasAction, self).__init__(request,
 
58
                                                        *args,
 
59
                                                        **kwargs)
 
60
        disabled_quotas = quotas.get_disabled_quotas(request)
 
61
        for field in disabled_quotas:
 
62
            if field in self.fields:
 
63
                self.fields[field].required = False
 
64
                self.fields[field].widget = forms.HiddenInput()
 
65
 
 
66
    class Meta:
 
67
        name = _("Default Quotas")
 
68
        slug = 'update_default_quotas'
 
69
        help_text = _("From here you can update the default quotas "
 
70
                      "(max limits).")
 
71
 
 
72
 
 
73
class UpdateDefaultQuotas(workflows.Step):
 
74
    action_class = UpdateDefaultQuotasAction
 
75
    contributes = (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS)
 
76
 
 
77
 
 
78
class UpdateDefaultQuotas(workflows.Workflow):
 
79
    slug = "update_default_quotas"
 
80
    name = _("Update Default Quotas")
 
81
    finalize_button_name = _("Update Defaults")
 
82
    success_message = _('Default quotas updated "%s".')
 
83
    failure_message = _('Unable to update default quotas "%s".')
 
84
    success_url = "horizon:admin:defaults:index"
 
85
    default_steps = (UpdateDefaultQuotas,)
 
86
 
 
87
    def handle(self, request, data):
 
88
        # Update the default quotas.
 
89
        # `fixed_ips` update for quota class is not supported by novaclient
 
90
        nova_data = dict([(key, data[key]) for key in ALL_NOVA_QUOTA_FIELDS
 
91
                         if key != 'fixed_ips'])
 
92
        try:
 
93
            nova.default_quota_update(request, **nova_data)
 
94
 
 
95
            if base.is_service_enabled(request, 'volume'):
 
96
                cinder_data = dict([(key, data[key]) for key in
 
97
                                    quotas.CINDER_QUOTA_FIELDS])
 
98
                cinder.default_quota_update(request, **cinder_data)
 
99
        except Exception:
 
100
            exceptions.handle(request, _('Unable to update default quotas.'))
 
101
        return True