From 5f0749733ade294844fc818a3387e54a55927738 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Tue, 25 Jan 2011 17:59:36 +0100 Subject: [PATCH] ht: Add TMaybeDict check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This replaces a number of equal βht.TOr(ht.TDict, ht.TNone)β checks. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/ht.py | 4 ++-- lib/opcodes.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/ht.py b/lib/ht.py index 4e517101b..57dcdcaf2 100644 --- a/lib/ht.py +++ b/lib/ht.py @@ -163,14 +163,14 @@ def TMap(fn, test): #: a non-empty string TNonEmptyString = TAnd(TString, TTrue) - #: a maybe non-empty string TMaybeString = TOr(TNonEmptyString, TNone) - #: a maybe boolean (bool or none) TMaybeBool = TOr(TBool, TNone) +#: Maybe a dictionary (dict or None) +TMaybeDict = TOr(TDict, TNone) #: a positive integer TPositiveInt = TAnd(TInt, lambda v: v >= 0) diff --git a/lib/opcodes.py b/lib/opcodes.py index ef20a72dd..288f2e5a7 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -533,8 +533,8 @@ class OpClusterSetParams(OpCode): ("remove_uids", None, ht.NoType), ("maintain_node_health", None, ht.TMaybeBool), ("prealloc_wipe_disks", None, ht.TMaybeBool), - ("nicparams", None, ht.TOr(ht.TDict, ht.TNone)), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("nicparams", None, ht.TMaybeDict), + ("ndparams", None, ht.TMaybeDict), ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone)), ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)), ("master_netdev", None, ht.TOr(ht.TString, ht.TNone)), @@ -649,7 +649,7 @@ class OpNodeAdd(OpCode): ("group", None, ht.TMaybeString), ("master_capable", None, ht.TMaybeBool), ("vm_capable", None, ht.TMaybeBool), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("ndparams", None, ht.TMaybeDict), ] @@ -714,7 +714,7 @@ class OpNodeSetParams(OpCode): ("master_capable", None, ht.TMaybeBool), ("vm_capable", None, ht.TMaybeBool), ("secondary_ip", None, ht.TMaybeString), - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("ndparams", None, ht.TMaybeDict), ("powered", None, ht.TMaybeBool), ] @@ -803,7 +803,7 @@ class OpInstanceReinstall(OpCode): _PInstanceName, ("os_type", None, ht.TMaybeString), ("force_variant", False, ht.TBool), - ("osparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("osparams", None, ht.TMaybeDict), ] @@ -985,7 +985,7 @@ class OpInstanceSetParams(OpCode): ("remote_node", None, ht.TMaybeString), ("os_name", None, ht.TMaybeString), ("force_variant", False, ht.TBool), - ("osparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("osparams", None, ht.TMaybeDict), ] @@ -1007,7 +1007,7 @@ class OpGroupAdd(OpCode): OP_DSC_FIELD = "group_name" OP_PARAMS = [ _PGroupName, - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("ndparams", None, ht.TMaybeDict), ("alloc_policy", None, ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES))), ] @@ -1036,7 +1036,7 @@ class OpGroupSetParams(OpCode): OP_DSC_FIELD = "group_name" OP_PARAMS = [ _PGroupName, - ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)), + ("ndparams", None, ht.TMaybeDict), ("alloc_policy", None, ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES))), ] -- GitLab