Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Storage / Utils.hs @ 4b763320

History | View | Annotate | Download (2.9 kB)

1 88d27b8a Helga Velroyen
{-| Implementation of Utility functions for storage
2 88d27b8a Helga Velroyen
3 88d27b8a Helga Velroyen
 -}
4 88d27b8a Helga Velroyen
5 88d27b8a Helga Velroyen
{-
6 88d27b8a Helga Velroyen
7 88d27b8a Helga Velroyen
Copyright (C) 2013 Google Inc.
8 88d27b8a Helga Velroyen
9 88d27b8a Helga Velroyen
This program is free software; you can redistribute it and/or modify
10 88d27b8a Helga Velroyen
it under the terms of the GNU General Public License as published by
11 88d27b8a Helga Velroyen
the Free Software Foundation; either version 2 of the License, or
12 88d27b8a Helga Velroyen
(at your option) any later version.
13 88d27b8a Helga Velroyen
14 88d27b8a Helga Velroyen
This program is distributed in the hope that it will be useful, but
15 88d27b8a Helga Velroyen
WITHOUT ANY WARRANTY; without even the implied warranty of
16 88d27b8a Helga Velroyen
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 88d27b8a Helga Velroyen
General Public License for more details.
18 88d27b8a Helga Velroyen
19 88d27b8a Helga Velroyen
You should have received a copy of the GNU General Public License
20 88d27b8a Helga Velroyen
along with this program; if not, write to the Free Software
21 88d27b8a Helga Velroyen
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 88d27b8a Helga Velroyen
02110-1301, USA.
23 88d27b8a Helga Velroyen
24 88d27b8a Helga Velroyen
-}
25 88d27b8a Helga Velroyen
26 88d27b8a Helga Velroyen
module Ganeti.Storage.Utils
27 88d27b8a Helga Velroyen
  ( getClusterStorageUnits
28 88d27b8a Helga Velroyen
  ) where
29 88d27b8a Helga Velroyen
30 88d27b8a Helga Velroyen
import Ganeti.Objects
31 88d27b8a Helga Velroyen
import Ganeti.Types
32 88d27b8a Helga Velroyen
import qualified Ganeti.Types as T
33 88d27b8a Helga Velroyen
34 88d27b8a Helga Velroyen
type StorageUnit = (StorageType, String)
35 88d27b8a Helga Velroyen
36 88d27b8a Helga Velroyen
-- | Get the cluster's default storage unit for a given disk template
37 88d27b8a Helga Velroyen
getDefaultStorageKey :: ConfigData -> DiskTemplate -> Maybe String
38 88d27b8a Helga Velroyen
getDefaultStorageKey cfg T.DTDrbd8 = clusterVolumeGroupName $ configCluster cfg
39 88d27b8a Helga Velroyen
getDefaultStorageKey cfg T.DTPlain = clusterVolumeGroupName $ configCluster cfg
40 88d27b8a Helga Velroyen
getDefaultStorageKey cfg T.DTFile =
41 88d27b8a Helga Velroyen
    Just (clusterFileStorageDir $ configCluster cfg)
42 88d27b8a Helga Velroyen
getDefaultStorageKey cfg T.DTSharedFile =
43 88d27b8a Helga Velroyen
    Just (clusterSharedFileStorageDir $ configCluster cfg)
44 88d27b8a Helga Velroyen
getDefaultStorageKey _ _ = Nothing
45 88d27b8a Helga Velroyen
46 88d27b8a Helga Velroyen
-- | Get the cluster's default spindle storage unit
47 88d27b8a Helga Velroyen
getDefaultSpindleSU :: ConfigData -> (StorageType, Maybe String)
48 88d27b8a Helga Velroyen
getDefaultSpindleSU cfg =
49 88d27b8a Helga Velroyen
    (T.StorageLvmPv, clusterVolumeGroupName $ configCluster cfg)
50 88d27b8a Helga Velroyen
51 88d27b8a Helga Velroyen
-- | Get the cluster's storage units from the configuration
52 88d27b8a Helga Velroyen
getClusterStorageUnits :: ConfigData -> [StorageUnit]
53 88d27b8a Helga Velroyen
getClusterStorageUnits cfg = foldSUs (maybe_units ++ [spindle_unit])
54 88d27b8a Helga Velroyen
  where disk_templates = clusterEnabledDiskTemplates $ configCluster cfg
55 88d27b8a Helga Velroyen
        storage_types = map diskTemplateToStorageType disk_templates
56 88d27b8a Helga Velroyen
        maybe_units = zip storage_types (map (getDefaultStorageKey cfg)
57 88d27b8a Helga Velroyen
            disk_templates)
58 88d27b8a Helga Velroyen
        spindle_unit = getDefaultSpindleSU cfg
59 88d27b8a Helga Velroyen
60 88d27b8a Helga Velroyen
-- | fold the storage unit list by sorting out the ones without keys
61 88d27b8a Helga Velroyen
foldSUs :: [(StorageType, Maybe String)] -> [StorageUnit]
62 88d27b8a Helga Velroyen
foldSUs = foldr ff []
63 88d27b8a Helga Velroyen
  where ff (st, Just sk) acc = (st, sk) : acc
64 88d27b8a Helga Velroyen
        ff (_, Nothing) acc = acc
65 88d27b8a Helga Velroyen
66 88d27b8a Helga Velroyen
-- | Mapping fo disk templates to storage type
67 88d27b8a Helga Velroyen
-- FIXME: This is semantically the same as the constant
68 88d27b8a Helga Velroyen
-- C.diskTemplatesStorageType
69 88d27b8a Helga Velroyen
diskTemplateToStorageType :: DiskTemplate -> StorageType
70 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTExt = T.StorageExt
71 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTFile = T.StorageFile
72 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTSharedFile = T.StorageFile
73 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTDrbd8 = T.StorageLvmVg
74 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTPlain = T.StorageLvmVg
75 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTRbd = T.StorageRados
76 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTDiskless = T.StorageDiskless
77 88d27b8a Helga Velroyen
diskTemplateToStorageType T.DTBlock = T.StorageBlock