Commit d752eb39 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a new vcpus attribute to instances

This patch adds reading of vcpu count for instances, in preparation for
using the vcpu ratio in cluster scoring.
parent 734b1ff1
......@@ -51,8 +51,9 @@ parseBaseInstance :: String
parseBaseInstance n a = do
disk <- fromObj "disk_space_total" a
mem <- fromObj "memory" a
vcpus <- fromObj "vcpus" a
let running = "running"
return $ (n, Instance.create n mem disk running 0 0)
return $ (n, Instance.create n mem disk vcpus running 0 0)
-- | Parses an instance as found in the cluster instance list.
parseInstance :: NameAssoc -- ^ The node name-to-index association list
......
......@@ -37,6 +37,7 @@ import qualified Ganeti.HTools.Container as Container
data Instance = Instance { name :: String -- ^ The instance name
, mem :: Int -- ^ Memory of the instance
, dsk :: Int -- ^ Disk size of instance
, vcpus :: Int -- ^ Number of VCPUs
, running :: Bool -- ^ Whether the instance
-- is running
, run_st :: String -- ^ Original (text) run status
......@@ -64,12 +65,13 @@ type List = Container.Container Instance
--
-- Some parameters are not initialized by function, and must be set
-- later (via 'setIdx' for example).
create :: String -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
create name_init mem_init dsk_init run_init pn sn =
create :: String -> Int -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
create name_init mem_init dsk_init vcpus_init run_init pn sn =
Instance {
name = name_init,
mem = mem_init,
dsk = dsk_init,
vcpus = vcpus_init,
running = case run_init of
"running" -> True
"ERROR_up" -> True
......
......@@ -82,12 +82,13 @@ parseInstance ktn a = do
name <- fromObj "name" a
disk <- fromObj "disk_usage" a
mem <- fromObj "beparams" a >>= fromObj "memory"
vcpus <- fromObj "beparams" a >>= fromObj "vcpus"
pnode <- fromObj "pnode" a >>= lookupNode ktn name
snodes <- fromObj "snodes" a
snode <- (if null snodes then return Node.noSecondary
else readEitherString (head snodes) >>= lookupNode ktn name)
running <- fromObj "status" a
let inst = Instance.create name mem disk running pnode snode
let inst = Instance.create name mem disk vcpus running pnode snode
return (name, inst)
-- | Construct a node from a JSON object.
......
......@@ -66,15 +66,16 @@ loadNode s = fail $ "Invalid/incomplete node data: '" ++ (show s) ++ "'"
-- | Load an instance from a field list.
loadInst :: (Monad m) =>
[(String, Ndx)] -> [String] -> m (String, Instance.Instance)
loadInst ktn (name:mem:dsk:status:pnode:snode:[]) = do
loadInst ktn (name:mem:dsk:vcpus:status:pnode:snode:[]) = do
pidx <- lookupNode ktn name pnode
sidx <- (if null snode then return Node.noSecondary
else lookupNode ktn name snode)
vmem <- tryRead name mem
vdsk <- tryRead name dsk
vvcpus <- tryRead name vcpus
when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode
let newinst = Instance.create name vmem vdsk status pidx sidx
let newinst = Instance.create name vmem vdsk vvcpus status pidx sidx
return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ (show s) ++ "'"
......
......@@ -86,7 +86,7 @@ usable for whatever reason, the following two commands should be run::
gnt-node list -oname,mtotal,mnode,mfree,dtotal,dfree,offline \
--separator '|' --no-headers > nodes
gnt-instance list -oname,be/memory,sda_size,status,pnode,snodes \
gnt-instance list -oname,be/memory,sda_size,be/vcpus,status,pnode,snodes \
--separator '|' --no-head > instances
These two files should be saved under the names of *nodes* and
......
......@@ -56,6 +56,7 @@ data Options = Options
, optOffline :: [String] -- ^ Names of offline nodes
, optIMem :: Int -- ^ Instance memory
, optIDsk :: Int -- ^ Instance disk
, optIVCPUs :: Int -- ^ Instance VCPUs
, optINodes :: Int -- ^ Nodes required for an instance
, optShowVer :: Bool -- ^ Just show the program version
, optShowHelp :: Bool -- ^ Just show the help
......@@ -86,6 +87,7 @@ defaultOptions = Options
, optOffline = []
, optIMem = 4096
, optIDsk = 102400
, optIVCPUs = 1
, optINodes = 2
, optShowVer = False
, optShowHelp = False
......@@ -121,6 +123,9 @@ options =
, Option [] ["disk"]
(ReqArg (\ d opts -> opts { optIDsk = read d }) "DISK")
"disk size for instances"
, Option [] ["vcpus"]
(ReqArg (\ p opts -> opts { optIVCPUs = read p }) "NUM")
"number of virtual cpus for instances"
, Option [] ["req-nodes"]
(ReqArg (\ n opts -> opts { optINodes = read n }) "NODES")
"number of nodes for the new instances (1=plain, 2=mirrored)"
......@@ -236,7 +241,7 @@ main = do
let nmlen = Container.maxNameLen nl
newinst = Instance.create "new" (optIMem opts) (optIDsk opts)
"ADMIN_down" (-1) (-1)
(optIVCPUs opts) "ADMIN_down" (-1) (-1)
let (fin_nl, ixes) = iterateDepth nl il newinst req_nodes []
allocs = length ixes
......
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