Revision a07343b2

b/htools/Ganeti/HTools/Types.hs
72 72
  , connTimeout
73 73
  , queryTimeout
74 74
  , EvacMode(..)
75
  , ISpec(..)
76
  , IPolicy(..)
75 77
  ) where
76 78

  
77 79
import qualified Data.Map as M
78
import qualified Text.JSON as JSON
80
import Text.JSON (makeObj, readJSON, showJSON)
79 81

  
80 82
import qualified Ganeti.Constants as C
81 83
import qualified Ganeti.THH as THH
82 84
import Ganeti.BasicTypes
85
import Ganeti.HTools.JSON
83 86

  
84 87
-- | The instance index type.
85 88
type Idx = Int
......
139 142
  , rspecDsk  :: Int  -- ^ Requested disk
140 143
  } deriving (Show, Read, Eq)
141 144

  
145

  
146
-- | Instance specification type.
147
$(THH.buildObject "ISpec" "iSpec"
148
  [ THH.renameField "MemorySize" $ THH.simpleField "memory-size" [t| Int |]
149
  , THH.renameField "CpuCount"   $ THH.simpleField "cpu-count"   [t| Int |]
150
  , THH.renameField "DiskSize"   $ THH.simpleField "disk-size"   [t| Int |]
151
  , THH.renameField "DiskCount"  $ THH.simpleField "disk-count"  [t| Int |]
152
  , THH.renameField "NicCount"   $ THH.simpleField "nic-count"   [t| Int |]
153
  ])
154

  
155
-- | Instance policy type.
156
$(THH.buildObject "IPolicy" "iPolicy"
157
  [ THH.renameField "StdSpec" $ THH.simpleField "std" [t| ISpec |]
158
  , THH.renameField "MinSpec" $ THH.simpleField "min" [t| ISpec |]
159
  , THH.renameField "MaxSpec" $ THH.simpleField "max" [t| ISpec |]
160
  ])
161

  
142 162
-- | The dynamic resource specs of a machine (i.e. load or load
143 163
-- capacity, as opposed to size).
144 164
data DynUtil = DynUtil
b/htools/Ganeti/THH.hs
453 453
  let felems = map (uncurry saveObjectField) (zip fnames fields)
454 454
      -- now build the OP_ID serialisation
455 455
      opid = [| [( $(stringE "OP_ID"),
456
                   $showJSONE $(stringE . deCamelCase $ sname) )] |]
456
                   JSON.showJSON $(stringE . deCamelCase $ sname) )] |]
457 457
      flist = listE (opid:felems)
458 458
      -- and finally convert all this to a json object
459 459
      flist' = [| $(varNameE "makeObj") (concat $flist) |]
......
621 621

  
622 622
saveObjectField :: Name -> Field -> Q Exp
623 623
saveObjectField fvar field
624
  | isContainer = [| [( $nameE , $showJSONE . showContainer $ $fvarE)] |]
624
  | isContainer = [| [( $nameE , JSON.showJSON . showContainer $ $fvarE)] |]
625 625
  | fisOptional = [| case $(varE fvar) of
626 626
                      Nothing -> []
627
                      Just v -> [( $nameE, $showJSONE v)]
627
                      Just v -> [( $nameE, JSON.showJSON v)]
628 628
                  |]
629 629
  | otherwise = case fieldShow field of
630
      Nothing -> [| [( $nameE, $showJSONE $fvarE)] |]
631
      Just fn -> [| [( $nameE, $showJSONE . $fn $ $fvarE)] |]
630
      Nothing -> [| [( $nameE, JSON.showJSON $fvarE)] |]
631
      Just fn -> [| [( $nameE, JSON.showJSON . $fn $ $fvarE)] |]
632 632
  where isContainer = fieldIsContainer field
633 633
        fisOptional  = fieldIsOptional field
634 634
        nameE = stringE (fieldName field)

Also available in: Unified diff