Add support for shrinking an instance spindles-wise
authorBernardo Dal Seno <bdalseno@google.com>
Thu, 6 Jun 2013 12:12:12 +0000 (14:12 +0200)
committerBernardo Dal Seno <bdalseno@google.com>
Fri, 7 Jun 2013 13:11:20 +0000 (15:11 +0200)
This makes tiered allocation in hspace work also with respect to spindles.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

src/Ganeti/HTools/Instance.hs

index d42e0c2..fa8fa25 100644 (file)
@@ -265,6 +265,15 @@ shrinkByType inst T.FailCPU = let v = vcpus inst - T.unitCpu
                               in if v < T.unitCpu
                                  then Bad "out of vcpus"
                                  else Ok inst { vcpus = v }
+shrinkByType inst T.FailSpindles =
+  case disks inst of
+    [Disk ds sp] -> case sp of
+                      Nothing -> Bad "No spindles, shouldn't have happened"
+                      Just sp' -> let v = sp' - T.unitSpindle
+                                  in if v < T.unitSpindle
+                                     then Bad "out of spindles"
+                                     else Ok inst { disks = [Disk ds (Just v)] }
+    d -> Bad $ "Expected one disk, but found " ++ show d
 shrinkByType _ f = Bad $ "Unhandled failure mode " ++ show f
 
 -- | Get the number of disk spindles