Commit fafd0773 authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 1d42996b
......@@ -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
......
......@@ -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"
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment