Commit a07343b2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add object definitions for the ispec and ipolicy


Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent b69be409
......@@ -72,14 +72,17 @@ module Ganeti.HTools.Types
, connTimeout
, queryTimeout
, EvacMode(..)
, ISpec(..)
, IPolicy(..)
) where
import qualified Data.Map as M
import qualified Text.JSON as JSON
import Text.JSON (makeObj, readJSON, showJSON)
import qualified Ganeti.Constants as C
import qualified Ganeti.THH as THH
import Ganeti.BasicTypes
import Ganeti.HTools.JSON
-- | The instance index type.
type Idx = Int
......@@ -139,6 +142,23 @@ data RSpec = RSpec
, rspecDsk :: Int -- ^ Requested disk
} deriving (Show, Read, Eq)
-- | Instance specification type.
$(THH.buildObject "ISpec" "iSpec"
[ THH.renameField "MemorySize" $ THH.simpleField "memory-size" [t| Int |]
, THH.renameField "CpuCount" $ THH.simpleField "cpu-count" [t| Int |]
, THH.renameField "DiskSize" $ THH.simpleField "disk-size" [t| Int |]
, THH.renameField "DiskCount" $ THH.simpleField "disk-count" [t| Int |]
, THH.renameField "NicCount" $ THH.simpleField "nic-count" [t| Int |]
])
-- | Instance policy type.
$(THH.buildObject "IPolicy" "iPolicy"
[ THH.renameField "StdSpec" $ THH.simpleField "std" [t| ISpec |]
, THH.renameField "MinSpec" $ THH.simpleField "min" [t| ISpec |]
, THH.renameField "MaxSpec" $ THH.simpleField "max" [t| ISpec |]
])
-- | The dynamic resource specs of a machine (i.e. load or load
-- capacity, as opposed to size).
data DynUtil = DynUtil
......
......@@ -453,7 +453,7 @@ saveConstructor sname fields = do
let felems = map (uncurry saveObjectField) (zip fnames fields)
-- now build the OP_ID serialisation
opid = [| [( $(stringE "OP_ID"),
$showJSONE $(stringE . deCamelCase $ sname) )] |]
JSON.showJSON $(stringE . deCamelCase $ sname) )] |]
flist = listE (opid:felems)
-- and finally convert all this to a json object
flist' = [| $(varNameE "makeObj") (concat $flist) |]
......@@ -621,14 +621,14 @@ genSaveObject save_fn sname fields = do
saveObjectField :: Name -> Field -> Q Exp
saveObjectField fvar field
| isContainer = [| [( $nameE , $showJSONE . showContainer $ $fvarE)] |]
| isContainer = [| [( $nameE , JSON.showJSON . showContainer $ $fvarE)] |]
| fisOptional = [| case $(varE fvar) of
Nothing -> []
Just v -> [( $nameE, $showJSONE v)]
Just v -> [( $nameE, JSON.showJSON v)]
|]
| otherwise = case fieldShow field of
Nothing -> [| [( $nameE, $showJSONE $fvarE)] |]
Just fn -> [| [( $nameE, $showJSONE . $fn $ $fvarE)] |]
Nothing -> [| [( $nameE, JSON.showJSON $fvarE)] |]
Just fn -> [| [( $nameE, JSON.showJSON . $fn $ $fvarE)] |]
where isContainer = fieldIsContainer field
fisOptional = fieldIsOptional field
nameE = stringE (fieldName field)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment