Revision d6eec019

b/htools/Ganeti/HTools/Loader.hs
7 7

  
8 8
{-
9 9

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

  
12 12
This program is free software; you can redistribute it and/or modify
13 13
it under the terms of the GNU General Public License as published by
......
219 219
            in Container.add sdx snew ac2
220 220
       else ac2
221 221

  
222
-- | Set the node's policy to its group one. Note that this requires
223
-- the group to exist (should have been checked before), otherwise it
224
-- will abort with a runtime error.
225
setNodePolicy :: Group.List -> Node.Node -> Node.Node
226
setNodePolicy gl node =
227
  let grp = Container.find (Node.group node) gl
228
      gpol = Group.iPolicy grp
229
  in Node.setPolicy gpol node
230

  
222 231
-- | Remove non-selected tags from the exclusion list.
223 232
filterExTags :: [String] -> Instance.Instance -> Instance.Instance
224 233
filterExTags tl inst =
......
269 278
          -> [String]             -- ^ Excluded instances
270 279
          -> ClusterData          -- ^ Data from backends
271 280
          -> Result ClusterData   -- ^ Fixed cluster data
272
mergeData um extags selinsts exinsts cdata@(ClusterData _ nl il2 tags _) =
281
mergeData um extags selinsts exinsts cdata@(ClusterData gl nl il2 tags _) =
273 282
  let il = Container.elems il2
274 283
      il3 = foldl' (\im (name, n_util) ->
275 284
                        case Container.findByName im name of
......
291 300
                           filterExTags allextags .
292 301
                           updateMovable selinst_names exinst_names) il3
293 302
      nl2 = foldl' fixNodes nl (Container.elems il4)
294
      nl3 = Container.map (computeAlias common_suffix .
303
      nl3 = Container.map (setNodePolicy gl .
304
                           computeAlias common_suffix .
295 305
                           (`Node.buildPeers` il4)) nl2
296 306
  in if' (null lkp_unknown)
297 307
         (Ok cdata { cdNodes = nl3, cdInstances = il4 })
b/htools/Ganeti/HTools/Node.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
......
41 41
  , setSec
42 42
  , setMdsk
43 43
  , setMcpu
44
  , setPolicy
44 45
  -- * Tag maps
45 46
  , addTags
46 47
  , delTags
......
124 125
  , utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
125 126
  , pTags    :: TagMap    -- ^ Map of primary instance tags and their count
126 127
  , group    :: T.Gdx     -- ^ The node's group (index)
128
  , iPolicy  :: T.IPolicy -- ^ The instance policy (of the node's group)
127 129
  } deriving (Show, Read, Eq)
128 130

  
129 131
instance T.Element Node where
......
219 221
       , utilLoad = T.zeroUtil
220 222
       , pTags = Map.empty
221 223
       , group = group_init
224
       , iPolicy = T.defIPolicy
222 225
       }
223 226

  
224 227
-- | Conversion formula from mDsk\/tDsk to loDsk.
......
257 260
setMcpu :: Node -> Double -> Node
258 261
setMcpu t val = t { mCpu = val, hiCpu = mCpuTohiCpu val (tCpu t) }
259 262

  
263
-- | Sets the policy.
264
setPolicy :: T.IPolicy -> Node -> Node
265
setPolicy pol node = node { iPolicy = pol }
266

  
260 267
-- | Computes the maximum reserved memory for peers from a peer map.
261 268
computeMaxRes :: P.PeerMap -> P.Elem
262 269
computeMaxRes = P.maxElem
b/htools/Ganeti/HTools/QC.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
......
262 262
  offl  <- arbitrary
263 263
  let n = Node.create name (fromIntegral mem_t) mem_n mem_f
264 264
          (fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl 0
265
  return $ Node.buildPeers n Container.empty
265
      n' = Node.setPolicy nullIPolicy n
266
  return $ Node.buildPeers n' Container.empty
266 267

  
267 268
-- and a random node
268 269
instance Arbitrary Node.Node where
......
679 680
       Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==
680 681
  Just (Node.name n, n)
681 682
    -- override failN1 to what loadNode returns by default
682
    where n = node { Node.failN1 = True, Node.offline = False }
683
    where n = node { Node.failN1 = True, Node.offline = False
684
                   , Node.iPolicy = Types.defIPolicy }
683 685

  
684 686
testSuite "Text"
685 687
            [ 'prop_Text_Load_Instance

Also available in: Unified diff