X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/525bfb36bbd0404b8f2d49169ea20a6e3b064de6..5a4a3b7f0edcfc4d82d647828d05c1779b7e1eae:/htools/Ganeti/HTools/Types.hs?ds=sidebyside diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs index be7ec18..efa2f0a 100644 --- a/htools/Ganeti/HTools/Types.hs +++ b/htools/Ganeti/HTools/Types.hs @@ -48,6 +48,9 @@ module Ganeti.HTools.Types , unknownField , Placement , IMove(..) + , DiskTemplate(..) + , dtToString + , dtFromString , MoveJob , JobSet , Result(..) @@ -59,6 +62,7 @@ module Ganeti.HTools.Types , OpResult(..) , connTimeout , queryTimeout + , EvacMode(..) ) where import qualified Data.Map as M @@ -100,7 +104,7 @@ data AllocPolicy -- last-resort, after the preferred groups | AllocUnallocable -- ^ This group must not be used for new -- allocations - deriving (Show, Read, Eq, Ord) + deriving (Show, Read, Eq, Ord, Enum, Bounded) -- | Convert a string to an alloc policy. apolFromString :: (Monad m) => String -> m AllocPolicy @@ -174,6 +178,43 @@ data IMove = Failover -- ^ Failover the instance (f) | FailoverAndReplace Ndx -- ^ Failover, replace secondary (f, r:ns) deriving (Show, Read) +-- | Instance disk template type +data DiskTemplate = DTDiskless + | DTFile + | DTSharedFile + | DTPlain + | DTBlock + | DTDrbd8 + deriving (Show, Read, Eq, Enum, Bounded) + +-- | Converts a DiskTemplate to String +dtToString :: DiskTemplate -> String +dtToString DTDiskless = C.dtDiskless +dtToString DTFile = C.dtFile +dtToString DTSharedFile = C.dtSharedFile +dtToString DTPlain = C.dtPlain +dtToString DTBlock = C.dtBlock +dtToString DTDrbd8 = C.dtDrbd8 + +-- | Converts a DiskTemplate from String +dtFromString :: (Monad m) => String -> m DiskTemplate +dtFromString s = + case () of + _ | s == C.dtDiskless -> return DTDiskless + | s == C.dtFile -> return DTFile + | s == C.dtSharedFile -> return DTSharedFile + | s == C.dtPlain -> return DTPlain + | s == C.dtBlock -> return DTBlock + | s == C.dtDrbd8 -> return DTDrbd8 + | otherwise -> fail $ "Invalid disk template: " ++ s + +instance JSON.JSON DiskTemplate where + showJSON = JSON.showJSON . dtToString + readJSON s = case JSON.readJSON s of + JSON.Ok s' -> dtFromString s' + JSON.Error e -> JSON.Error $ + "Can't parse disk_template as string: " ++ e + -- | Formatted solution output for one move (involved nodes and -- commands. type MoveJob = ([Ndx], Idx, IMove, [String]) @@ -279,3 +320,9 @@ class Element a where name = nameOf e -- | Updates the index of the element setIdx :: a -> Int -> a + +-- | The iallocator node-evacuate evac_mode type. +data EvacMode = ChangePrimary + | ChangeSecondary + | ChangeAll + deriving (Show, Read)