Revision 212b66c3 src/Ganeti/Storage/Utils.hs

b/src/Ganeti/Storage/Utils.hs
24 24
-}
25 25

  
26 26
module Ganeti.Storage.Utils
27
  ( getClusterStorageUnits
27
  ( getStorageUnitsOfNodes
28
  , nodesWithValidConfig
28 29
  ) where
29 30

  
31
import Ganeti.Config
30 32
import Ganeti.Objects
31 33
import Ganeti.Types
32 34
import qualified Ganeti.Types as T
33 35

  
34
type StorageUnit = (StorageType, String)
36
import Control.Monad
37
import Data.Maybe
38
import qualified Data.Map as M
35 39

  
36 40
-- | Get the cluster's default storage unit for a given disk template
37
getDefaultStorageKey :: ConfigData -> DiskTemplate -> Maybe String
41
getDefaultStorageKey :: ConfigData -> DiskTemplate -> Maybe StorageKey
38 42
getDefaultStorageKey cfg T.DTDrbd8 = clusterVolumeGroupName $ configCluster cfg
39 43
getDefaultStorageKey cfg T.DTPlain = clusterVolumeGroupName $ configCluster cfg
40 44
getDefaultStorageKey cfg T.DTFile =
......
44 48
getDefaultStorageKey _ _ = Nothing
45 49

  
46 50
-- | Get the cluster's default spindle storage unit
47
getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe String)
51
getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe StorageKey)
48 52
getDefaultSpindleSU cfg =
49 53
    (T.StorageLvmPv, clusterVolumeGroupName $ configCluster cfg)
50 54

  
51 55
-- | Get the cluster's storage units from the configuration
52
getClusterStorageUnits :: ConfigData -> [StorageUnit]
53
getClusterStorageUnits cfg = foldSUs (maybe_units ++ [spindle_unit])
56
getClusterStorageUnitRaws :: ConfigData -> [StorageUnitRaw]
57
getClusterStorageUnitRaws cfg = foldSUs (maybe_units ++ [spindle_unit])
54 58
  where disk_templates = clusterEnabledDiskTemplates $ configCluster cfg
55 59
        storage_types = map diskTemplateToStorageType disk_templates
56 60
        maybe_units = zip storage_types (map (getDefaultStorageKey cfg)
......
58 62
        spindle_unit = getDefaultSpindleSU cfg
59 63

  
60 64
-- | fold the storage unit list by sorting out the ones without keys
61
foldSUs :: [(StorageType, Maybe String)] -> [StorageUnit]
65
foldSUs :: [(StorageType, Maybe StorageKey)] -> [StorageUnitRaw]
62 66
foldSUs = foldr ff []
63
  where ff (st, Just sk) acc = (st, sk) : acc
67
  where ff (st, Just sk) acc = SURaw st sk : acc
64 68
        ff (_, Nothing) acc = acc
65 69

  
66
-- | Mapping fo disk templates to storage type
67
-- FIXME: This is semantically the same as the constant
68
-- C.diskTemplatesStorageType
69
diskTemplateToStorageType :: DiskTemplate -> StorageType
70
diskTemplateToStorageType T.DTExt = T.StorageExt
71
diskTemplateToStorageType T.DTFile = T.StorageFile
72
diskTemplateToStorageType T.DTSharedFile = T.StorageFile
73
diskTemplateToStorageType T.DTDrbd8 = T.StorageLvmVg
74
diskTemplateToStorageType T.DTPlain = T.StorageLvmVg
75
diskTemplateToStorageType T.DTRbd = T.StorageRados
76
diskTemplateToStorageType T.DTDiskless = T.StorageDiskless
77
diskTemplateToStorageType T.DTBlock = T.StorageBlock
70
-- | Gets the value of the 'exclusive storage' flag of the node
71
getExclusiveStorage :: ConfigData -> Node -> Maybe Bool
72
getExclusiveStorage cfg n = liftM ndpExclusiveStorage (getNodeNdParams cfg n)
73

  
74
-- | Determines whether a node's config contains an 'exclusive storage' flag
75
hasExclusiveStorageFlag :: ConfigData -> Node -> Bool
76
hasExclusiveStorageFlag cfg = isJust . getExclusiveStorage cfg
77

  
78
-- | Filter for nodes with a valid config
79
nodesWithValidConfig :: ConfigData -> [Node] -> [Node]
80
nodesWithValidConfig cfg = filter (hasExclusiveStorageFlag cfg)
81

  
82
-- | Get the storage units of the node
83
getStorageUnitsOfNode :: ConfigData -> Node -> [StorageUnit]
84
getStorageUnitsOfNode cfg n =
85
  let clusterSUs = getClusterStorageUnitRaws cfg
86
      es = fromJust (getExclusiveStorage cfg n)
87
  in  map (addParamsToStorageUnit es) clusterSUs
88

  
89
-- | Get the storage unit map for all nodes
90
getStorageUnitsOfNodes :: ConfigData -> [Node] -> M.Map String [StorageUnit]
91
getStorageUnitsOfNodes cfg ns =
92
  M.fromList (map (\n -> (nodeUuid n, getStorageUnitsOfNode cfg n)) ns)

Also available in: Unified diff