Revision 756df409 htools/Ganeti/HTools/Program/Hspace.hs

b/htools/Ganeti/HTools/Program/Hspace.hs
27 27

  
28 28
import Control.Monad
29 29
import Data.Char (toUpper, isAlphaNum)
30
import Data.Function (on)
30 31
import Data.List
31 32
import Data.Maybe (isJust, fromJust)
32 33
import Data.Ord (comparing)
......
152 153
  -- this should be the final entry
153 154
  printKeys [("OK", "1")]
154 155

  
156
-- | Compute the tiered spec counts from a list of allocated
157
-- instances.
158
tieredSpecMap :: [Instance.Instance]
159
              -> [(RSpec, Int)]
160
tieredSpecMap trl_ixes =
161
    let fin_trl_ixes = reverse trl_ixes
162
        ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes
163
        spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs))
164
                   ix_byspec
165
    in spec_map
166

  
167
-- | Formats a spec map to strings.
168
formatSpecMap :: [(RSpec, Int)] -> [String]
169
formatSpecMap =
170
    map (\(spec, cnt) -> printf "%d,%d,%d=%d" (rspecMem spec)
171
                         (rspecDsk spec) (rspecCpu spec) cnt)
172

  
155 173
formatRSpec :: Double -> String -> RSpec -> [(String, String)]
156 174
formatRSpec m_cpu s r =
157 175
    [ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r)
......
304 322
           then return result_noalloc
305 323
           else exitifbad (Cluster.tieredAlloc nl il Nothing (iofspec tspec)
306 324
                                  allocnodes [] [])
307
       let spec_map' = Cluster.tieredSpecMap trl_ixes
325
       let spec_map' = tieredSpecMap trl_ixes
308 326

  
309 327
       printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes
310 328

  
......
316 334

  
317 335
       printKeys $ map (\(a, fn) -> ("TSPEC_INI_" ++ a, fn tspec)) specData
318 336
       printKeys $ printStats PTiered (Cluster.totalResources trl_nl)
319
       printKeys [("TSPEC", intercalate " " spec_map')]
337
       printKeys [("TSPEC", intercalate " " (formatSpecMap spec_map'))]
320 338
       printAllocationStats m_cpu nl trl_nl)
321 339

  
322 340
  -- Run the standard (avg-mode) allocation

Also available in: Unified diff