Revision 17e7af2b
b/Ganeti/HTools/IAlloc.hs | ||
---|---|---|
52 | 52 |
disk <- fromObj "disk_space_total" a |
53 | 53 |
mem <- fromObj "memory" a |
54 | 54 |
vcpus <- fromObj "vcpus" a |
55 |
tags <- fromObj "tags" a |
|
55 | 56 |
let running = "running" |
56 |
return (n, Instance.create n mem disk vcpus running 0 0) |
|
57 |
return (n, Instance.create n mem disk vcpus running tags 0 0)
|
|
57 | 58 |
|
58 | 59 |
-- | Parses an instance as found in the cluster instance listg. |
59 | 60 |
parseInstance :: NameAssoc -- ^ The node name-to-index association list |
b/Ganeti/HTools/Instance.hs | ||
---|---|---|
56 | 56 |
, sNode :: T.Ndx -- ^ Original secondary node |
57 | 57 |
, idx :: T.Idx -- ^ Internal index |
58 | 58 |
, util :: T.DynUtil -- ^ Dynamic resource usage |
59 |
, tags :: [String] -- ^ List of instance tags |
|
59 | 60 |
} deriving (Show) |
60 | 61 |
|
61 | 62 |
instance T.Element Instance where |
... | ... | |
86 | 87 |
-- |
87 | 88 |
-- Some parameters are not initialized by function, and must be set |
88 | 89 |
-- later (via 'setIdx' for example). |
89 |
create :: String -> Int -> Int -> Int -> String -> T.Ndx -> T.Ndx -> Instance |
|
90 |
create name_init mem_init dsk_init vcpus_init run_init pn sn = |
|
90 |
create :: String -> Int -> Int -> Int -> String |
|
91 |
-> [String] -> T.Ndx -> T.Ndx -> Instance |
|
92 |
create name_init mem_init dsk_init vcpus_init run_init tags_init pn sn = |
|
91 | 93 |
Instance { name = name_init |
92 | 94 |
, mem = mem_init |
93 | 95 |
, dsk = dsk_init |
... | ... | |
98 | 100 |
, sNode = sn |
99 | 101 |
, idx = -1 |
100 | 102 |
, util = T.baseUtil |
103 |
, tags = tags_init |
|
101 | 104 |
} |
102 | 105 |
|
103 | 106 |
-- | Changes the index. |
b/Ganeti/HTools/Luxi.hs | ||
---|---|---|
70 | 70 |
let nnames = JSArray [] |
71 | 71 |
fnames = ["name", |
72 | 72 |
"disk_usage", "be/memory", "be/vcpus", |
73 |
"status", "pnode", "snodes"] |
|
73 |
"status", "pnode", "snodes", "tags"]
|
|
74 | 74 |
fields = JSArray $ map (JSString . toJSString) fnames |
75 | 75 |
use_locking = JSBool False |
76 | 76 |
in JSArray [nnames, fields, use_locking] |
... | ... | |
94 | 94 |
-> JSValue |
95 | 95 |
-> Result (String, Instance.Instance) |
96 | 96 |
parseInstance ktn (JSArray [ name, disk, mem, vcpus |
97 |
, status, pnode, snodes ]) = do |
|
97 |
, status, pnode, snodes, tags ]) = do
|
|
98 | 98 |
xname <- annotateResult "Parsing new instance" (fromJVal name) |
99 | 99 |
let convert v = annotateResult ("Instance '" ++ xname ++ "'") (fromJVal v) |
100 | 100 |
xdisk <- convert disk |
... | ... | |
105 | 105 |
snode <- (if null xsnodes then return Node.noSecondary |
106 | 106 |
else lookupNode ktn xname (fromJSString $ head xsnodes)) |
107 | 107 |
xrunning <- convert status |
108 |
let inst = Instance.create xname xmem xdisk xvcpus xrunning xpnode snode |
|
108 |
xtags <- convert tags |
|
109 |
let inst = Instance.create xname xmem xdisk xvcpus |
|
110 |
xrunning xtags xpnode snode |
|
109 | 111 |
return (xname, inst) |
110 | 112 |
|
111 | 113 |
parseInstance _ v = fail ("Invalid instance query result: " ++ show v) |
b/Ganeti/HTools/Rapi.hs | ||
---|---|---|
88 | 88 |
snode <- (if null snodes then return Node.noSecondary |
89 | 89 |
else readEitherString (head snodes) >>= lookupNode ktn name) |
90 | 90 |
running <- extract "status" a |
91 |
let inst = Instance.create name mem disk vcpus running pnode snode |
|
91 |
tags <- extract "tags" a |
|
92 |
let inst = Instance.create name mem disk vcpus running tags pnode snode |
|
92 | 93 |
return (name, inst) |
93 | 94 |
|
94 | 95 |
-- | Construct a node from a JSON object. |
b/Ganeti/HTools/Text.hs | ||
---|---|---|
60 | 60 |
-- | Load an instance from a field list. |
61 | 61 |
loadInst :: (Monad m) => |
62 | 62 |
[(String, Ndx)] -> [String] -> m (String, Instance.Instance) |
63 |
loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode] = do |
|
63 |
loadInst ktn [name, mem, dsk, vcpus, status, pnode, snode, tags] = do
|
|
64 | 64 |
pidx <- lookupNode ktn name pnode |
65 | 65 |
sidx <- (if null snode then return Node.noSecondary |
66 | 66 |
else lookupNode ktn name snode) |
... | ... | |
69 | 69 |
vvcpus <- tryRead name vcpus |
70 | 70 |
when (sidx == pidx) $ fail $ "Instance " ++ name ++ |
71 | 71 |
" has same primary and secondary node - " ++ pnode |
72 |
let newinst = Instance.create name vmem vdsk vvcpus status pidx sidx |
|
72 |
let vtags = sepSplit ',' tags |
|
73 |
newinst = Instance.create name vmem vdsk vvcpus status vtags pidx sidx |
|
73 | 74 |
return (name, newinst) |
74 | 75 |
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'" |
75 | 76 |
|
b/hscan.hs | ||
---|---|---|
81 | 81 |
then "" |
82 | 82 |
else Container.nameOf nl sidx ++ csf) |
83 | 83 |
in |
84 |
printf "%s|%d|%d|%d|%s|%s|%s" |
|
84 |
printf "%s|%d|%d|%d|%s|%s|%s|%s"
|
|
85 | 85 |
iname (Instance.mem inst) (Instance.dsk inst) |
86 | 86 |
(Instance.vcpus inst) (Instance.runSt inst) |
87 |
pnode snode |
|
87 |
pnode snode (intercalate "," (Instance.tags inst))
|
|
88 | 88 |
|
89 | 89 |
-- | Generate instance file data from instance objects |
90 | 90 |
serializeInstances :: String -> Node.List -> Instance.List -> String |
b/hspace.hs | ||
---|---|---|
277 | 277 |
|
278 | 278 |
-- utility functions |
279 | 279 |
let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx) |
280 |
(rspecCpu spx) "ADMIN_down" (-1) (-1) |
|
280 |
(rspecCpu spx) "ADMIN_down" [] (-1) (-1)
|
|
281 | 281 |
exitifbad val = (case val of |
282 | 282 |
Bad s -> do |
283 | 283 |
hPrintf stderr "Failure: %s\n" s |
Also available in: Unified diff