Should the patch title not read "... add node parameter related constants"
instead of "... add node parameter related"?


On Mon, Oct 7, 2013 at 4:37 PM, Jose A. Lopes <[email protected]> wrote:

> Add node parameter related constants to the Haskell to Python constant
> generation.  This patch also fixes a type inconsistency between
> Haskell and Python, namely, 'ndsParameterTypes' and
> 'ndsParameterTitles' become 'Map's instead of 'Tuple's, which allows
> us to simplify the module 'Ganeti.Query.Common'.
>
> Signed-off-by: Jose A. Lopes <[email protected]>
> ---
>  lib/constants.py           | 38 ++++++++++----------------------------
>  src/Ganeti/HsConstants.hs  | 45
> ++++++++++++++++++++++++++++++++++++++++++++-
>  src/Ganeti/Query/Common.hs | 12 ++----------
>  3 files changed, 56 insertions(+), 39 deletions(-)
>
> diff --git a/lib/constants.py b/lib/constants.py
> index 8319124..1fe7087 100644
> --- a/lib/constants.py
> +++ b/lib/constants.py
> @@ -976,6 +976,16 @@ DS_DEFAULTS = {
>    DS_DISK_OVERHEAD: 0,
>    }
>
> +ND_OOB_PROGRAM = _constants.ND_OOB_PROGRAM
> +ND_SPINDLE_COUNT = _constants.ND_SPINDLE_COUNT
> +ND_EXCLUSIVE_STORAGE = _constants.ND_EXCLUSIVE_STORAGE
> +ND_OVS = _constants.ND_OVS
> +ND_OVS_NAME = _constants.ND_OVS_NAME
> +ND_OVS_LINK = _constants.ND_OVS_LINK
> +
> +NDS_PARAMETER_TYPES = _constants.NDS_PARAMETER_TYPES
> +NDS_PARAMETERS = _constants.NDS_PARAMETERS
> +NDS_PARAMETER_TITLES = _constants.NDS_PARAMETER_TITLES
>  DSS_PARAMETER_TYPES = {
>    DS_DISK_TOTAL: VTYPE_INT,
>    DS_DISK_RESERVED: VTYPE_INT,
> @@ -1057,34 +1067,6 @@ IPOLICY_PARAMETERS = compat.UniqueFrozenset([
>  IPOLICY_ALL_KEYS = (IPOLICY_PARAMETERS |
>                      frozenset([ISPECS_MINMAX, ISPECS_STD, IPOLICY_DTS]))
>
> -# Node parameter names
> -ND_OOB_PROGRAM = "oob_program"
> -ND_SPINDLE_COUNT = "spindle_count"
> -ND_EXCLUSIVE_STORAGE = "exclusive_storage"
> -ND_OVS = "ovs"
> -ND_OVS_NAME = "ovs_name"
> -ND_OVS_LINK = "ovs_link"
> -
> -NDS_PARAMETER_TYPES = {
> -  ND_OOB_PROGRAM: VTYPE_STRING,
> -  ND_SPINDLE_COUNT: VTYPE_INT,
> -  ND_EXCLUSIVE_STORAGE: VTYPE_BOOL,
> -  ND_OVS: VTYPE_BOOL,
> -  ND_OVS_NAME: VTYPE_MAYBE_STRING,
> -  ND_OVS_LINK: VTYPE_MAYBE_STRING,
> -  }
> -
> -NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
> -
> -NDS_PARAMETER_TITLES = {
> -  ND_OOB_PROGRAM: "OutOfBandProgram",
> -  ND_SPINDLE_COUNT: "SpindleCount",
> -  ND_EXCLUSIVE_STORAGE: "ExclusiveStorage",
> -  ND_OVS: "OpenvSwitch",
> -  ND_OVS_NAME: "OpenvSwitchName",
> -  ND_OVS_LINK: "OpenvSwitchLink",
> -  }
> -
>  # Logical Disks parameters
>  LDP_RESYNC_RATE = "resync-rate"
>  LDP_STRIPES = "stripes"
> diff --git a/src/Ganeti/HsConstants.hs b/src/Ganeti/HsConstants.hs
> index 195bc2f..165d522 100644
> --- a/src/Ganeti/HsConstants.hs
> +++ b/src/Ganeti/HsConstants.hs
> @@ -38,7 +38,7 @@ module Ganeti.HsConstants where
>
>  import Data.List ((\\))
>  import Data.Map (Map)
> -import qualified Data.Map as Map (fromList)
> +import qualified Data.Map as Map (fromList, keys, insert)
>
>  import AutoConf
>  import Ganeti.ConstantUtils (FrozenSet, Protocol(..), buildVersion)
> @@ -664,6 +664,49 @@ rpcTmo_1day = Types.rpcTimeoutToRaw OneDay
>  rpcConnectTimeout :: Int
>  rpcConnectTimeout = 5
>
> +-- | Node parameter names
> +
> +ndExclusiveStorage :: String
> +ndExclusiveStorage = "exclusive_storage"
> +
> +ndOobProgram :: String
> +ndOobProgram = "oob_program"
> +
> +ndSpindleCount :: String
> +ndSpindleCount = "spindle_count"
> +
> +ndOvs :: String
> +ndOvs = "ovs"
> +
> +ndOvsLink :: String
> +ndOvsLink = "ovs_link"
> +
> +ndOvsName :: String
> +ndOvsName = "ovs_name"
> +
> +ndsParameterTypes :: Map String VType
> +ndsParameterTypes =
> +  Map.fromList
> +  [(ndExclusiveStorage, VTypeBool),
> +   (ndOobProgram, VTypeString),
> +   (ndOvs, VTypeBool),
> +   (ndOvsLink, VTypeMaybeString),
> +   (ndOvsName, VTypeMaybeString),
> +   (ndSpindleCount, VTypeInt)]
> +
> +ndsParameters :: FrozenSet String
> +ndsParameters = ConstantUtils.mkSet (Map.keys ndsParameterTypes)
> +
> +ndsParameterTitles :: Map String String
> +ndsParameterTitles =
> +  Map.fromList
> +  [(ndExclusiveStorage, "ExclusiveStorage"),
> +   (ndOobProgram, "OutOfBandProgram"),
> +   (ndOvs, "OpenvSwitch"),
> +   (ndOvsLink, "OpenvSwitchLink"),
> +   (ndOvsName, "OpenvSwitchName"),
> +   (ndSpindleCount, "SpindleCount")]
> +
>  ipCommandPath :: String
>  ipCommandPath = AutoConf.ipPath
>
> diff --git a/src/Ganeti/Query/Common.hs b/src/Ganeti/Query/Common.hs
> index 51b3b76..f710d71 100644
> --- a/src/Ganeti/Query/Common.hs
> +++ b/src/Ganeti/Query/Common.hs
> @@ -37,7 +37,6 @@ module Ganeti.Query.Common
>    , serialFields
>    , tagsFields
>    , dictFieldGetter
> -  , buildQFTLookup
>    , buildNdParamField
>    ) where
>
> @@ -147,20 +146,13 @@ tagsFields =
>  dictFieldGetter :: (DictObject a) => String -> Maybe a -> ResultEntry
>  dictFieldGetter k = maybe rsNoData (rsMaybeNoData . lookup k . toDict)
>
> --- | Build an optimised lookup map from a Python _PARAMETER_TYPES
> --- association list.
> -buildQFTLookup :: [(String, String)] -> Map.Map String FieldType
> -buildQFTLookup =
> -  Map.fromList .
> -  map (\(k, v) -> (k, maybe QFTOther vTypeToQFT (vTypeFromRaw v)))
> -
>  -- | Ndparams optimised lookup map.
>  ndParamTypes :: Map.Map String FieldType
> -ndParamTypes = buildQFTLookup C.ndsParameterTypes
> +ndParamTypes = Map.map vTypeToQFT C.ndsParameterTypes
>
>  -- | Ndparams title map.
>  ndParamTitles :: Map.Map String FieldTitle
> -ndParamTitles = Map.fromList C.ndsParameterTitles
> +ndParamTitles = C.ndsParameterTitles
>
>  -- | Ndparam getter builder: given a field, it returns a FieldConfig
>  -- getter, that is a function that takes the config and the object and
> --
> 1.8.4
>
>
Rest LGTM, thanks.


-- 
Thomas Thrainer | Software Engineer | [email protected] |

Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to