diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs index 3209ce7a71e9a8b29cad3010a36b1dabeb22ffae..99f07dc257d6e8dd0fac04b7cd2e653ab1249575 100644 --- a/htools/Ganeti/HTools/Types.hs +++ b/htools/Ganeti/HTools/Types.hs @@ -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 diff --git a/htools/Ganeti/THH.hs b/htools/Ganeti/THH.hs index 2c6983dd118f642626bbbc78d6ce3210283e7dc6..ca1e7659295f3cedeb959427c0372a88f8236f2d 100644 --- a/htools/Ganeti/THH.hs +++ b/htools/Ganeti/THH.hs @@ -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)