Commit d5a93a80 authored by Iustin Pop's avatar Iustin Pop

Remove container field special cases

Since we now handle Containers uniformly, we can remove all traces of
the special handling for this field type.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 84835174
......@@ -357,9 +357,9 @@ $(buildObject "Cluster" "cluster" $
, simpleField "enabled_hypervisors" [t| [String] |]
-- , simpleField "hvparams" [t| [(String, [(String, String)])] |]
-- , simpleField "os_hvp" [t| [(String, String)] |]
, containerField $ simpleField "beparams" [t| FilledBEParams |]
, simpleField "beparams" [t| Container FilledBEParams |]
-- , simpleField "osparams" [t| [(String, String)] |]
, containerField $ simpleField "nicparams" [t| FilledNICParams |]
, simpleField "nicparams" [t| Container FilledNICParams |]
-- , simpleField "ndparams" [t| FilledNDParams |]
, simpleField "candidate_pool_size" [t| Int |]
, simpleField "modify_etc_hosts" [t| Bool |]
......@@ -381,10 +381,10 @@ $(buildObject "Cluster" "cluster" $
$(buildObject "ConfigData" "config" $
-- timeStampFields ++
[ simpleField "version" [t| Int |]
, simpleField "cluster" [t| Cluster |]
, containerField $ simpleField "nodes" [t| Node |]
, containerField $ simpleField "nodegroups" [t| NodeGroup |]
, containerField $ simpleField "instances" [t| Instance |]
[ simpleField "version" [t| Int |]
, simpleField "cluster" [t| Cluster |]
, simpleField "nodes" [t| Container Node |]
, simpleField "nodegroups" [t| Container NodeGroup |]
, simpleField "instances" [t| Container Instance |]
]
++ serialFields)
......@@ -42,7 +42,6 @@ module Ganeti.THH ( declareSADT
, defaultField
, optionalField
, renameField
, containerField
, customField
, timeStampFields
, uuidFields
......@@ -51,7 +50,6 @@ module Ganeti.THH ( declareSADT
, buildObject
, buildObjectSerialisation
, buildParam
, Container
) where
import Control.Monad (liftM, liftM2)
......@@ -62,8 +60,6 @@ import Language.Haskell.TH
import qualified Text.JSON as JSON
import Ganeti.HTools.JSON
-- * Exported types
-- | Serialised field data type.
......@@ -73,7 +69,6 @@ data Field = Field { fieldName :: String
, fieldShow :: Maybe (Q Exp)
, fieldDefault :: Maybe (Q Exp)
, fieldConstr :: Maybe String
, fieldIsContainer :: Bool
, fieldIsOptional :: Bool
}
......@@ -86,7 +81,6 @@ simpleField fname ftype =
, fieldShow = Nothing
, fieldDefault = Nothing
, fieldConstr = Nothing
, fieldIsContainer = False
, fieldIsOptional = False
}
......@@ -103,10 +97,6 @@ defaultField defval field = field { fieldDefault = Just defval }
optionalField :: Field -> Field
optionalField field = field { fieldIsOptional = True }
-- | Marks a field as a container.
containerField :: Field -> Field
containerField field = field { fieldIsContainer = True }
-- | Sets custom functions on a field.
customField :: Name -- ^ The name of the read function
-> Name -- ^ The name of the show function
......@@ -130,8 +120,7 @@ fieldVariable f =
_ -> map (\c -> if c == '-' then '_' else c) $ fieldName f
actualFieldType :: Field -> Q Type
actualFieldType f | fieldIsContainer f = [t| Container $t |]
| fieldIsOptional f = [t| Maybe $t |]
actualFieldType f | fieldIsOptional f = [t| Maybe $t |]
| otherwise = t
where t = fieldType f
......@@ -150,8 +139,6 @@ loadFn :: Field -- ^ The field definition
-> Q Exp -- ^ The value of the field as existing in the JSON message
-> Q Exp -- ^ The entire object in JSON object format
-> Q Exp -- ^ Resulting expression
loadFn (Field { fieldIsContainer = True }) expr _ =
[| $expr |]
loadFn (Field { fieldRead = Just readfn }) expr o = [| $expr >>= $readfn $o |]
loadFn _ expr _ = expr
......@@ -623,7 +610,6 @@ genSaveObject save_fn sname fields = do
saveObjectField :: Name -> Field -> Q Exp
saveObjectField fvar field
| isContainer = [| [( $nameE , JSON.showJSON $fvarE)] |]
| fisOptional = [| case $(varE fvar) of
Nothing -> []
Just v -> [( $nameE, JSON.showJSON v)]
......@@ -633,8 +619,7 @@ saveObjectField fvar field
Just fn -> [| let (actual, extra) = $fn $fvarE
in extra ++ [( $nameE, JSON.showJSON actual)]
|]
where isContainer = fieldIsContainer field
fisOptional = fieldIsOptional field
where fisOptional = fieldIsOptional field
nameE = stringE (fieldName field)
fvarE = varE fvar
......
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