Add an availDisk node function
authorIustin Pop <iustin@google.com>
Fri, 3 Jul 2009 17:22:06 +0000 (20:22 +0300)
committerIustin Pop <iustin@google.com>
Fri, 3 Jul 2009 19:01:02 +0000 (22:01 +0300)
This function returns the amount of available disk, which depends on
whether a low disk limit has been configured or not and on the free disk
space of the node.

Ganeti/HTools/Node.hs

index 67c421b..34210cc 100644 (file)
@@ -52,6 +52,8 @@ module Ganeti.HTools.Node
     , removeSec
     , addPri
     , addSec
+    -- * Stats
+    , availDisk
     -- * Formatting
     , list
     -- * Misc stuff
@@ -339,6 +341,20 @@ addSec t inst pdx =
                      r_mem = new_rmem, p_dsk = new_dp,
                      p_rem = new_prem}
 
+-- * Stats functions
+
+-- | Computes the amount of available disk on a given node
+availDisk :: Node -> Int
+availDisk t =
+    let _f = f_dsk t
+        _l = lo_dsk t
+    in
+      if _l == noLimitInt
+      then _f
+      else if _f < _l
+           then 0
+           else _f - _l
+
 -- * Display functions
 
 -- | String converter for the node list functionality.