module Ganeti.Storage.Utils
( getStorageUnitsOfNode
, nodesWithValidConfig
) where
import Ganeti.Config
import Ganeti.Objects
import Ganeti.Types
import qualified Ganeti.Types as T
import Control.Monad
import Data.List (nub)
import Data.Maybe
getDefaultStorageKey :: ConfigData -> DiskTemplate -> Maybe StorageKey
getDefaultStorageKey cfg T.DTDrbd8 = clusterVolumeGroupName $ configCluster cfg
getDefaultStorageKey cfg T.DTPlain = clusterVolumeGroupName $ configCluster cfg
getDefaultStorageKey cfg T.DTFile =
Just (clusterFileStorageDir $ configCluster cfg)
getDefaultStorageKey _ _ = Nothing
getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe StorageKey)
getDefaultSpindleSU cfg =
(T.StorageLvmPv, clusterVolumeGroupName $ configCluster cfg)
getClusterStorageUnitRaws :: ConfigData -> [StorageUnitRaw]
getClusterStorageUnitRaws cfg =
foldSUs (nub (maybe_units ++ [spindle_unit]))
where disk_templates = clusterEnabledDiskTemplates $ configCluster cfg
storage_types = map diskTemplateToStorageType disk_templates
maybe_units = zip storage_types (map (getDefaultStorageKey cfg)
disk_templates)
spindle_unit = getDefaultSpindleSU cfg
foldSUs :: [(StorageType, Maybe StorageKey)] -> [StorageUnitRaw]
foldSUs = foldr ff []
where ff (st, Just sk) acc = SURaw st sk : acc
ff (_, Nothing) acc = acc
getExclusiveStorage :: ConfigData -> Node -> Maybe Bool
getExclusiveStorage cfg n = liftM ndpExclusiveStorage (getNodeNdParams cfg n)
hasExclusiveStorageFlag :: ConfigData -> Node -> Bool
hasExclusiveStorageFlag cfg = isJust . getExclusiveStorage cfg
nodesWithValidConfig :: ConfigData -> [Node] -> [Node]
nodesWithValidConfig cfg = filter (hasExclusiveStorageFlag cfg)
getStorageUnitsOfNode :: ConfigData -> Node -> [StorageUnit]
getStorageUnitsOfNode cfg n =
let clusterSUs = getClusterStorageUnitRaws cfg
es = fromJust (getExclusiveStorage cfg n)
in map (addParamsToStorageUnit es) clusterSUs