root / src / Ganeti / Storage / Utils.hs @ 13d26b66
History | View | Annotate | Download (3.4 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 _ _ = Nothing |
48 | 00839a42 | Helga Velroyen | |
49 | 00839a42 | Helga Velroyen | -- | Get the cluster's default spindle storage unit |
50 | 212b66c3 | Helga Velroyen | getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe StorageKey) |
51 | 00839a42 | Helga Velroyen | getDefaultSpindleSU cfg = |
52 | 00839a42 | Helga Velroyen | (T.StorageLvmPv, clusterVolumeGroupName $ configCluster cfg) |
53 | 00839a42 | Helga Velroyen | |
54 | 00839a42 | Helga Velroyen | -- | Get the cluster's storage units from the configuration |
55 | 212b66c3 | Helga Velroyen | getClusterStorageUnitRaws :: ConfigData -> [StorageUnitRaw] |
56 | fa7f3e26 | Helga Velroyen | getClusterStorageUnitRaws cfg = |
57 | fa7f3e26 | Helga Velroyen | foldSUs (nub (maybe_units ++ [spindle_unit])) |
58 | 00839a42 | Helga Velroyen | where disk_templates = clusterEnabledDiskTemplates $ configCluster cfg |
59 | fa7f3e26 | Helga Velroyen | storage_types = map diskTemplateToStorageType disk_templates |
60 | 00839a42 | Helga Velroyen | maybe_units = zip storage_types (map (getDefaultStorageKey cfg) |
61 | 00839a42 | Helga Velroyen | disk_templates) |
62 | 00839a42 | Helga Velroyen | spindle_unit = getDefaultSpindleSU cfg |
63 | 00839a42 | Helga Velroyen | |
64 | 00839a42 | Helga Velroyen | -- | fold the storage unit list by sorting out the ones without keys |
65 | 212b66c3 | Helga Velroyen | foldSUs :: [(StorageType, Maybe StorageKey)] -> [StorageUnitRaw] |
66 | 00839a42 | Helga Velroyen | foldSUs = foldr ff [] |
67 | 212b66c3 | Helga Velroyen | where ff (st, Just sk) acc = SURaw st sk : acc |
68 | 00839a42 | Helga Velroyen | ff (_, Nothing) acc = acc |
69 | 00839a42 | Helga Velroyen | |
70 | 212b66c3 | Helga Velroyen | -- | Gets the value of the 'exclusive storage' flag of the node |
71 | 212b66c3 | Helga Velroyen | getExclusiveStorage :: ConfigData -> Node -> Maybe Bool |
72 | 212b66c3 | Helga Velroyen | getExclusiveStorage cfg n = liftM ndpExclusiveStorage (getNodeNdParams cfg n) |
73 | 212b66c3 | Helga Velroyen | |
74 | 212b66c3 | Helga Velroyen | -- | Determines whether a node's config contains an 'exclusive storage' flag |
75 | 212b66c3 | Helga Velroyen | hasExclusiveStorageFlag :: ConfigData -> Node -> Bool |
76 | 212b66c3 | Helga Velroyen | hasExclusiveStorageFlag cfg = isJust . getExclusiveStorage cfg |
77 | 212b66c3 | Helga Velroyen | |
78 | 212b66c3 | Helga Velroyen | -- | Filter for nodes with a valid config |
79 | 212b66c3 | Helga Velroyen | nodesWithValidConfig :: ConfigData -> [Node] -> [Node] |
80 | 212b66c3 | Helga Velroyen | nodesWithValidConfig cfg = filter (hasExclusiveStorageFlag cfg) |
81 | 212b66c3 | Helga Velroyen | |
82 | 212b66c3 | Helga Velroyen | -- | Get the storage units of the node |
83 | 212b66c3 | Helga Velroyen | getStorageUnitsOfNode :: ConfigData -> Node -> [StorageUnit] |
84 | 212b66c3 | Helga Velroyen | getStorageUnitsOfNode cfg n = |
85 | 212b66c3 | Helga Velroyen | let clusterSUs = getClusterStorageUnitRaws cfg |
86 | 212b66c3 | Helga Velroyen | es = fromJust (getExclusiveStorage cfg n) |
87 | 212b66c3 | Helga Velroyen | in map (addParamsToStorageUnit es) clusterSUs |
88 | 212b66c3 | Helga Velroyen | |
89 | 212b66c3 | Helga Velroyen | -- | Get the storage unit map for all nodes |
90 | 212b66c3 | Helga Velroyen | getStorageUnitsOfNodes :: ConfigData -> [Node] -> M.Map String [StorageUnit] |
91 | 212b66c3 | Helga Velroyen | getStorageUnitsOfNodes cfg ns = |
92 | 212b66c3 | Helga Velroyen | M.fromList (map (\n -> (nodeUuid n, getStorageUnitsOfNode cfg n)) ns) |