-serializeNodes :: Node.List -> String -> String
-serializeNodes nl csf =
- let nodes = Container.elems nl
- nlines = map
- (\node ->
- let name = Node.name node ++ csf
- t_mem = (truncate $ Node.t_mem node)::Int
- t_dsk = (truncate $ Node.t_dsk node)::Int
- in
- printf "%s|%d|%d|%d|%d|%d|%c" name
- t_mem (Node.n_mem node) (Node.f_mem node)
- t_dsk (Node.f_dsk node)
- (if Node.offline node then 'Y' else 'N')
- )
- nodes
- in unlines nlines
+serializeNodes :: String -> Node.List -> String
+serializeNodes csf =
+ unlines . map (serializeNode csf) . Container.elems
+
+-- | Serialize a single instance
+serializeInstance :: String -> Node.List -> Instance.Instance -> String
+serializeInstance csf nl inst =
+ let
+ iname = Instance.name inst ++ csf
+ pnode = (Container.nameOf nl $ Instance.pnode inst) ++ csf
+ sidx = Instance.snode inst
+ snode = (if sidx == Node.noSecondary
+ then ""
+ else (Container.nameOf nl sidx) ++ csf)
+ in
+ printf "%s|%d|%d|%d|%s|%s|%s"
+ iname (Instance.mem inst) (Instance.dsk inst)
+ (Instance.vcpus inst) (Instance.run_st inst)
+ pnode snode