From fafd07732ee9f081d03e010026088548d010c8de Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 7 Mar 2012 01:49:52 +0200 Subject: [PATCH] Add a helper function for mirrorType computations We most always use `templateMirrorType . diskTemplate`, so let's add a helper function for this. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- 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 983b30e67..e9e423afd 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 3d1762689..ae349054e 100644 --- a/htools/Ganeti/HTools/IAlloc.hs +++ b/htools/Ganeti/HTools/IAlloc.hs @@ -270,7 +270,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 269f3209c..42871b393 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 @@ -304,3 +305,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 a57ed4bd9..35225def5 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -237,8 +237,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] @@ -1297,8 +1296,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 -- GitLab