Revision 2fce67b6

b/src/Ganeti/HTools/Program/Hroller.hs
37 37

  
38 38
import qualified Ganeti.HTools.Container as Container
39 39
import qualified Ganeti.HTools.Node as Node
40
import qualified Ganeti.HTools.Group as Group
40 41

  
41 42
import Ganeti.Common
42 43
import Ganeti.HTools.CLI
......
59 60
    , oQuiet
60 61
    , oNoHeaders
61 62
    , oSaveCluster
63
    , oGroup
62 64
    ]
63 65

  
64 66
-- | The list of arguments supported by the program.
......
84 86
              where elsize = (IntMap.size.snd) el
85 87

  
86 88
-- | Filter the output list.
87
-- Only online nodes are shown, and output groups which are empty after being
88
-- filtered are removed as well.
89
filterOutput :: [[Node.Node]] -> [[Node.Node]]
90
filterOutput l =
89
-- Only online nodes are shown, optionally belonging to a particular target
90
-- nodegroup.  Output groups which are empty after being filtered are removed
91
-- as well.
92
filterOutput :: Maybe Group.Group -> [[Node.Node]] -> [[Node.Node]]
93
filterOutput g l =
91 94
  let onlineOnly = filter (not . Node.offline)
95
      hasGroup grp node = Node.group node == Group.idx grp
96
      byGroupOnly Nothing xs = xs
97
      byGroupOnly (Just grp) xs = filter (hasGroup grp) xs
92 98
      nonNullOnly = filter (not . null)
93
  in nonNullOnly (map onlineOnly l)
99
  in nonNullOnly (map (onlineOnly . byGroupOnly g) l)
94 100

  
95 101
-- | Main function.
96 102
main :: Options -> [String] -> IO ()
......
101 107

  
102 108
  -- Load cluster data. The last two arguments, cluster tags and ipolicy, are
103 109
  -- currently not used by this tool.
104
  ini_cdata@(ClusterData _ fixed_nl ilf _ _) <- loadExternalData opts
110
  ini_cdata@(ClusterData gl fixed_nl ilf _ _) <- loadExternalData opts
105 111

  
106 112
  nlf <- setNodeStatus opts fixed_nl
107 113

  
108 114
  maybeSaveData (optSaveCluster opts) "original" "before hroller run" ini_cdata
109 115

  
110
  -- TODO: filter by node group
116
  -- Find the wanted node group, if any.
117
  wantedGroup <- case optGroup opts of
118
    Nothing -> return Nothing
119
    Just name -> case Container.findByName gl name of
120
      Nothing -> exitErr "Cannot find target group."
121
      Just grp -> return (Just grp)
122

  
111 123
  -- TODO: fail if instances are running (with option to warn only)
112 124
  -- TODO: identify master node, and put it last
113 125

  
......
126 138
        (snd . minimumBy (comparing (IntMap.size . snd))) colorings
127 139
      idToNode = (`Container.find` nlf)
128 140
      nodesRebootGroups = map (map idToNode) $ IntMap.elems smallestColoring
129
      outputRebootGroups = filterOutput nodesRebootGroups
141
      outputRebootGroups = filterOutput wantedGroup nodesRebootGroups
130 142
      outputRebootNames = map (map Node.name) outputRebootGroups
131 143

  
132 144
  when (verbose > 1) . putStrLn $ getStats colorings

Also available in: Unified diff