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

Node: add the node group's UUID



This is not used anywhere yet, and the backend are all just adding the
default UUID, not the real one.

The patch also allows displaying the group UUID in the node list.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 9b9da389
......@@ -81,7 +81,7 @@ parseNode n a = do
offline <- fromObj "offline" a
drained <- fromObj "drained" a
node <- (if offline || drained
then return $ Node.create n 0 0 0 0 0 0 True
then return $ Node.create n 0 0 0 0 0 0 True defaultUUID
else do
mtotal <- fromObj "total_memory" a
mnode <- fromObj "reserved_memory" a
......@@ -90,7 +90,7 @@ parseNode n a = do
dfree <- fromObj "free_disk" a
ctotal <- fromObj "total_cpus" a
return $ Node.create n mtotal mnode mfree
dtotal dfree ctotal False)
dtotal dfree ctotal False defaultUUID)
return (n, node)
-- | Top-level parser.
......
......@@ -37,7 +37,8 @@ import Ganeti.HTools.Loader
import Ganeti.HTools.Types
import qualified Ganeti.HTools.Node as Node
import qualified Ganeti.HTools.Instance as Instance
import Ganeti.HTools.Utils (fromJVal, annotateResult, tryFromObj, asJSObject)
import Ganeti.HTools.Utils (fromJVal, annotateResult, tryFromObj, asJSObject,
defaultUUID)
-- * Utility functions
......@@ -123,7 +124,7 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree
xdrained <- convert drained
xvm_capable <- convert vm_capable
node <- (if xoffline || xdrained || not xvm_capable
then return $ Node.create xname 0 0 0 0 0 0 True
then return $ Node.create xname 0 0 0 0 0 0 True defaultUUID
else do
xmtotal <- convert mtotal
xmnode <- convert mnode
......@@ -132,7 +133,7 @@ parseNode (JSArray [ name, mtotal, mnode, mfree, dtotal, dfree
xdfree <- convert dfree
xctotal <- convert ctotal
return $ Node.create xname xmtotal xmnode xmfree
xdtotal xdfree xctotal False)
xdtotal xdfree xctotal False defaultUUID)
return (xname, node)
parseNode v = fail ("Invalid node query result: " ++ show v)
......
......@@ -68,7 +68,7 @@ module Ganeti.HTools.Node
, noSecondary
) where
import Data.List
import Data.List hiding (group)
import qualified Data.Map as Map
import qualified Data.Foldable as Foldable
import Text.Printf (printf)
......@@ -119,6 +119,7 @@ data Node = Node
, utilPool :: T.DynUtil -- ^ Total utilisation capacity
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
, group :: String -- ^ The node's group (as UUID)
} deriving (Show, Eq)
instance T.Element Node where
......@@ -182,9 +183,9 @@ conflictingPrimaries (Node { pTags = t }) = Foldable.sum t - Map.size t
-- The index and the peers maps are empty, and will be need to be
-- update later via the 'setIdx' and 'buildPeers' functions.
create :: String -> Double -> Int -> Int -> Double
-> Int -> Double -> Bool -> Node
-> Int -> Double -> Bool -> String -> Node
create name_init mem_t_init mem_n_init mem_f_init
dsk_t_init dsk_f_init cpu_t_init offline_init =
dsk_t_init dsk_f_init cpu_t_init offline_init group_init =
Node { name = name_init
, alias = name_init
, tMem = mem_t_init
......@@ -213,6 +214,7 @@ create name_init mem_t_init mem_n_init mem_f_init
, utilPool = T.baseUtil
, utilLoad = T.zeroUtil
, pTags = Map.empty
, group = group_init
}
-- | Conversion formula from mDsk\/tDsk to loDsk
......@@ -483,6 +485,7 @@ showField t field =
"ptags" -> intercalate "," . map (\(k, v) -> printf "%s=%d" k v) .
Map.toList $ pTags t
"peermap" -> show $ peers t
"group.uuid" -> group t
_ -> T.unknownField
where
T.DynUtil { T.cpuWeight = uC, T.memWeight = uM,
......@@ -521,6 +524,7 @@ showHeader field =
"nload" -> ("lNet", True)
"ptags" -> ("PrimaryTags", False)
"peermap" -> ("PeerMap", False)
"group.uuid" -> ("GroupUUID", False)
_ -> (T.unknownField, False)
-- | String converter for the node list functionality.
......
......@@ -176,6 +176,7 @@ instance Arbitrary Node.Node where
offl <- arbitrary
let n = Node.create name (fromIntegral mem_t) mem_n mem_f
(fromIntegral dsk_t) dsk_f (fromIntegral cpu_t) offl
Utils.defaultUUID
n' = Node.buildPeers n Container.empty
return n'
......
......@@ -106,7 +106,7 @@ parseNode a = do
offline <- extract "offline"
drained <- extract "drained"
node <- (if offline || drained
then return $ Node.create name 0 0 0 0 0 0 True
then return $ Node.create name 0 0 0 0 0 0 True defaultUUID
else do
mtotal <- extract "mtotal"
mnode <- extract "mnode"
......@@ -115,7 +115,7 @@ parseNode a = do
dfree <- extract "dfree"
ctotal <- extract "ctotal"
return $ Node.create name mtotal mnode mfree
dtotal dfree ctotal False)
dtotal dfree ctotal False defaultUUID)
return (name, node)
-- | Loads the raw cluster data from an URL.
......
......@@ -59,7 +59,7 @@ parseData ndata = do
let n = Node.create (printf "node%03d" idx)
(fromIntegral mem) 0 mem
(fromIntegral disk) disk
(fromIntegral cpu) False
(fromIntegral cpu) False defaultUUID
in (idx, Node.setIdx n idx)
) [1..cnt]
return (nodes, [], [])
......
......@@ -95,7 +95,7 @@ loadNode :: (Monad m) => [String] -> m (String, Node.Node)
loadNode [name, tm, nm, fm, td, fd, tc, fo] = do
new_node <-
if any (== "?") [tm,nm,fm,td,fd,tc] || fo == "Y" then
return $ Node.create name 0 0 0 0 0 0 True
return $ Node.create name 0 0 0 0 0 0 True defaultUUID
else do
vtm <- tryRead name tm
vnm <- tryRead name nm
......@@ -103,7 +103,7 @@ loadNode [name, tm, nm, fm, td, fd, tc, fo] = do
vtd <- tryRead name td
vfd <- tryRead name fd
vtc <- tryRead name tc
return $ Node.create name vtm vnm vfm vtd vfd vtc False
return $ Node.create name vtm vnm vfm vtd vfd vtc False defaultUUID
return (name, new_node)
loadNode s = fail $ "Invalid/incomplete node 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