Revision 8353b5e1

b/htools/Ganeti/HTools/Instance.hs
41 41
    , specOf
42 42
    , shrinkByType
43 43
    , runningStates
44
    , localStorageTemplates
45
    , hasSecondary
44 46
    , requiredNodes
45 47
    , allNodes
48
    , usesLocalStorage
46 49
    ) where
47 50

  
48 51
import qualified Ganeti.HTools.Types as T
......
64 67
    , sNode        :: T.Ndx     -- ^ Original secondary node
65 68
    , idx          :: T.Idx     -- ^ Internal index
66 69
    , util         :: T.DynUtil -- ^ Dynamic resource usage
67
    , movable      :: Bool      -- ^ Can the instance be moved?
70
    , movable      :: Bool      -- ^ Can and should the instance be moved?
68 71
    , autoBalance  :: Bool      -- ^ Is the instance auto-balanced?
69 72
    , tags         :: [String]  -- ^ List of instance tags
70 73
    , diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
......
81 84
runningStates :: [String]
82 85
runningStates = [C.inststRunning, C.inststErrorup]
83 86

  
87
-- | Constant holding the local storage templates.
88
--
89
-- /Note:/ Currently Ganeti only exports node total/free disk space
90
-- for LVM-based storage; file-based storage is ignored in this model,
91
-- so even though file-based storage uses in reality disk space on the
92
-- node, in our model it won't affect it and we can't compute whether
93
-- there is enough disk space for a file-based instance. Therefore we
94
-- will treat this template as \'foreign\' storage.
95
localStorageTemplates :: [T.DiskTemplate]
96
localStorageTemplates = [ T.DTDrbd8, T.DTPlain ]
97

  
98
-- | Constant holding the movable disk templates.
99
--
100
-- This only determines the initial 'movable' state of the
101
-- instance. Further the movable state can be restricted more due to
102
-- user choices, etc.
103
movableDiskTemplates :: [T.DiskTemplate]
104
movableDiskTemplates = [ T.DTDrbd8, T.DTBlock, T.DTSharedFile ]
105

  
84 106
-- | A simple name for the int, instance association list.
85 107
type AssocList = [(T.Idx, Instance)]
86 108

  
......
109 131
             , idx = -1
110 132
             , util = T.baseUtil
111 133
             , tags = tags_init
112
             , movable = True
134
             , movable = supportsMoves dt
113 135
             , autoBalance = auto_balance_init
114 136
             , diskTemplate = dt
115 137
             }
......
187 209
specOf Instance { mem = m, dsk = d, vcpus = c } =
188 210
    T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
189 211

  
212
-- | Checks whether the instance uses a secondary node.
213
--
214
-- /Note:/ This should be reconciled with @'sNode' ==
215
-- 'Node.noSecondary'@.
216
hasSecondary :: Instance -> Bool
217
hasSecondary = (== T.DTDrbd8) . diskTemplate
218

  
190 219
-- | Computed the number of nodes for a given disk template.
191 220
requiredNodes :: T.DiskTemplate -> Int
192 221
requiredNodes T.DTDrbd8 = 2
......
197 226
allNodes inst = case diskTemplate inst of
198 227
                  T.DTDrbd8 -> [pNode inst, sNode inst]
199 228
                  _ -> [pNode inst]
229

  
230
-- | Checks whether a given disk template uses local storage.
231
usesLocalStorage :: Instance -> Bool
232
usesLocalStorage = (`elem` localStorageTemplates) . diskTemplate
233

  
234
-- | Checks whether a given disk template supported moves.
235
supportsMoves :: T.DiskTemplate -> Bool
236
supportsMoves = (`elem` movableDiskTemplates)

Also available in: Unified diff