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