Revision ebf38064 htools/Ganeti/HTools/Text.hs

b/htools/Ganeti/HTools/Text.hs
27 27
-}
28 28

  
29 29
module Ganeti.HTools.Text
30
    (
31
      loadData
32
    , parseData
33
    , loadInst
34
    , loadNode
35
    , serializeInstances
36
    , serializeNode
37
    , serializeNodes
38
    , serializeCluster
39
    ) where
30
  ( loadData
31
  , parseData
32
  , loadInst
33
  , loadNode
34
  , serializeInstances
35
  , serializeNode
36
  , serializeNodes
37
  , serializeCluster
38
  ) where
40 39

  
41 40
import Control.Monad
42 41
import Data.List
......
56 55
-- | Serialize a single group.
57 56
serializeGroup :: Group.Group -> String
58 57
serializeGroup grp =
59
    printf "%s|%s|%s" (Group.name grp) (Group.uuid grp)
60
               (allocPolicyToRaw (Group.allocPolicy grp))
58
  printf "%s|%s|%s" (Group.name grp) (Group.uuid grp)
59
           (allocPolicyToRaw (Group.allocPolicy grp))
61 60

  
62 61
-- | Generate group file data from a group list.
63 62
serializeGroups :: Group.List -> String
......
68 67
              -> Node.Node  -- ^ The node to be serialised
69 68
              -> String
70 69
serializeNode gl node =
71
    printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s" (Node.name node)
72
               (Node.tMem node) (Node.nMem node) (Node.fMem node)
73
               (Node.tDsk node) (Node.fDsk node) (Node.tCpu node)
74
               (if Node.offline node then 'Y' else 'N')
75
               (Group.uuid grp)
70
  printf "%s|%.0f|%d|%d|%.0f|%d|%.0f|%c|%s" (Node.name node)
71
           (Node.tMem node) (Node.nMem node) (Node.fMem node)
72
           (Node.tDsk node) (Node.fDsk node) (Node.tCpu node)
73
           (if Node.offline node then 'Y' else 'N')
74
           (Group.uuid grp)
76 75
    where grp = Container.find (Node.group node) gl
77 76

  
78 77
-- | Generate node file data from node objects.
......
85 84
                  -> Instance.Instance -- ^ The instance to be serialised
86 85
                  -> String
87 86
serializeInstance nl inst =
88
    let
89
        iname = Instance.name inst
90
        pnode = Container.nameOf nl (Instance.pNode inst)
91
        sidx = Instance.sNode inst
92
        snode = (if sidx == Node.noSecondary
93
                    then ""
94
                    else Container.nameOf nl sidx)
95
    in
96
      printf "%s|%d|%d|%d|%s|%s|%s|%s|%s|%s"
97
             iname (Instance.mem inst) (Instance.dsk inst)
98
             (Instance.vcpus inst) (instanceStatusToRaw (Instance.runSt inst))
99
             (if Instance.autoBalance inst then "Y" else "N")
100
             pnode snode (diskTemplateToRaw (Instance.diskTemplate inst))
101
             (intercalate "," (Instance.tags inst))
87
  let iname = Instance.name inst
88
      pnode = Container.nameOf nl (Instance.pNode inst)
89
      sidx = Instance.sNode inst
90
      snode = (if sidx == Node.noSecondary
91
                 then ""
92
                 else Container.nameOf nl sidx)
93
  in printf "%s|%d|%d|%d|%s|%s|%s|%s|%s|%s"
94
       iname (Instance.mem inst) (Instance.dsk inst)
95
       (Instance.vcpus inst) (instanceStatusToRaw (Instance.runSt inst))
96
       (if Instance.autoBalance inst then "Y" else "N")
97
       pnode snode (diskTemplateToRaw (Instance.diskTemplate inst))
98
       (intercalate "," (Instance.tags inst))
102 99

  
103 100
-- | Generate instance file data from instance objects.
104 101
serializeInstances :: Node.List -> Instance.List -> String
105 102
serializeInstances nl =
106
    unlines . map (serializeInstance nl) . Container.elems
103
  unlines . map (serializeInstance nl) . Container.elems
107 104

  
108 105
-- | Generate complete cluster data from node and instance lists.
109 106
serializeCluster :: ClusterData -> String

Also available in: Unified diff