Revision ec18dca9

b/Ganeti/HTools/Container.hs
19 19
    , add
20 20
    , addTwo
21 21
    , remove
22
    , IntMap.map
22 23
    -- * Conversion
23 24
    , elems
24 25
    , keys
b/hbal.hs
17 17
import qualified Ganeti.HTools.Container as Container
18 18
import qualified Ganeti.HTools.Cluster as Cluster
19 19
import qualified Ganeti.HTools.Version as Version
20
import qualified Ganeti.HTools.Node as Node
20 21
import Ganeti.HTools.Rapi
21 22
import Ganeti.HTools.Utils
22 23

  
......
31 32
    , optMaster    :: String   -- ^ Collect data from RAPI
32 33
    , optVerbose   :: Int      -- ^ Verbosity level
33 34
    , optShowVer   :: Bool     -- ^ Just show the program version
35
    , optOffline   :: [String] -- ^ Names of offline nodes
34 36
    } deriving Show
35 37

  
36 38
-- | Default values for the command line options.
......
45 47
 , optMaster    = ""
46 48
 , optVerbose   = 0
47 49
 , optShowVer   = False
50
 , optOffline   = []
48 51
 }
49 52

  
50 53
-- | Options list and functions
......
79 82
    , Option ['V']     ["version"]
80 83
      (NoArg (\ opts -> opts { optShowVer = True}))
81 84
      "show the version of the program"
85
    , Option ['O']     ["offline"]
86
      (ReqArg (\ n opts -> opts { optOffline = n:optOffline opts }) "NODE")
87
       " set node as offline"
82 88
    ]
83 89

  
84 90
-- | Command line parser, using the 'options' structure.
......
109 115
iterateDepth ini_tbl max_rounds ktn kti nmlen imlen cmd_strs oneline =
110 116
    let Cluster.Table ini_nl ini_il ini_cv ini_plc = ini_tbl
111 117
        all_inst = Container.elems ini_il
112
        node_idx = Container.keys ini_nl
118
        node_idx = map Node.idx . filter (not . Node.offline) $
119
                   Container.elems ini_nl
113 120
        fin_tbl = Cluster.checkMove node_idx ini_tbl all_inst
114 121
        (Cluster.Table _ _ fin_cv fin_plc) = fin_tbl
115 122
        ini_plc_len = length ini_plc
......
152 159
            host -> (readData getNodes host,
153 160
                     readData getInstances host)
154 161

  
155
  (nl, il, csf, ktn, kti) <- liftM2 Cluster.loadData node_data inst_data
162
  (loaded_nl, il, csf, ktn, kti) <- liftM2 Cluster.loadData node_data inst_data
163

  
164
  let offline_names = optOffline opts
165
      offline_indices = fst . unzip .
166
                        filter (\(_, n) -> elem n offline_names) $ ktn
167

  
168
  let nl = Container.map (\n -> if elem (Node.idx n) offline_indices
169
                                then Node.setOffline n True
170
                                else n) loaded_nl
156 171

  
157 172
  unless oneline $ printf "Loaded %d nodes, %d instances\n"
158 173
             (Container.size nl)

Also available in: Unified diff