~ubuntu-branches/ubuntu/saucy/horizon/saucy-updates

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/project/volumes/forms.py

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Chuck Short
  • Date: 2013-10-03 13:48:12 UTC
  • mfrom: (1.1.31)
  • Revision ID: package-import@ubuntu.com-20131003134812-2vkwosem4flwuk5y
Tags: 1:2013.2~rc1-0ubuntu1
[ James Page ]
* New upstream release candidate:
  - d/static: Refreshed static assets for 2013.2~rc1.
  - d/patches: Refreshed patches.

[ Chuck Short ]
* debian/control: Add python-lesscpy as a suggests to optionally
  support online compression of static assets (LP: #1226674).

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from openstack_dashboard.api import glance
26
26
from openstack_dashboard.dashboards.project.images_and_snapshots import utils
27
27
from openstack_dashboard.dashboards.project.instances import tables
 
28
from openstack_dashboard.usage import quotas
28
29
 
29
30
 
30
31
class CreateForm(forms.SelfHandlingForm):
36
37
    size = forms.IntegerField(min_value=1, label=_("Size (GB)"))
37
38
    volume_source_type = forms.ChoiceField(label=_("Volume Source"),
38
39
                                           required=False)
39
 
    snapshot_source = forms.ChoiceField(label=_("Use snapshot as a source"),
40
 
                                        widget=fields.SelectWidget(
41
 
                                          attrs={'class': 'snapshot-selector'},
42
 
                                          data_attrs=('size', 'display_name'),
43
 
                                          transform=lambda x:
44
 
                                                ("%s (%sGB)" % (x.display_name,
45
 
                                                                x.size))),
46
 
                                        required=False)
47
 
    image_source = forms.ChoiceField(label=_("Use image as a source"),
48
 
                                     widget=fields.SelectWidget(
49
 
                                         attrs={'class': 'image-selector'},
50
 
                                         data_attrs=('size', 'name'),
51
 
                                         transform=lambda x:
52
 
                                             ("%s (%s)" %
53
 
                                                 (x.name,
54
 
                                                  filesizeformat(x.bytes)))),
55
 
                                     required=False)
 
40
    snapshot_source = forms.ChoiceField(
 
41
        label=_("Use snapshot as a source"),
 
42
        widget=fields.SelectWidget(
 
43
            attrs={'class': 'snapshot-selector'},
 
44
            data_attrs=('size', 'display_name'),
 
45
            transform=lambda x: "%s (%sGB)" % (x.display_name, x.size)),
 
46
        required=False)
 
47
    image_source = forms.ChoiceField(
 
48
        label=_("Use image as a source"),
 
49
        widget=fields.SelectWidget(
 
50
            attrs={'class': 'image-selector'},
 
51
            data_attrs=('size', 'name'),
 
52
            transform=lambda x: "%s (%s)" % (x.name, filesizeformat(x.bytes))),
 
53
        required=False)
56
54
 
57
55
    def __init__(self, request, *args, **kwargs):
58
56
        super(CreateForm, self).__init__(request, *args, **kwargs)
141
139
 
142
140
    def handle(self, request, data):
143
141
        try:
144
 
            usages = cinder.tenant_absolute_limits(self.request)
145
 
            volumes = cinder.volume_list(self.request)
146
 
            total_size = sum([getattr(volume, 'size', 0) for volume
147
 
                              in volumes])
148
 
            usages['gigabytesUsed'] = total_size
149
 
            usages['volumesUsed'] = len(volumes)
150
 
            availableGB = usages['maxTotalVolumeGigabytes'] -\
 
142
            usages = quotas.tenant_limit_usages(self.request)
 
143
            availableGB = usages['maxTotalVolumeGigabytes'] - \
151
144
                usages['gigabytesUsed']
152
145
            availableVol = usages['maxTotalVolumes'] - usages['volumesUsed']
153
146
 
256
249
        instances = []
257
250
        for instance in instance_list:
258
251
            if instance.status in tables.ACTIVE_STATES and \
259
 
                        not any(instance.id == att["server_id"]
260
 
                                for att in volume.attachments):
 
252
                    not any(instance.id == att["server_id"]
 
253
                            for att in volume.attachments):
261
254
                instances.append((instance.id, '%s (%s)' % (instance.name,
262
255
                                                            instance.id)))
263
256
        if instances: