Commit 4938fa30 authored by Guido Trotter's avatar Guido Trotter
Browse files

Do proper name lookup for the -O option



hspace and hbal treat -O differently, and use aliases for short names
(although hbal succeeds in that, and hspace doesn't). Uniform this with
a name lookup, using the same functions we used for instance
selection/exclusion.

Some of the code is by the way a bit repetitive, and could probably be
merged in a single function. That needs to be a monadic one, though, so
I promise to do it as soon as I realize how to write them! ;)
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent c0f6d0d8
......@@ -30,6 +30,8 @@ module Ganeti.HTools.Loader
( mergeData
, checkData
, assignIndices
, lookupName
, goodLookupResult
, lookupNode
, lookupInstance
, lookupGroup
......
......@@ -49,7 +49,7 @@ import Ganeti.HTools.CLI
import Ganeti.HTools.ExtLoader
import Ganeti.HTools.Utils
import Ganeti.HTools.Types
import Ganeti.HTools.Loader (ClusterData(..))
import Ganeti.HTools.Loader
import qualified Ganeti.Luxi as L
import Ganeti.Jobs
......@@ -240,22 +240,21 @@ main = do
ini_cdata@(ClusterData gl fixed_nl ilf ctags) <- loadExternalData opts
let offline_names = optOffline opts
let offline_passed = optOffline opts
all_nodes = Container.elems fixed_nl
all_names = concatMap allNames all_nodes
offline_wrong = filter (`notElem` all_names) offline_names
offline_lkp = map (lookupName (map Node.name all_nodes)) offline_passed
offline_wrong = filter (not . goodLookupResult) offline_lkp
offline_names = map lrContent offline_lkp
offline_indices = map Node.idx $
filter (\n ->
Node.name n `elem` offline_names ||
Node.alias n `elem` offline_names)
filter (\n -> Node.name n `elem` offline_names)
all_nodes
m_cpu = optMcpu opts
m_dsk = optMdsk opts
csf = commonSuffix fixed_nl ilf
when (length offline_wrong > 0) $ do
hPrintf stderr "Wrong node name(s) set as offline: %s\n"
(commaJoin offline_wrong) :: IO ()
when (not (null offline_wrong)) $ do
hPrintf stderr "Error: Wrong node name(s) set as offline: %s\n"
(commaJoin (map lrContent offline_wrong)) :: IO ()
exitWith $ ExitFailure 1
let nm = Container.map (\n -> if Node.idx n `elem` offline_indices
......
......@@ -46,7 +46,7 @@ import Ganeti.HTools.Utils
import Ganeti.HTools.Types
import Ganeti.HTools.CLI
import Ganeti.HTools.ExtLoader
import Ganeti.HTools.Loader (ClusterData(..))
import Ganeti.HTools.Loader
-- | Options list and functions
options :: [OptType]
......@@ -246,21 +246,20 @@ main = do
let num_instances = length $ Container.elems il
let offline_names = optOffline opts
let offline_passed = optOffline opts
all_nodes = Container.elems fixed_nl
all_names = map Node.name all_nodes
offline_wrong = filter (`notElem` all_names) offline_names
offline_lkp = map (lookupName (map Node.name all_nodes)) offline_passed
offline_wrong = filter (not . goodLookupResult) offline_lkp
offline_names = map lrContent offline_lkp
offline_indices = map Node.idx $
filter (\n ->
Node.name n `elem` offline_names ||
Node.alias n `elem` offline_names)
filter (\n -> Node.name n `elem` offline_names)
all_nodes
m_cpu = optMcpu opts
m_dsk = optMdsk opts
when (length offline_wrong > 0) $ do
when (not (null offline_wrong)) $ do
hPrintf stderr "Error: Wrong node name(s) set as offline: %s\n"
(commaJoin offline_wrong) :: IO ()
(commaJoin (map lrContent offline_wrong)) :: IO ()
exitWith $ ExitFailure 1
when (req_nodes /= 1 && req_nodes /= 2) $ do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment