- else:
- machine_id = None
- disk_usage = Disk.query().filter(Disk.c.machine_id != machine_id).\
- join('machine').\
- filter_by(owner=owner).sum(Disk.c.size) or 0
- return min(quota_single, quota_total-disk_usage/1024.)
+ # XXX The machine modification form doesn't currently handle the
+ # case of machines with multiple disks. It simply addresses the "first"
+ # disk (which is possibly nondeterministic and wrong). Since we're
+ # doing validation for that form, we have to use the same logic it
+ # does.
+ current_size = machine.disks[0].size / 1024.
+ disk_usage_query = Disk.query.filter(Disk.machine_id != machine_id).\
+ join('machine').filter_by(owner=owner)
+
+ disk_usage = sum([m.size for m in disk_usage_query]) or 0
+ return max(current_size, min(quota_single, quota_total-disk_usage/1024.))