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
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"),
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'),
44
("%s (%sGB)" % (x.display_name,
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'),
54
filesizeformat(x.bytes)))),
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)),
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))),
57
55
def __init__(self, request, *args, **kwargs):
58
56
super(CreateForm, self).__init__(request, *args, **kwargs)
142
140
def handle(self, request, data):
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
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']
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,