disk <- fromObj "disk_space_total" a
mem <- fromObj "memory" a
vcpus <- fromObj "vcpus" a
+ tags <- fromObj "tags" a
let running = "running"
- return (n, Instance.create n mem disk vcpus running 0 0)
+ return (n, Instance.create n mem disk vcpus running tags 0 0)
-- | Parses an instance as found in the cluster instance listg.
parseInstance :: NameAssoc -- ^ The node name-to-index association list
, sNode :: T.Ndx -- ^ Original secondary node
, idx :: T.Idx -- ^ Internal index
, util :: T.DynUtil -- ^ Dynamic resource usage
+ , tags :: [String] -- ^ List of instance tags
} deriving (Show)
instance T.Element Instance where
--
-- Some parameters are not initialized by function, and must be set
-- later (via 'setIdx' for example).
-create :: String -> Int -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance
-create name_init mem_init dsk_init vcpus_init run_init pn sn =
+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 =
Instance { name = name_init
, mem = mem_init
, dsk = dsk_init
, sNode = sn
, idx = -1
, util = T.baseUtil
+ , tags = tags_init
}
-- | Changes the index.
let nnames = JSArray []
fnames = ["name",
"disk_usage", "be/memory", "be/vcpus",
- "status", "pnode", "snodes"]
+ "status", "pnode", "snodes", "tags"]
fields = JSArray $ map (JSString . toJSString) fnames
use_locking = JSBool False
in JSArray [nnames, fields, use_locking]
-> JSValue
-> Result (String, Instance.Instance)
parseInstance ktn (JSArray [ name, disk, mem, vcpus
- , status, pnode, snodes ]) = do
+ , status, pnode, snodes, tags ]) = do
xname <- annotateResult "Parsing new instance" (fromJVal name)
let convert v = annotateResult ("Instance '" ++ xname ++ "'") (fromJVal v)
xdisk <- convert disk
snode <- (if null xsnodes then return Node.noSecondary
else lookupNode ktn xname (fromJSString $ head xsnodes))
xrunning <- convert status
- let inst = Instance.create xname xmem xdisk xvcpus xrunning xpnode snode
+ xtags <- convert tags
+ let inst = Instance.create xname xmem xdisk xvcpus
+ xrunning xtags xpnode snode
return (xname, inst)
parseInstance _ v = fail ("Invalid instance query result: " ++ show v)
snode <- (if null snodes then return Node.noSecondary
else readEitherString (head snodes) >>= lookupNode ktn name)
running <- extract "status" a
- let inst = Instance.create name mem disk vcpus running pnode snode
+ tags <- extract "tags" a
+ let inst = Instance.create name mem disk vcpus running tags pnode snode
return (name, inst)
-- | Construct a node from a JSON object.
-- | Load an instance from a field list.
loadInst :: (Monad m) =>
[(String, Ndx)] -> [String] -> m (String, Instance.Instance)
-loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode] = do
+loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode, tags] = do
pidx <- lookupNode ktn name pnode
sidx <- (if null snode then return Node.noSecondary
else lookupNode ktn name snode)
vvcpus <- tryRead name vcpus
when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode
- let newinst = Instance.create name vmem vdsk vvcpus status pidx sidx
+ let vtags = sepSplit ',' tags
+ newinst = Instance.create name vmem vdsk vvcpus status vtags pidx sidx
return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
then ""
else Container.nameOf nl sidx ++ csf)
in
- printf "%s|%d|%d|%d|%s|%s|%s"
+ printf "%s|%d|%d|%d|%s|%s|%s|%s"
iname (Instance.mem inst) (Instance.dsk inst)
(Instance.vcpus inst) (Instance.runSt inst)
- pnode snode
+ pnode snode (intercalate "," (Instance.tags inst))
-- | Generate instance file data from instance objects
serializeInstances :: String -> Node.List -> Instance.List -> String
-- utility functions
let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx)
- (rspecCpu spx) "ADMIN_down" (-1) (-1)
+ (rspecCpu spx) "ADMIN_down" [] (-1) (-1)
exitifbad val = (case val of
Bad s -> do
hPrintf stderr "Failure: %s\n" s