{-
-Copyright (C) 2009, 2010, 2011 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
( readRequest
, runIAllocator
, processRelocate
+ , loadData
) where
import Data.Either ()
-import Data.Maybe (fromMaybe, isJust)
+import Data.Maybe (fromMaybe)
import Data.List
import Control.Monad
import Text.JSON (JSObject, JSValue(JSArray),
import qualified Ganeti.Constants as C
import Ganeti.HTools.CLI
import Ganeti.HTools.Loader
-import Ganeti.HTools.ExtLoader (loadExternalData)
import Ganeti.HTools.JSON
import Ganeti.HTools.Types
let vm_capable' = fromMaybe True vm_capable
gidx <- lookupGroup ktg n guuid
node <- if offline || drained || not vm_capable'
- then return $ Node.create n 0 0 0 0 0 0 True gidx
+ then return $ Node.create n 0 0 0 0 0 0 True 0 gidx
else do
mtotal <- extract "total_memory"
mnode <- extract "reserved_memory"
dtotal <- extract "total_disk"
dfree <- extract "free_disk"
ctotal <- extract "total_cpus"
+ ndparams <- extract "ndparams" >>= asJSObject
+ spindles <- tryFromObj desc (fromJSObject ndparams)
+ "spindle_count"
return $ Node.create n mtotal mnode mfree
- dtotal dfree ctotal False gidx
+ dtotal dfree ctotal False spindles gidx
return (n, node)
-- | Parses a group as found in the cluster group list.
let extract x = tryFromObj ("invalid data for group '" ++ u ++ "'") a x
name <- extract "name"
apol <- extract "alloc_policy"
- return (u, Group.create name u apol)
+ ipol <- extract "ipolicy"
+ return (u, Group.create name u apol ipol)
-- | Top-level parser.
--
formatNodeEvac gl nl il
-- | Reads the request from the data file(s).
-readRequest :: Options -> [String] -> IO Request
-readRequest opts args = do
- when (null args) $ do
- hPutStrLn stderr "Error: this program needs an input file."
- exitWith $ ExitFailure 1
-
- input_data <- readFile (head args)
- r1 <- case parseData input_data of
- Bad err -> do
- hPutStrLn stderr $ "Error: " ++ err
- exitWith $ ExitFailure 1
- Ok (fix_msgs, rq) -> maybeShowWarnings fix_msgs >> return rq
- if isJust (optDataFile opts) || (not . null . optNodeSim) opts
- then do
- cdata <- loadExternalData opts
- let Request rqt _ = r1
- return $ Request rqt cdata
- else return r1
+readRequest :: FilePath -> IO Request
+readRequest fp = do
+ input_data <- readFile fp
+ case parseData input_data of
+ Bad err -> do
+ hPutStrLn stderr $ "Error: " ++ err
+ exitWith $ ExitFailure 1
+ Ok (fix_msgs, rq) -> maybeShowWarnings fix_msgs >> return rq
-- | Main iallocator pipeline.
runIAllocator :: Request -> (Maybe (Node.List, Instance.List), String)
Bad msg -> (False, "Request failed: " ++ msg, JSArray [], Nothing)
rstring = formatResponse ok info result
in (cdata, rstring)
+
+-- | Load the data from an iallocation request file
+loadData :: FilePath -- ^ The path to the file
+ -> IO (Result ClusterData)
+loadData fp = do
+ Request _ cdata <- readRequest fp
+ return $ Ok cdata