Revision 8bc34c7b

b/htools/Ganeti/HTools/IAlloc.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2009, 2010, 2011 Google Inc.
7
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
105 105
  let vm_capable' = fromMaybe True vm_capable
106 106
  gidx <- lookupGroup ktg n guuid
107 107
  node <- if offline || drained || not vm_capable'
108
            then return $ Node.create n 0 0 0 0 0 0 True gidx
108
            then return $ Node.create n 0 0 0 0 0 0 True 0 gidx
109 109
            else do
110 110
              mtotal <- extract "total_memory"
111 111
              mnode  <- extract "reserved_memory"
......
113 113
              dtotal <- extract "total_disk"
114 114
              dfree  <- extract "free_disk"
115 115
              ctotal <- extract "total_cpus"
116
              ndparams <- extract "ndparams" >>= asJSObject
117
              spindles <- tryFromObj desc (fromJSObject ndparams)
118
                          "spindle_count"
116 119
              return $ Node.create n mtotal mnode mfree
117
                     dtotal dfree ctotal False gidx
120
                     dtotal dfree ctotal False spindles gidx
118 121
  return (n, node)
119 122

  
120 123
-- | Parses a group as found in the cluster group list.
b/htools/Ganeti/HTools/Luxi.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2009, 2010, 2011 Google Inc.
7
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
99 99
queryNodesMsg =
100 100
  L.Query L.QRNode ["name", "mtotal", "mnode", "mfree", "dtotal", "dfree",
101 101
                    "ctotal", "offline", "drained", "vm_capable",
102
                    "group.uuid"] ()
102
                    "ndp/spindle_count", "group.uuid"] ()
103 103

  
104 104
-- | The input data for instance query.
105 105
queryInstancesMsg :: L.LuxiOp
......
175 175
-- | Construct a node from a JSON object.
176 176
parseNode :: NameAssoc -> [(JSValue, JSValue)] -> Result (String, Node.Node)
177 177
parseNode ktg [ name, mtotal, mnode, mfree, dtotal, dfree
178
              , ctotal, offline, drained, vm_capable, g_uuid ]
178
              , ctotal, offline, drained, vm_capable, spindles, g_uuid ]
179 179
    = do
180 180
  xname <- annotateResult "Parsing new node" (fromJValWithStatus name)
181 181
  let convert a = genericConvert "Node" xname a
182 182
  xoffline <- convert "offline" offline
183 183
  xdrained <- convert "drained" drained
184 184
  xvm_capable <- convert "vm_capable" vm_capable
185
  xspindles <- convert "spindles" spindles
185 186
  xgdx   <- convert "group.uuid" g_uuid >>= lookupGroup ktg xname
186 187
  node <- if xoffline || xdrained || not xvm_capable
187
            then return $ Node.create xname 0 0 0 0 0 0 True xgdx
188
            then return $ Node.create xname 0 0 0 0 0 0 True xspindles xgdx
188 189
            else do
189 190
              xmtotal  <- convert "mtotal" mtotal
190 191
              xmnode   <- convert "mnode" mnode
......
193 194
              xdfree   <- convert "dfree" dfree
194 195
              xctotal  <- convert "ctotal" ctotal
195 196
              return $ Node.create xname xmtotal xmnode xmfree
196
                     xdtotal xdfree xctotal False xgdx
197
                     xdtotal xdfree xctotal False xspindles xgdx
197 198
  return (xname, node)
198 199

  
199 200
parseNode _ v = fail ("Invalid node query result: " ++ show v)
b/htools/Ganeti/HTools/Node.hs
101 101
  , fDsk     :: Int       -- ^ Free disk space (MiB)
102 102
  , tCpu     :: Double    -- ^ Total CPU count
103 103
  , uCpu     :: Int       -- ^ Used VCPU count
104
  , spindleCount :: Int   -- ^ Node spindles (spindle_count node parameter)
104 105
  , pList    :: [T.Idx]   -- ^ List of primary instance indices
105 106
  , sList    :: [T.Idx]   -- ^ List of secondary instance indices
106 107
  , idx      :: T.Ndx     -- ^ Internal index for book-keeping
......
117 118
                          -- threshold
118 119
  , hiCpu    :: Int       -- ^ Autocomputed from mCpu high cpu
119 120
                          -- threshold
121
  , hiSpindles :: Double  -- ^ Auto-computed from policy spindle_ratio
122
                          -- and the node spindle count
123
  , instSpindles :: Double -- ^ Spindles used by instances
120 124
  , offline  :: Bool      -- ^ Whether the node should not be used for
121 125
                          -- allocations and skipped from score
122 126
                          -- computations
......
188 192
-- The index and the peers maps are empty, and will be need to be
189 193
-- update later via the 'setIdx' and 'buildPeers' functions.
190 194
create :: String -> Double -> Int -> Int -> Double
191
       -> Int -> Double -> Bool -> T.Gdx -> Node
195
       -> Int -> Double -> Bool -> Int -> T.Gdx -> Node
192 196
create name_init mem_t_init mem_n_init mem_f_init
193
       dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
197
       dsk_t_init dsk_f_init cpu_t_init offline_init spindles_init
198
       group_init =
194 199
  Node { name = name_init
195 200
       , alias = name_init
196 201
       , tMem = mem_t_init
......
199 204
       , tDsk = dsk_t_init
200 205
       , fDsk = dsk_f_init
201 206
       , tCpu = cpu_t_init
207
       , spindleCount = spindles_init
202 208
       , uCpu = 0
203 209
       , pList = []
204 210
       , sList = []
......
215 221
       , mDsk = T.defReservedDiskRatio
216 222
       , loDsk = mDskToloDsk T.defReservedDiskRatio dsk_t_init
217 223
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio T.defIPolicy) cpu_t_init
224
       , hiSpindles = computeHiSpindles (T.iPolicySpindleRatio T.defIPolicy)
225
                      spindles_init
226
       , instSpindles = 0
218 227
       , utilPool = T.baseUtil
219 228
       , utilLoad = T.zeroUtil
220 229
       , pTags = Map.empty
......
230 239
mCpuTohiCpu :: Double -> Double -> Int
231 240
mCpuTohiCpu mval = floor . (mval *)
232 241

  
242
-- | Conversiojn formula from spindles and spindle ratio to hiSpindles.
243
computeHiSpindles :: Double -> Int -> Double
244
computeHiSpindles spindle_ratio = (spindle_ratio *) . fromIntegral
245

  
233 246
-- | Changes the index.
234 247
--
235 248
-- This is used only during the building of the data structures.
......
265 278
setPolicy :: T.IPolicy -> Node -> Node
266 279
setPolicy pol node =
267 280
  node { iPolicy = pol
268
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node) }
281
       , hiCpu = mCpuTohiCpu (T.iPolicyVcpuRatio pol) (tCpu node)
282
       , hiSpindles = computeHiSpindles (T.iPolicySpindleRatio pol)
283
                      (spindleCount node)
284
       }
269 285

  
270 286
-- | Computes the maximum reserved memory for peers from a peer map.
271 287
computeMaxRes :: P.PeerMap -> P.Elem
b/htools/Ganeti/HTools/QC.hs
342 342
  cpu_t <- choose (base_cpu, top_cpu)
343 343
  offl  <- arbitrary
344 344
  let n = Node.create name (fromIntegral mem_t) mem_n mem_f
345
          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 0
345
          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 1 0
346 346
      n' = Node.setPolicy nullIPolicy n
347 347
  return $ Node.buildPeers n' Container.empty
348 348

  
b/htools/Ganeti/HTools/Rapi.hs
4 4

  
5 5
{-
6 6

  
7
Copyright (C) 2009, 2010, 2011 Google Inc.
7
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
8 8

  
9 9
This program is free software; you can redistribute it and/or modify
10 10
it under the terms of the GNU General Public License as published by
......
137 137
  drained <- extract "drained"
138 138
  vm_cap  <- annotateResult desc $ maybeFromObj a "vm_capable"
139 139
  let vm_cap' = fromMaybe True vm_cap
140
  ndparams <- extract "ndparams" >>= asJSObject
141
  spindles <- tryFromObj desc (fromJSObject ndparams) "spindle_count"
140 142
  guuid   <- annotateResult desc $ maybeFromObj a "group.uuid"
141 143
  guuid' <-  lookupGroup ktg name (fromMaybe defaultGroupID guuid)
142 144
  node <- if offline || drained || not vm_cap'
143
            then return $ Node.create name 0 0 0 0 0 0 True guuid'
145
            then return $ Node.create name 0 0 0 0 0 0 True 0 guuid'
144 146
            else do
145 147
              mtotal  <- extract "mtotal"
146 148
              mnode   <- extract "mnode"
......
149 151
              dfree   <- extract "dfree"
150 152
              ctotal  <- extract "ctotal"
151 153
              return $ Node.create name mtotal mnode mfree
152
                     dtotal dfree ctotal False guuid'
154
                     dtotal dfree ctotal False spindles guuid'
153 155
  return (name, node)
154 156

  
155 157
-- | Construct a group from a JSON object.
b/htools/Ganeti/HTools/Simu.hs
6 6

  
7 7
{-
8 8

  
9
Copyright (C) 2009, 2010, 2011 Google Inc.
9
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
10 10

  
11 11
This program is free software; you can redistribute it and/or modify
12 12
it under the terms of the GNU General Public License as published by
......
74 74
                     Node.create (printf "node-%02d-%03d" grpIndex idx)
75 75
                           (fromIntegral mem) 0 mem
76 76
                           (fromIntegral disk) disk
77
                           (fromIntegral cpu) False grpIndex
77
                           (fromIntegral cpu) False 1 grpIndex
78 78
                  ) [1..ncount]
79 79
      grp = Group.create (printf "group-%02d" grpIndex)
80 80
            (printf "fake-uuid-%02d" grpIndex) apol defIPolicy
b/htools/Ganeti/HTools/Text.hs
181 181
  gdx <- lookupGroup ktg name gu
182 182
  new_node <-
183 183
      if any (== "?") [tm,nm,fm,td,fd,tc] || fo == "Y" then
184
          return $ Node.create name 0 0 0 0 0 0 True gdx
184
          return $ Node.create name 0 0 0 0 0 0 True 0 gdx
185 185
      else do
186 186
        vtm <- tryRead name tm
187 187
        vnm <- tryRead name nm
......
189 189
        vtd <- tryRead name td
190 190
        vfd <- tryRead name fd
191 191
        vtc <- tryRead name tc
192
        return $ Node.create name vtm vnm vfm vtd vfd vtc False gdx
192
        return $ Node.create name vtm vnm vfm vtd vfd vtc False 1 gdx
193 193
  return (name, new_node)
194 194
loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
195 195

  

Also available in: Unified diff