From fe3d6f02ca980a7519c070cc55ae05dd38763bb5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 3 Jul 2009 20:22:06 +0300
Subject: [PATCH] Add an availDisk node function

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 | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Ganeti/HTools/Node.hs b/Ganeti/HTools/Node.hs
index 67c421b2f..34210ccd1 100644
--- a/Ganeti/HTools/Node.hs
+++ b/Ganeti/HTools/Node.hs
@@ -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.
-- 
GitLab