diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 4dfe9f99ffc837b63369253dcdd5a5498d32dce5..c6ff7a081fe5c80257d7b5c042248ebe6418beec 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -70,6 +70,14 @@ def _EmptyDict(): return {} +#: The without-default default value +_NoDefault = object() + + +#: The no-type (value to complex to check it in the type system) +_NoType = object() + + # Some basic types def _TNotNone(val): """Checks if the given value is not None. @@ -163,13 +171,24 @@ def _TOr(*args): # Type aliases -# non-empty string +#: a non-empty string _TNonEmptyString = _TAnd(_TString, _TTrue) -# positive integer +#: a maybe non-empty string +_TMaybeString = _TOr(_TNonEmptyString, _TNone) + + +#: a maybe boolean (bool or none) +_TMaybeBool = _TOr(_TBool, _TNone) + + +#: a positive integer _TPositiveInt = _TAnd(_TInt, lambda v: v >= 0) +#: a strictly positive integer +_TStrictPositiveInt = _TAnd(_TInt, lambda v: v > 0) + def _TListOf(my_type): """Checks if a given value is a list with all elements of the same type. @@ -189,6 +208,27 @@ def _TDictOf(key_type, val_type): for v in my_dict.values()))) +# Common opcode attributes + +#: output fields for a query operation +_POutputFields = ("output_fields", _NoDefault, _TListOf(_TNonEmptyString)) + + +#: the shutdown timeout +_PShutdownTimeout = ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, + _TPositiveInt) + +#: the force parameter +_PForce = ("force", False, _TBool) + +#: a required instance name (for single-instance LUs) +_PInstanceName = ("instance_name", _NoDefault, _TNonEmptyString) + + +#: a required node name (for single-node LUs) +_PNodeName = ("node_name", _NoDefault, _TNonEmptyString) + + # End types class LogicalUnit(object): """Logical Unit base class.