Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / Storage / Utils.hs @ 88d27b8a

History | View | Annotate | Download (2.9 kB)

1
{-| Implementation of Utility functions for storage
2

    
3
 -}
4

    
5
{-
6

    
7
Copyright (C) 2013 Google Inc.
8

    
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13

    
14
This program is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
General Public License for more details.
18

    
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
02110-1301, USA.
23

    
24
-}
25

    
26
module Ganeti.Storage.Utils
27
  ( getClusterStorageUnits
28
  ) where
29

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

    
34
type StorageUnit = (StorageType, String)
35

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

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

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

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

    
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