Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ parseBaseInstance n a = do ...@@ -43,7 +43,7 @@ parseBaseInstance n a = do
x@(Ok _) -> x x@(Ok _) -> x
mem <- fromObj "memory" a mem <- fromObj "memory" a
let running = "running" let running = "running"
return $ (n, Instance.create mem disk running 0 0) return $ (n, Instance.create n mem disk running 0 0)
parseInstance :: NameAssoc parseInstance :: NameAssoc
-> String -> String
...@@ -68,7 +68,7 @@ parseNode n a = do ...@@ -68,7 +68,7 @@ parseNode n a = do
dfree <- fromObj "free_disk" a dfree <- fromObj "free_disk" a
offline <- fromObj "offline" a offline <- fromObj "offline" a
drained <- 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)) (offline || drained))
parseData :: String -> Result Request parseData :: String -> Result Request
......
...@@ -6,7 +6,8 @@ intelligence is in the "Node" and "Cluster" modules. ...@@ -6,7 +6,8 @@ intelligence is in the "Node" and "Cluster" modules.
-} -}
module Ganeti.HTools.Instance where 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 , dsk :: Int -- ^ disk size of instance
, running :: Bool -- ^ whether the instance , running :: Bool -- ^ whether the instance
-- is running -- is running
...@@ -20,9 +21,10 @@ data Instance = Instance { mem :: Int -- ^ memory of the instance ...@@ -20,9 +21,10 @@ data Instance = Instance { mem :: Int -- ^ memory of the instance
-- | A simple name for the int, instance association list -- | A simple name for the int, instance association list
type AssocList = [(Int, Instance)] type AssocList = [(Int, Instance)]
create :: Int -> Int -> String -> Int -> Int -> Instance create :: String -> Int -> Int -> String -> Int -> Int -> Instance
create mem_init dsk_init run_init pn sn = create name_init mem_init dsk_init run_init pn sn =
Instance { Instance {
name = name_init,
mem = mem_init, mem = mem_init,
dsk = dsk_init, dsk = dsk_init,
running = case run_init of running = case run_init of
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
module Ganeti.HTools.Node 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, p_mem, p_dsk, p_rem,
plist, slist, offline) plist, slist, offline)
-- * Constructor -- * Constructor
...@@ -38,7 +38,8 @@ import qualified Ganeti.HTools.Container as Container ...@@ -38,7 +38,8 @@ import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Instance as Instance import qualified Ganeti.HTools.Instance as Instance
import qualified Ganeti.HTools.PeerMap as PeerMap 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) , n_mem :: Int -- ^ node memory (MiB)
, f_mem :: Int -- ^ free memory (MiB) , f_mem :: Int -- ^ free memory (MiB)
, x_mem :: Int -- ^ unaccounted 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 ...@@ -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. later via the 'setIdx' and 'buildPeers' functions.
-} -}
create :: Double -> Int -> Int -> Double -> Int -> Bool -> Node create :: String -> Double -> Int -> Int -> Double -> Int -> Bool -> Node
create mem_t_init mem_n_init mem_f_init dsk_t_init dsk_f_init create name_init mem_t_init mem_n_init mem_f_init
offline_init = dsk_t_init dsk_f_init offline_init =
Node Node
{ {
name = name_init,
t_mem = mem_t_init, t_mem = mem_t_init,
n_mem = mem_n_init, n_mem = mem_n_init,
f_mem = mem_f_init, f_mem = mem_f_init,
......
...@@ -63,7 +63,7 @@ parseInstance ktn a = do ...@@ -63,7 +63,7 @@ parseInstance ktn a = do
snode <- (if null snodes then return Node.noSecondary snode <- (if null snodes then return Node.noSecondary
else readEitherString (head snodes) >>= lookupNode ktn name) else readEitherString (head snodes) >>= lookupNode ktn name)
running <- fromObj "status" a 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) return (name, inst)
parseNode :: JSObject JSValue -> Result (String, Node.Node) parseNode :: JSObject JSValue -> Result (String, Node.Node)
...@@ -71,7 +71,7 @@ parseNode a = do ...@@ -71,7 +71,7 @@ parseNode a = do
name <- fromObj "name" a name <- fromObj "name" a
offline <- fromObj "offline" a offline <- fromObj "offline" a
node <- (case offline of 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 _ -> do
drained <- fromObj "drained" a drained <- fromObj "drained" a
mtotal <- fromObj "mtotal" a mtotal <- fromObj "mtotal" a
...@@ -79,7 +79,7 @@ parseNode a = do ...@@ -79,7 +79,7 @@ parseNode a = do
mfree <- fromObj "mfree" a mfree <- fromObj "mfree" a
dtotal <- fromObj "dtotal" a dtotal <- fromObj "dtotal" a
dfree <- fromObj "dfree" a dfree <- fromObj "dfree" a
return $ Node.create mtotal mnode mfree return $ Node.create name mtotal mnode mfree
dtotal dfree (offline || drained)) dtotal dfree (offline || drained))
return (name, node) return (name, node)
......
...@@ -31,14 +31,14 @@ loadNode :: (Monad m) => [String] -> m (String, Node.Node) ...@@ -31,14 +31,14 @@ loadNode :: (Monad m) => [String] -> m (String, Node.Node)
loadNode (name:tm:nm:fm:td:fd:fo:[]) = do loadNode (name:tm:nm:fm:td:fd:fo:[]) = do
new_node <- new_node <-
if any (== "?") [tm,nm,fm,td,fd] || fo == "Y" then 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 else do
vtm <- tryRead name tm vtm <- tryRead name tm
vnm <- tryRead name nm vnm <- tryRead name nm
vfm <- tryRead name fm vfm <- tryRead name fm
vtd <- tryRead name td vtd <- tryRead name td
vfd <- tryRead name fd 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) return (name, new_node)
loadNode s = fail $ "Invalid/incomplete node data: '" ++ (show s) ++ "'" loadNode s = fail $ "Invalid/incomplete node data: '" ++ (show s) ++ "'"
...@@ -53,7 +53,7 @@ loadInst ktn (name:mem:dsk:status:pnode:snode:[]) = do ...@@ -53,7 +53,7 @@ loadInst ktn (name:mem:dsk:status:pnode:snode:[]) = do
vdsk <- tryRead name dsk vdsk <- tryRead name dsk
when (sidx == pidx) $ fail $ "Instance " ++ name ++ when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode " 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) return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ (show s) ++ "'" loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ (show s) ++ "'"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment