We most always use `templateMirrorType . diskTemplate`, so let's add a
helper function for this.
---
 htools/Ganeti/HTools/Cluster.hs  |    4 ++--
 htools/Ganeti/HTools/IAlloc.hs   |    2 +-
 htools/Ganeti/HTools/Instance.hs |    5 +++++
 htools/Ganeti/HTools/QC.hs       |    7 +++----
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs
index 6879bf1..835287b 100644
--- a/htools/Ganeti/HTools/Cluster.hs
+++ b/htools/Ganeti/HTools/Cluster.hs
@@ -563,7 +563,7 @@ checkInstanceMove nodes_idx disk_moves inst_moves ini_tbl 
target =
       osdx = Instance.sNode target
       bad_nodes = [opdx, osdx]
       nodes = filter (`notElem` bad_nodes) nodes_idx
-      mir_type = templateMirrorType $ Instance.diskTemplate target
+      mir_type = Instance.mirrorType target
       use_secondary = elem osdx nodes_idx && inst_moves
       aft_failover = if mir_type == MirrorInternal && use_secondary
                        -- if drbd and allowed to failover
@@ -970,7 +970,7 @@ evacOneNodeOnly :: Node.List         -- ^ The node list 
(cluster-wide)
                                       -- for allocation
                 -> Result (Node.List, Instance.List, [OpCodes.OpCode])
 evacOneNodeOnly nl il inst gdx avail_nodes = do
-  op_fn <- case templateMirrorType (Instance.diskTemplate inst) of
+  op_fn <- case Instance.mirrorType inst of
              MirrorNone -> Bad "Can't relocate/evacuate non-mirrored instances"
              MirrorInternal -> Ok ReplaceSecondary
              MirrorExternal -> Ok FailoverToAny
diff --git a/htools/Ganeti/HTools/IAlloc.hs b/htools/Ganeti/HTools/IAlloc.hs
index d426aef..6200f1f 100644
--- a/htools/Ganeti/HTools/IAlloc.hs
+++ b/htools/Ganeti/HTools/IAlloc.hs
@@ -269,7 +269,7 @@ processRelocate gl nl il idx 1 exndx = do
   let orig = Container.find idx il
       sorig = Instance.sNode orig
       porig = Instance.pNode orig
-      mir_type = templateMirrorType $ Instance.diskTemplate orig
+      mir_type = Instance.mirrorType orig
   (exp_node, node_type, reloc_type) <-
     case mir_type of
       MirrorNone -> fail "Can't relocate non-mirrored instances"
diff --git a/htools/Ganeti/HTools/Instance.hs b/htools/Ganeti/HTools/Instance.hs
index 8de3c8b..1b3af86 100644
--- a/htools/Ganeti/HTools/Instance.hs
+++ b/htools/Ganeti/HTools/Instance.hs
@@ -54,6 +54,7 @@ module Ganeti.HTools.Instance
   , requiredNodes
   , allNodes
   , usesLocalStorage
+  , mirrorType
   ) where
 
 import qualified Ganeti.HTools.Types as T
@@ -301,3 +302,7 @@ usesLocalStorage = (`elem` localStorageTemplates) . 
diskTemplate
 -- | Checks whether a given disk template supported moves.
 supportsMoves :: T.DiskTemplate -> Bool
 supportsMoves = (`elem` movableDiskTemplates)
+
+-- | A simple wrapper over 'T.templateMirrorType'.
+mirrorType :: Instance -> T.MirrorType
+mirrorType = T.templateMirrorType . diskTemplate
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 3e7a2f8..f621f0a 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -234,8 +234,7 @@ genUniquesList cnt =
 
 -- | Checks if an instance is mirrored.
 isMirrored :: Instance.Instance -> Bool
-isMirrored =
-  (/= Types.MirrorNone) . Types.templateMirrorType . Instance.diskTemplate
+isMirrored = (/= Types.MirrorNone) . Instance.mirrorType
 
 -- | Returns the possible change node types for a disk template.
 evacModeOptions :: Types.MirrorType -> [Types.EvacMode]
@@ -1281,8 +1280,8 @@ prop_ClusterAllocEvacuate =
       conjoin $ map (\mode -> check_EvacMode defGroup inst' $
                               Cluster.tryNodeEvac defGroupList nl il mode
                                 [Instance.idx inst']) .
-                              evacModeOptions . Types.templateMirrorType .
-                              Instance.diskTemplate $ inst'
+                              evacModeOptions .
+                              Instance.mirrorType $ inst'
 
 -- | Checks that on a 4-8 node cluster with two node groups, once we
 -- allocate an instance on the first node group, we can also change
-- 
1.7.9.1

Reply via email to