Commit 2727257a authored by Iustin Pop's avatar Iustin Pop
Browse files

Add back names to nodes/instances

In order to simplify the data structures, we add back the name on the
node and instance objects. We still keep the index for, well, indexing,
but we will use the name directly from the object, in order to get rid
of the ktn/kti arguments which are passed around everywhere.
parent e4c5beaf
......@@ -43,7 +43,7 @@ parseBaseInstance n a = do
x@(Ok _) -> x
mem <- fromObj "memory" a
let running = "running"
return $ (n, Instance.create mem disk running 0 0)
return $ (n, Instance.create n mem disk running 0 0)
parseInstance :: NameAssoc
-> String
......@@ -68,7 +68,7 @@ parseNode n a = do
dfree <- fromObj "free_disk" a
offline <- fromObj "offline" a
drained <- fromObj "offline" a
return $ (name, Node.create mtotal mnode mfree dtotal dfree
return $ (name, Node.create n mtotal mnode mfree dtotal dfree
(offline || drained))
parseData :: String -> Result Request
......
......@@ -6,7 +6,8 @@ intelligence is in the "Node" and "Cluster" modules.
-}
module Ganeti.HTools.Instance where
data Instance = Instance { mem :: Int -- ^ memory of the instance
data Instance = Instance { name :: String -- ^ the instance name
, mem :: Int -- ^ memory of the instance
, dsk :: Int -- ^ disk size of instance
, running :: Bool -- ^ whether the instance
-- is running
......@@ -20,9 +21,10 @@ data Instance = Instance { mem :: Int -- ^ memory of the instance
-- | A simple name for the int, instance association list
type AssocList = [(Int, Instance)]
create :: Int -> Int -> String -> Int -> Int -> Instance
create mem_init dsk_init run_init pn sn =
create :: String -> Int -> Int -> String -> Int -> Int -> Instance
create name_init mem_init dsk_init run_init pn sn =
Instance {
name = name_init,
mem = mem_init,
dsk = dsk_init,
running = case run_init of
......
......@@ -6,7 +6,7 @@
module Ganeti.HTools.Node
(
Node(failN1, idx, t_mem, n_mem, f_mem, t_dsk, f_dsk,
Node(failN1, name, idx, t_mem, n_mem, f_mem, t_dsk, f_dsk,
p_mem, p_dsk, p_rem,
plist, slist, offline)
-- * Constructor
......@@ -38,7 +38,8 @@ import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Instance as Instance
import qualified Ganeti.HTools.PeerMap as PeerMap
data Node = Node { t_mem :: Double -- ^ total memory (MiB)
data Node = Node { name :: String -- ^ the node name
, t_mem :: Double -- ^ total memory (MiB)
, n_mem :: Int -- ^ node memory (MiB)
, f_mem :: Int -- ^ free memory (MiB)
, x_mem :: Int -- ^ unaccounted memory (MiB)
......@@ -72,11 +73,12 @@ The index and the peers maps are empty, and will be need to be update
later via the 'setIdx' and 'buildPeers' functions.
-}
create :: Double -> Int -> Int -> Double -> Int -> Bool -> Node
create mem_t_init mem_n_init mem_f_init dsk_t_init dsk_f_init
offline_init =
create :: String -> Double -> Int -> Int -> Double -> Int -> Bool -> Node
create name_init mem_t_init mem_n_init mem_f_init
dsk_t_init dsk_f_init offline_init =
Node
{
name = name_init,
t_mem = mem_t_init,
n_mem = mem_n_init,
f_mem = mem_f_init,
......
......@@ -63,7 +63,7 @@ parseInstance ktn a = do
snode <- (if null snodes then return Node.noSecondary
else readEitherString (head snodes) >>= lookupNode ktn name)
running <- fromObj "status" a
let inst = Instance.create mem disk running pnode snode
let inst = Instance.create name mem disk running pnode snode
return (name, inst)
parseNode :: JSObject JSValue -> Result (String, Node.Node)
......@@ -71,7 +71,7 @@ parseNode a = do
name <- fromObj "name" a
offline <- fromObj "offline" a
node <- (case offline of
True -> return $ Node.create 0 0 0 0 0 True
True -> return $ Node.create name 0 0 0 0 0 True
_ -> do
drained <- fromObj "drained" a
mtotal <- fromObj "mtotal" a
......@@ -79,7 +79,7 @@ parseNode a = do
mfree <- fromObj "mfree" a
dtotal <- fromObj "dtotal" a
dfree <- fromObj "dfree" a
return $ Node.create mtotal mnode mfree
return $ Node.create name mtotal mnode mfree
dtotal dfree (offline || drained))
return (name, node)
......
......@@ -31,14 +31,14 @@ loadNode :: (Monad m) => [String] -> m (String, Node.Node)
loadNode (name:tm:nm:fm:td:fd:fo:[]) = do
new_node <-
if any (== "?") [tm,nm,fm,td,fd] || fo == "Y" then
return $ Node.create 0 0 0 0 0 True
return $ Node.create name 0 0 0 0 0 True
else do
vtm <- tryRead name tm
vnm <- tryRead name nm
vfm <- tryRead name fm
vtd <- tryRead name td
vfd <- tryRead name fd
return $ Node.create vtm vnm vfm vtd vfd False
return $ Node.create name vtm vnm vfm vtd vfd False
return (name, new_node)
loadNode s = fail $ "Invalid/incomplete node data: '" ++ (show s) ++ "'"
......@@ -53,7 +53,7 @@ loadInst ktn (name:mem:dsk:status:pnode:snode:[]) = do
vdsk <- tryRead name dsk
when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode
let newinst = Instance.create vmem vdsk status pidx sidx
let newinst = Instance.create name vmem vdsk status pidx sidx
return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ (show s) ++ "'"
......
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