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

Add a new attribute to Instance.Instance



This will mirror Ganeti's be/auto_balance one, which we need to use to
properly match N+1 computations.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 49e11c49
......@@ -57,7 +57,7 @@ parseBaseInstance n a = do
vcpus <- extract "vcpus"
tags <- extract "tags"
let running = "running"
return (n, Instance.create n mem disk vcpus running tags 0 0)
return (n, Instance.create n mem disk vcpus running tags True 0 0)
-- | Parses an instance as found in the cluster instance listg.
parseInstance :: NameAssoc -- ^ The node name-to-index association list
......
......@@ -7,7 +7,7 @@ intelligence is in the "Node" and "Cluster" modules.
{-
Copyright (C) 2009, 2010 Google Inc.
Copyright (C) 2009, 2010, 2011 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
......@@ -49,20 +49,22 @@ import qualified Ganeti.HTools.Container as Container
-- * Type declarations
-- | The instance type
data Instance = Instance { name :: String -- ^ The instance name
, alias :: String -- ^ The shortened name
, mem :: Int -- ^ Memory of the instance
, dsk :: Int -- ^ Disk size of instance
, vcpus :: Int -- ^ Number of VCPUs
, running :: Bool -- ^ Is the instance running?
, runSt :: String -- ^ Original (text) run status
, pNode :: T.Ndx -- ^ Original primary node
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
, movable :: Bool -- ^ Can the instance be moved?
, tags :: [String] -- ^ List of instance tags
} deriving (Show, Read)
data Instance = Instance
{ name :: String -- ^ The instance name
, alias :: String -- ^ The shortened name
, mem :: Int -- ^ Memory of the instance
, dsk :: Int -- ^ Disk size of instance
, vcpus :: Int -- ^ Number of VCPUs
, running :: Bool -- ^ Is the instance running?
, runSt :: String -- ^ Original (text) run status
, pNode :: T.Ndx -- ^ Original primary node
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
, movable :: Bool -- ^ Can the instance be moved?
, auto_balance :: Bool -- ^ Is the instance auto-balanced?
, tags :: [String] -- ^ List of instance tags
} deriving (Show, Read)
instance T.Element Instance where
nameOf = name
......@@ -88,8 +90,9 @@ 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 -> Int -> String
-> [String] -> T.Ndx -> T.Ndx -> Instance
create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn =
-> [String] -> Bool -> T.Ndx -> T.Ndx -> Instance
create name_init mem_init dsk_init vcpus_init run_init tags_init
auto_balance_init pn sn =
Instance { name = name_init
, alias = name_init
, mem = mem_init
......@@ -103,6 +106,7 @@ create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn =
, util = T.baseUtil
, tags = tags_init
, movable = True
, auto_balance = auto_balance_init
}
-- | Changes the index.
......
......@@ -127,7 +127,7 @@ parseInstance ktn (JSArray [ name, disk, mem, vcpus
xrunning <- convert "status" status
xtags <- convert "tags" tags
let inst = Instance.create xname xmem xdisk xvcpus
xrunning xtags xpnode snode
xrunning xtags True xpnode snode
return (xname, inst)
parseInstance _ v = fail ("Invalid instance query result: " ++ show v)
......
......@@ -106,7 +106,7 @@ setInstanceSmallerThanNode node inst =
-- | Create an instance given its spec
createInstance mem dsk vcpus =
Instance.create "inst-unnamed" mem dsk vcpus "running" [] (-1) (-1)
Instance.create "inst-unnamed" mem dsk vcpus "running" [] True (-1) (-1)
-- | Create a small cluster by repeating a node spec
makeSmallCluster :: Node.Node -> Int -> Node.List
......@@ -184,7 +184,7 @@ instance Arbitrary Instance.Instance where
pn <- arbitrary
sn <- arbitrary
vcpus <- choose (0, maxCpu)
return $ Instance.create name mem dsk vcpus run_st [] pn sn
return $ Instance.create name mem dsk vcpus run_st [] True pn sn
-- and a random node
instance Arbitrary Node.Node where
......
......@@ -122,7 +122,7 @@ parseInstance ktn a = do
else readEitherString (head snodes) >>= lookupNode ktn name)
running <- extract "status" a
tags <- extract "tags" a
let inst = Instance.create name mem disk vcpus running tags pnode snode
let inst = Instance.create name mem disk vcpus running tags True pnode snode
return (name, inst)
-- | Construct a node from a JSON object.
......
......@@ -144,7 +144,8 @@ loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode, tags] = do
when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode
let vtags = sepSplit ',' tags
newinst = Instance.create name vmem vdsk vvcpus status vtags pidx sidx
newinst = Instance.create name vmem vdsk vvcpus status vtags
True pidx sidx
return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
......
......@@ -280,7 +280,7 @@ main = do
-- utility functions
let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx)
(rspecCpu spx) "running" [] (-1) (-1)
(rspecCpu spx) "running" [] True (-1) (-1)
exitifbad val = (case val of
Bad s -> do
hPrintf stderr "Failure: %s\n" s :: IO ()
......
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