From a07343b2ac5693f5f0d5bc715806a0b9974b2440 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 22 Dec 2011 16:27:05 +0100 Subject: [PATCH] Add object definitions for the ispec and ipolicy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: RenΓ© Nussbaumer <rn@google.com> --- htools/Ganeti/HTools/Types.hs | 22 +++++++++++++++++++++- htools/Ganeti/THH.hs | 10 +++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs index 3209ce7a7..99f07dc25 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 2c6983dd1..ca1e76592 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) -- GitLab