Allow users to keep existing large disks while modifying machines 0.1.55
authorMitchell E Berger <mitchb@mit.edu>
Sat, 21 Dec 2019 00:35:05 +0000 (19:35 -0500)
committerMitchell E Berger <mitchb@mit.edu>
Sat, 21 Dec 2019 01:11:12 +0000 (20:11 -0500)
code/validation.py
debian/changelog

index 003df61..da01d8d 100755 (executable)
@@ -99,19 +99,26 @@ def maxDisk(owner, machine=None):
     """Return the maximum disk that a machine can reach.
 
     If machine is None, the maximum disk for a new machine. Otherwise,
-    return the maximum that a given machine can be changed to.
+    return the maximum that a given machine can be changed to.  If the
+    disk currently exceeds the quotas, it can be changed to anything up
+    to its current size.
     """
     (quota_total, quota_single) = Owner.getDiskQuotas(machine.owner if machine else owner)
 
-    if machine is not None:
+    machine_id, current_size = None, 0
+    if machine is not None and machine.disks:
         machine_id = machine.machine_id
-    else:
-        machine_id = None
+        # 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 min(quota_single, quota_total-disk_usage/1024.)
+    return max(current_size, min(quota_single, quota_total-disk_usage/1024.))
 
 def cantAddVm(owner, g):
     machines = getMachinesByOwner(owner)
index 4eb32d9..3c18b0f 100644 (file)
@@ -1,3 +1,9 @@
+invirt-web (0.1.55) precise; urgency=medium
+
+  * Allow users to keep existing large disks while modifying machines
+
+ -- Mitchell Berger <mitchb@mit.edu>  Fri, 20 Dec 2019 19:06:00 -0500
+
 invirt-web (0.1.54) precise; urgency=medium
 
   * Change VM creation auth failure message to include info about system:anyuser needing the l permission