Revision 525bfb36 htools/Ganeti/HTools/Node.hs

b/htools/Ganeti/HTools/Node.hs
85 85

  
86 86
-- * Type declarations
87 87

  
88
-- | The tag map type
88
-- | The tag map type.
89 89
type TagMap = Map.Map String Int
90 90

  
91 91
-- | The node type.
......
140 140
type List = Container.Container Node
141 141

  
142 142
-- | A simple name for an allocation element (here just for logistic
143
-- reasons)
143
-- reasons).
144 144
type AllocElement = (List, Instance.Instance, [Node], T.Score)
145 145

  
146 146
-- | Constant node index for a non-moveable instance.
......
149 149

  
150 150
-- * Helper functions
151 151

  
152
-- | Add a tag to a tagmap
152
-- | Add a tag to a tagmap.
153 153
addTag :: TagMap -> String -> TagMap
154 154
addTag t s = Map.insertWith (+) s 1 t
155 155

  
156
-- | Add multiple tags
156
-- | Add multiple tags.
157 157
addTags :: TagMap -> [String] -> TagMap
158 158
addTags = foldl' addTag
159 159

  
160
-- | Adjust or delete a tag from a tagmap
160
-- | Adjust or delete a tag from a tagmap.
161 161
delTag :: TagMap -> String -> TagMap
162 162
delTag t s = Map.update (\v -> if v > 1
163 163
                               then Just (v-1)
164 164
                               else Nothing)
165 165
             s t
166 166

  
167
-- | Remove multiple tags
167
-- | Remove multiple tags.
168 168
delTags :: TagMap -> [String] -> TagMap
169 169
delTags = foldl' delTag
170 170

  
171
-- | Check if we can add a list of tags to a tagmap
171
-- | Check if we can add a list of tags to a tagmap.
172 172
rejectAddTags :: TagMap -> [String] -> Bool
173 173
rejectAddTags t = any (`Map.member` t)
174 174

  
......
221 221
         , group = group_init
222 222
         }
223 223

  
224
-- | Conversion formula from mDsk\/tDsk to loDsk
224
-- | Conversion formula from mDsk\/tDsk to loDsk.
225 225
mDskToloDsk :: Double -> Double -> Int
226 226
mDskToloDsk mval tdsk = floor (mval * tdsk)
227 227

  
228
-- | Conversion formula from mCpu\/tCpu to hiCpu
228
-- | Conversion formula from mCpu\/tCpu to hiCpu.
229 229
mCpuTohiCpu :: Double -> Double -> Int
230 230
mCpuTohiCpu mval tcpu = floor (mval * tcpu)
231 231

  
......
249 249
setXmem :: Node -> Int -> Node
250 250
setXmem t val = t { xMem = val }
251 251

  
252
-- | Sets the max disk usage ratio
252
-- | Sets the max disk usage ratio.
253 253
setMdsk :: Node -> Double -> Node
254 254
setMdsk t val = t { mDsk = val, loDsk = mDskToloDsk val (tDsk t) }
255 255

  
256
-- | Sets the max cpu usage ratio
256
-- | Sets the max cpu usage ratio.
257 257
setMcpu :: Node -> Double -> Node
258 258
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
259 259

  
......
435 435

  
436 436
-- * Stats functions
437 437

  
438
-- | Computes the amount of available disk on a given node
438
-- | Computes the amount of available disk on a given node.
439 439
availDisk :: Node -> Int
440 440
availDisk t =
441 441
    let _f = fDsk t
......
444 444
       then 0
445 445
       else _f - _l
446 446

  
447
-- | Computes the amount of used disk on a given node
447
-- | Computes the amount of used disk on a given node.
448 448
iDsk :: Node -> Int
449 449
iDsk t = truncate (tDsk t) - fDsk t
450 450

  
451
-- | Computes the amount of available memory on a given node
451
-- | Computes the amount of available memory on a given node.
452 452
availMem :: Node -> Int
453 453
availMem t =
454 454
    let _f = fMem t
......
457 457
       then 0
458 458
       else _f - _l
459 459

  
460
-- | Computes the amount of available memory on a given node
460
-- | Computes the amount of available memory on a given node.
461 461
availCpu :: Node -> Int
462 462
availCpu t =
463 463
    let _u = uCpu t
......
472 472

  
473 473
-- * Display functions
474 474

  
475
showField :: Node -> String -> String
475
-- | Return a field for a given node.
476
showField :: Node   -- ^ Node which we're querying
477
          -> String -- ^ Field name
478
          -> String -- ^ Field value as string
476 479
showField t field =
477 480
    case field of
478 481
      "idx"  -> printf "%4d" $ idx t
......
512 515
      T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
513 516
                  T.dskWeight = uD, T.netWeight = uN } = utilLoad t
514 517

  
515
-- | Returns the header and numeric propery of a field
518
-- | Returns the header and numeric propery of a field.
516 519
showHeader :: String -> (String, Bool)
517 520
showHeader field =
518 521
    case field of
......
552 555
list fields t = map (showField t) fields
553 556

  
554 557

  
558
-- | Constant holding the fields we're displaying by default.
555 559
defaultFields :: [String]
556 560
defaultFields =
557 561
    [ "status", "name", "tmem", "nmem", "imem", "xmem", "fmem"
......
560 564
    , "cload", "mload", "dload", "nload" ]
561 565

  
562 566
-- | Split a list of nodes into a list of (node group UUID, list of
563
-- associated nodes)
567
-- associated nodes).
564 568
computeGroups :: [Node] -> [(T.Gdx, [Node])]
565 569
computeGroups nodes =
566 570
  let nodes' = sortBy (comparing group) nodes

Also available in: Unified diff