Make Query operators enforce strictness
[ganeti-local] / htools / Ganeti / HTools / Instance.hs
index 9e3b2ef..b941df6 100644 (file)
@@ -83,7 +83,7 @@ data Instance = Instance
   , spindleUse   :: Int       -- ^ The numbers of used spindles
   , allTags      :: [String]  -- ^ List of all instance tags
   , exclTags     :: [String]  -- ^ List of instance exclusion tags
-  } deriving (Show, Read, Eq)
+  } deriving (Show, Eq)
 
 instance T.Element Instance where
   nameOf   = name
@@ -100,8 +100,8 @@ isRunning _                              = False
 
 -- | Check if instance is offline.
 isOffline :: Instance -> Bool
-isOffline (Instance {runSt = T.AdminOffline}) = True
-isOffline _                                   = False
+isOffline (Instance {runSt = T.StatusOffline}) = True
+isOffline _                                    = False
 
 
 -- | Helper to check if the instance is not offline.
@@ -257,22 +257,22 @@ specOf Instance { mem = m, dsk = d, vcpus = c } =
   T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
 
 -- | Checks if an instance is smaller than a given spec. Returns
--- OpGood for a correct spec, otherwise OpFail one of the possible
+-- OpGood for a correct spec, otherwise Bad one of the possible
 -- failure modes.
 instBelowISpec :: Instance -> T.ISpec -> T.OpResult ()
 instBelowISpec inst ispec
-  | mem inst > T.iSpecMemorySize ispec = T.OpFail T.FailMem
-  | dsk inst > T.iSpecDiskSize ispec   = T.OpFail T.FailDisk
-  | vcpus inst > T.iSpecCpuCount ispec = T.OpFail T.FailCPU
-  | otherwise = T.OpGood ()
+  | mem inst > T.iSpecMemorySize ispec = Bad T.FailMem
+  | dsk inst > T.iSpecDiskSize ispec   = Bad T.FailDisk
+  | vcpus inst > T.iSpecCpuCount ispec = Bad T.FailCPU
+  | otherwise = Ok ()
 
 -- | Checks if an instance is bigger than a given spec.
 instAboveISpec :: Instance -> T.ISpec -> T.OpResult ()
 instAboveISpec inst ispec
-  | mem inst < T.iSpecMemorySize ispec = T.OpFail T.FailMem
-  | dsk inst < T.iSpecDiskSize ispec   = T.OpFail T.FailDisk
-  | vcpus inst < T.iSpecCpuCount ispec = T.OpFail T.FailCPU
-  | otherwise = T.OpGood ()
+  | mem inst < T.iSpecMemorySize ispec = Bad T.FailMem
+  | dsk inst < T.iSpecDiskSize ispec   = Bad T.FailDisk
+  | vcpus inst < T.iSpecCpuCount ispec = Bad T.FailCPU
+  | otherwise = Ok ()
 
 -- | Checks if an instance matches a policy.
 instMatchesPolicy :: Instance -> T.IPolicy -> T.OpResult ()
@@ -280,8 +280,8 @@ instMatchesPolicy inst ipol = do
   instAboveISpec inst (T.iPolicyMinSpec ipol)
   instBelowISpec inst (T.iPolicyMaxSpec ipol)
   if diskTemplate inst `elem` T.iPolicyDiskTemplates ipol
-    then T.OpGood ()
-    else T.OpFail T.FailDisk
+    then Ok ()
+    else Bad T.FailDisk
 
 -- | Checks whether the instance uses a secondary node.
 --