From 57f07ff20ab160bcb94c6245ef58d69e94d6377c Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 7 Jul 2011 00:57:14 +0200 Subject: [PATCH] htools: add ChangeGroup to IAllocator types/loader This patch updates the types and functions in IAllocator.hs and Loader.hs to the new design changes (elimination of multi-relocate mode and replacement with change-group). It also removes an extra re-export of EvacMode from Loader.hs. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htools/Ganeti/HTools/IAlloc.hs | 30 ++++++++---------------------- htools/Ganeti/HTools/Loader.hs | 10 +--------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/htools/Ganeti/HTools/IAlloc.hs b/htools/Ganeti/HTools/IAlloc.hs index 9afb18171..fa045d749 100644 --- a/htools/Ganeti/HTools/IAlloc.hs +++ b/htools/Ganeti/HTools/IAlloc.hs @@ -124,13 +124,6 @@ parseGroup u a = do apol <- extract "alloc_policy" return (u, Group.create name u apol) -parseTargetGroups :: JSRecord -- ^ The JSON object (request dict) - -> Group.List -- ^ The existing groups - -> Result [Gdx] -parseTargetGroups req map_g = do - group_uuids <- fromObjWithDefault req "target_groups" [] - mapM (liftM Group.idx . Container.findByName map_g) group_uuids - -- | Top-level parser. parseData :: String -- ^ The JSON message as received from Ganeti -> Result Request -- ^ A (possible valid) request @@ -186,22 +179,15 @@ parseData body = do ex_nodes <- mapM (Container.findByName map_n) ex_names let ex_ndx = map Node.idx ex_nodes return $ Evacuate ex_ndx - | optype == C.iallocatorModeMreloc -> + | optype == C.iallocatorModeChgGroup -> do rl_names <- extrReq "instances" - rl_insts <- mapM (Container.findByName map_i) rl_names - let rl_idx = map Instance.idx rl_insts - rl_mode <- - case extrReq "reloc_mode" of - Ok s | s == C.iallocatorMrelocKeep -> return KeepGroup - | s == C.iallocatorMrelocChange -> - do - tg_groups <- parseTargetGroups request map_g - return $ ChangeGroup tg_groups - | s == C.iallocatorMrelocAny -> return AnyGroup - | otherwise -> Bad $ "Invalid relocate mode " ++ s - Bad x -> Bad x - return $ MultiReloc rl_idx rl_mode + rl_insts <- mapM (liftM Instance.idx . + Container.findByName map_i) rl_names + gr_uuids <- extrReq "target_groups" + gr_idxes <- mapM (liftM Group.idx . + Container.findByName map_g) gr_uuids + return $ ChangeGroup rl_insts gr_idxes | optype == C.iallocatorModeNodeEvac -> do rl_names <- extrReq "instances" @@ -276,7 +262,7 @@ processRequest request = Cluster.tryMGReloc gl nl il idx reqn exnodes >>= formatAllocate Evacuate exnodes -> Cluster.tryMGEvac gl nl il exnodes >>= formatEvacuate - MultiReloc _ _ -> fail "multi-reloc not handled" + ChangeGroup _ _ -> fail "Request 'change-group' not implemented" NodeEvacuate xi mode -> Cluster.tryNodeEvac gl nl il mode xi >>= formatNodeEvac diff --git a/htools/Ganeti/HTools/Loader.hs b/htools/Ganeti/HTools/Loader.hs index cb74ed323..3747e971d 100644 --- a/htools/Ganeti/HTools/Loader.hs +++ b/htools/Ganeti/HTools/Loader.hs @@ -34,8 +34,6 @@ module Ganeti.HTools.Loader , lookupInstance , lookupGroup , commonSuffix - , RelocMode(..) - , EvacMode(..) , RqType(..) , Request(..) , ClusterData(..) @@ -67,12 +65,6 @@ exTagsPrefix = "htools:iextags:" -- * Types --- | The iallocator multi-evac group mode type. -data RelocMode = KeepGroup - | ChangeGroup [Gdx] - | AnyGroup - deriving (Show, Read) - {-| The iallocator request type. This type denotes what request we got from Ganeti and also holds @@ -84,7 +76,7 @@ data RqType | Relocate Idx Int [Ndx] -- ^ Move an instance to a new -- secondary node | Evacuate [Ndx] -- ^ Evacuate nodes - | MultiReloc [Idx] RelocMode -- ^ Multi-relocate mode + | ChangeGroup [Gdx] [Idx] -- ^ Multi-relocate mode | NodeEvacuate [Idx] EvacMode -- ^ node-evacuate mode deriving (Show, Read) -- GitLab