Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Storage / Utils.hs @ ac156ecd

History | View | Annotate | Download (3.5 kB)

1 00839a42 Helga Velroyen
{-| Implementation of Utility functions for storage
2 00839a42 Helga Velroyen
3 00839a42 Helga Velroyen
 -}
4 00839a42 Helga Velroyen
5 00839a42 Helga Velroyen
{-
6 00839a42 Helga Velroyen
7 00839a42 Helga Velroyen
Copyright (C) 2013 Google Inc.
8 00839a42 Helga Velroyen
9 00839a42 Helga Velroyen
This program is free software; you can redistribute it and/or modify
10 00839a42 Helga Velroyen
it under the terms of the GNU General Public License as published by
11 00839a42 Helga Velroyen
the Free Software Foundation; either version 2 of the License, or
12 00839a42 Helga Velroyen
(at your option) any later version.
13 00839a42 Helga Velroyen
14 00839a42 Helga Velroyen
This program is distributed in the hope that it will be useful, but
15 00839a42 Helga Velroyen
WITHOUT ANY WARRANTY; without even the implied warranty of
16 00839a42 Helga Velroyen
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 00839a42 Helga Velroyen
General Public License for more details.
18 00839a42 Helga Velroyen
19 00839a42 Helga Velroyen
You should have received a copy of the GNU General Public License
20 00839a42 Helga Velroyen
along with this program; if not, write to the Free Software
21 00839a42 Helga Velroyen
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 00839a42 Helga Velroyen
02110-1301, USA.
23 00839a42 Helga Velroyen
24 00839a42 Helga Velroyen
-}
25 00839a42 Helga Velroyen
26 00839a42 Helga Velroyen
module Ganeti.Storage.Utils
27 212b66c3 Helga Velroyen
  ( getStorageUnitsOfNodes
28 212b66c3 Helga Velroyen
  , nodesWithValidConfig
29 00839a42 Helga Velroyen
  ) where
30 00839a42 Helga Velroyen
31 212b66c3 Helga Velroyen
import Ganeti.Config
32 00839a42 Helga Velroyen
import Ganeti.Objects
33 00839a42 Helga Velroyen
import Ganeti.Types
34 00839a42 Helga Velroyen
import qualified Ganeti.Types as T
35 00839a42 Helga Velroyen
36 212b66c3 Helga Velroyen
import Control.Monad
37 ede6df3d Helga Velroyen
import Data.List (nub)
38 212b66c3 Helga Velroyen
import Data.Maybe
39 212b66c3 Helga Velroyen
import qualified Data.Map as M
40 00839a42 Helga Velroyen
41 00839a42 Helga Velroyen
-- | Get the cluster's default storage unit for a given disk template
42 212b66c3 Helga Velroyen
getDefaultStorageKey :: ConfigData -> DiskTemplate -> Maybe StorageKey
43 00839a42 Helga Velroyen
getDefaultStorageKey cfg T.DTDrbd8 = clusterVolumeGroupName $ configCluster cfg
44 00839a42 Helga Velroyen
getDefaultStorageKey cfg T.DTPlain = clusterVolumeGroupName $ configCluster cfg
45 00839a42 Helga Velroyen
getDefaultStorageKey cfg T.DTFile =
46 00839a42 Helga Velroyen
    Just (clusterFileStorageDir $ configCluster cfg)
47 00839a42 Helga Velroyen
getDefaultStorageKey cfg T.DTSharedFile =
48 00839a42 Helga Velroyen
    Just (clusterSharedFileStorageDir $ configCluster cfg)
49 00839a42 Helga Velroyen
getDefaultStorageKey _ _ = Nothing
50 00839a42 Helga Velroyen
51 00839a42 Helga Velroyen
-- | Get the cluster's default spindle storage unit
52 212b66c3 Helga Velroyen
getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe StorageKey)
53 00839a42 Helga Velroyen
getDefaultSpindleSU cfg =
54 00839a42 Helga Velroyen
    (T.StorageLvmPv, clusterVolumeGroupName $ configCluster cfg)
55 00839a42 Helga Velroyen
56 00839a42 Helga Velroyen
-- | Get the cluster's storage units from the configuration
57 212b66c3 Helga Velroyen
getClusterStorageUnitRaws :: ConfigData -> [StorageUnitRaw]
58 fa7f3e26 Helga Velroyen
getClusterStorageUnitRaws cfg =
59 fa7f3e26 Helga Velroyen
    foldSUs (nub (maybe_units ++ [spindle_unit]))
60 00839a42 Helga Velroyen
  where disk_templates = clusterEnabledDiskTemplates $ configCluster cfg
61 fa7f3e26 Helga Velroyen
        storage_types = map diskTemplateToStorageType disk_templates
62 00839a42 Helga Velroyen
        maybe_units = zip storage_types (map (getDefaultStorageKey cfg)
63 00839a42 Helga Velroyen
            disk_templates)
64 00839a42 Helga Velroyen
        spindle_unit = getDefaultSpindleSU cfg
65 00839a42 Helga Velroyen
66 00839a42 Helga Velroyen
-- | fold the storage unit list by sorting out the ones without keys
67 212b66c3 Helga Velroyen
foldSUs :: [(StorageType, Maybe StorageKey)] -> [StorageUnitRaw]
68 00839a42 Helga Velroyen
foldSUs = foldr ff []
69 212b66c3 Helga Velroyen
  where ff (st, Just sk) acc = SURaw st sk : acc
70 00839a42 Helga Velroyen
        ff (_, Nothing) acc = acc
71 00839a42 Helga Velroyen
72 212b66c3 Helga Velroyen
-- | Gets the value of the 'exclusive storage' flag of the node
73 212b66c3 Helga Velroyen
getExclusiveStorage :: ConfigData -> Node -> Maybe Bool
74 212b66c3 Helga Velroyen
getExclusiveStorage cfg n = liftM ndpExclusiveStorage (getNodeNdParams cfg n)
75 212b66c3 Helga Velroyen
76 212b66c3 Helga Velroyen
-- | Determines whether a node's config contains an 'exclusive storage' flag
77 212b66c3 Helga Velroyen
hasExclusiveStorageFlag :: ConfigData -> Node -> Bool
78 212b66c3 Helga Velroyen
hasExclusiveStorageFlag cfg = isJust . getExclusiveStorage cfg
79 212b66c3 Helga Velroyen
80 212b66c3 Helga Velroyen
-- | Filter for nodes with a valid config
81 212b66c3 Helga Velroyen
nodesWithValidConfig :: ConfigData -> [Node] -> [Node]
82 212b66c3 Helga Velroyen
nodesWithValidConfig cfg = filter (hasExclusiveStorageFlag cfg)
83 212b66c3 Helga Velroyen
84 212b66c3 Helga Velroyen
-- | Get the storage units of the node
85 212b66c3 Helga Velroyen
getStorageUnitsOfNode :: ConfigData -> Node -> [StorageUnit]
86 212b66c3 Helga Velroyen
getStorageUnitsOfNode cfg n =
87 212b66c3 Helga Velroyen
  let clusterSUs = getClusterStorageUnitRaws cfg
88 212b66c3 Helga Velroyen
      es = fromJust (getExclusiveStorage cfg n)
89 212b66c3 Helga Velroyen
  in  map (addParamsToStorageUnit es) clusterSUs
90 212b66c3 Helga Velroyen
91 212b66c3 Helga Velroyen
-- | Get the storage unit map for all nodes
92 212b66c3 Helga Velroyen
getStorageUnitsOfNodes :: ConfigData -> [Node] -> M.Map String [StorageUnit]
93 212b66c3 Helga Velroyen
getStorageUnitsOfNodes cfg ns =
94 212b66c3 Helga Velroyen
  M.fromList (map (\n -> (nodeUuid n, getStorageUnitsOfNode cfg n)) ns)