Revision ebf38064 htools/Ganeti/HTools/Instance.hs

b/htools/Ganeti/HTools/Instance.hs
27 27
-}
28 28

  
29 29
module Ganeti.HTools.Instance
30
    ( Instance(..)
31
    , AssocList
32
    , List
33
    , create
34
    , instanceRunning
35
    , instanceOffline
36
    , instanceDown
37
    , applyIfOnline
38
    , setIdx
39
    , setName
40
    , setAlias
41
    , setPri
42
    , setSec
43
    , setBoth
44
    , setMovable
45
    , specOf
46
    , shrinkByType
47
    , localStorageTemplates
48
    , hasSecondary
49
    , requiredNodes
50
    , allNodes
51
    , usesLocalStorage
52
    ) where
30
  ( Instance(..)
31
  , AssocList
32
  , List
33
  , create
34
  , instanceRunning
35
  , instanceOffline
36
  , instanceDown
37
  , applyIfOnline
38
  , setIdx
39
  , setName
40
  , setAlias
41
  , setPri
42
  , setSec
43
  , setBoth
44
  , setMovable
45
  , specOf
46
  , shrinkByType
47
  , localStorageTemplates
48
  , hasSecondary
49
  , requiredNodes
50
  , allNodes
51
  , usesLocalStorage
52
  ) where
53 53

  
54 54
import qualified Ganeti.HTools.Types as T
55 55
import qualified Ganeti.HTools.Container as Container
......
61 61

  
62 62
-- | The instance type.
63 63
data Instance = Instance
64
    { name         :: String    -- ^ The instance name
65
    , alias        :: String    -- ^ The shortened name
66
    , mem          :: Int       -- ^ Memory of the instance
67
    , dsk          :: Int       -- ^ Disk size of instance
68
    , vcpus        :: Int       -- ^ Number of VCPUs
69
    , runSt        :: T.InstanceStatus -- ^ Original run status
70
    , pNode        :: T.Ndx     -- ^ Original primary node
71
    , sNode        :: T.Ndx     -- ^ Original secondary node
72
    , idx          :: T.Idx     -- ^ Internal index
73
    , util         :: T.DynUtil -- ^ Dynamic resource usage
74
    , movable      :: Bool      -- ^ Can and should the instance be moved?
75
    , autoBalance  :: Bool      -- ^ Is the instance auto-balanced?
76
    , tags         :: [String]  -- ^ List of instance tags
77
    , diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
78
    } deriving (Show, Read)
64
  { name         :: String    -- ^ The instance name
65
  , alias        :: String    -- ^ The shortened name
66
  , mem          :: Int       -- ^ Memory of the instance
67
  , dsk          :: Int       -- ^ Disk size of instance
68
  , vcpus        :: Int       -- ^ Number of VCPUs
69
  , runSt        :: T.InstanceStatus -- ^ Original run status
70
  , pNode        :: T.Ndx     -- ^ Original primary node
71
  , sNode        :: T.Ndx     -- ^ Original secondary node
72
  , idx          :: T.Idx     -- ^ Internal index
73
  , util         :: T.DynUtil -- ^ Dynamic resource usage
74
  , movable      :: Bool      -- ^ Can and should the instance be moved?
75
  , autoBalance  :: Bool      -- ^ Is the instance auto-balanced?
76
  , tags         :: [String]  -- ^ List of instance tags
77
  , diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
78
  } deriving (Show, Read)
79 79

  
80 80
instance T.Element Instance where
81
    nameOf   = name
82
    idxOf    = idx
83
    setAlias = setAlias
84
    setIdx   = setIdx
85
    allNames n = [name n, alias n]
81
  nameOf   = name
82
  idxOf    = idx
83
  setAlias = setAlias
84
  setIdx   = setIdx
85
  allNames n = [name n, alias n]
86 86

  
87 87
-- | Check if instance is running.
88 88
instanceRunning :: Instance -> Bool
89 89
instanceRunning (Instance {runSt = T.Running}) = True
90 90
instanceRunning (Instance {runSt = T.ErrorUp}) = True
91
instanceRunning _                               = False
91
instanceRunning _                              = False
92 92

  
93 93
-- | Check if instance is offline.
94 94
instanceOffline :: Instance -> Bool
95 95
instanceOffline (Instance {runSt = T.AdminOffline}) = True
96
instanceOffline _                                    = False
96
instanceOffline _                                   = False
97 97

  
98 98
-- | Check if instance is down.
99 99
instanceDown :: Instance -> Bool
......
141 141
       -> [String] -> Bool -> T.Ndx -> T.Ndx -> T.DiskTemplate -> Instance
142 142
create name_init mem_init dsk_init vcpus_init run_init tags_init
143 143
       auto_balance_init pn sn dt =
144
    Instance { name = name_init
145
             , alias = name_init
146
             , mem = mem_init
147
             , dsk = dsk_init
148
             , vcpus = vcpus_init
149
             , runSt = run_init
150
             , pNode = pn
151
             , sNode = sn
152
             , idx = -1
153
             , util = T.baseUtil
154
             , tags = tags_init
155
             , movable = supportsMoves dt
156
             , autoBalance = auto_balance_init
157
             , diskTemplate = dt
158
             }
144
  Instance { name = name_init
145
           , alias = name_init
146
           , mem = mem_init
147
           , dsk = dsk_init
148
           , vcpus = vcpus_init
149
           , runSt = run_init
150
           , pNode = pn
151
           , sNode = sn
152
           , idx = -1
153
           , util = T.baseUtil
154
           , tags = tags_init
155
           , movable = supportsMoves dt
156
           , autoBalance = auto_balance_init
157
           , diskTemplate = dt
158
           }
159 159

  
160 160
-- | Changes the index.
161 161
--
......
228 228
-- | Return the spec of an instance.
229 229
specOf :: Instance -> T.RSpec
230 230
specOf Instance { mem = m, dsk = d, vcpus = c } =
231
    T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
231
  T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d }
232 232

  
233 233
-- | Checks whether the instance uses a secondary node.
234 234
--

Also available in: Unified diff