Revision a138ead7

b/lib/ht.py
121 121
  @param fn: Wrapped function
122 122

  
123 123
  """
124
  # Some type descriptions are rather long. If "None" is listed at the
125
  # end or somewhere in between it is easily missed. Therefore it should
126
  # be at the beginning, e.g. "None or (long description)".
127
  if __debug__ and TNone in args and args.index(TNone) > 0:
128
    raise Exception("TNone must be listed first")
129

  
124 130
  if len(args) == 1:
125 131
    descr = str(args[0])
126 132
  else:
......
310 316
TNonEmptyString = WithDesc("NonEmptyString")(TAnd(TString, TTrue))
311 317

  
312 318
#: a maybe non-empty string
313
TMaybeString = TOr(TNonEmptyString, TNone)
319
TMaybeString = TOr(TNone, TNonEmptyString)
314 320

  
315 321
#: a maybe boolean (bool or none)
316
TMaybeBool = TOr(TBool, TNone)
322
TMaybeBool = TOr(TNone, TBool)
317 323

  
318 324
#: Maybe a dictionary (dict or None)
319
TMaybeDict = TOr(TDict, TNone)
325
TMaybeDict = TOr(TNone, TDict)
320 326

  
321 327
#: a non-negative integer (value >= 0)
322 328
TNonNegativeInt = \
......
327 333
  TAnd(TInt, WithDesc("GreaterThanZero")(lambda v: v > 0))
328 334

  
329 335
#: a maybe positive integer (positive integer or None)
330
TMaybePositiveInt = TOr(TPositiveInt, TNone)
336
TMaybePositiveInt = TOr(TNone, TPositiveInt)
331 337

  
332 338
#: a negative integer (value < 0)
333 339
TNegativeInt = \
b/lib/opcodes.py
150 150
                  "List of error codes that should be treated as warnings")
151 151

  
152 152
# Disk parameters
153
_PDiskParams = ("diskparams", None,
154
                ht.TOr(
155
                  ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
156
                  ht.TNone),
157
                "Disk templates' parameter defaults")
153
_PDiskParams = \
154
  ("diskparams", None,
155
   ht.TOr(ht.TNone,
156
          ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict)),
157
   "Disk templates' parameter defaults")
158 158

  
159 159
# Parameters for node resource model
160 160
_PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
......
325 325
  template_check = ht.TElemOf(constants.DISK_TEMPLATES)
326 326

  
327 327
  if accept_none:
328
    template_check = ht.TOr(template_check, ht.TNone)
328
    template_check = ht.TOr(ht.TNone, template_check)
329 329

  
330 330
  return ht.TAnd(template_check, _CheckFileStorage)
331 331

  
......
864 864
  OP_PARAMS = [
865 865
    _PHvState,
866 866
    _PDiskState,
867
    ("vg_name", None, ht.TOr(ht.TString, ht.TNone), "Volume group name"),
867
    ("vg_name", None, ht.TOr(ht.TNone, ht.TString), "Volume group name"),
868 868
    ("enabled_hypervisors", None,
869
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
870
            ht.TNone),
869
     ht.TOr(ht.TNone,
870
            ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue)),
871 871
     "List of enabled hypervisors"),
872
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
873
                              ht.TNone),
872
    ("hvparams", None,
873
     ht.TOr(ht.TNone, ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
874 874
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
875
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
875
    ("beparams", None, ht.TOr(ht.TNone, ht.TDict),
876 876
     "Cluster-wide backend parameter defaults"),
877
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
878
                            ht.TNone),
877
    ("os_hvp", None, ht.TOr(ht.TNone, ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
879 878
     "Cluster-wide per-OS hypervisor parameter defaults"),
880
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
881
                              ht.TNone),
879
    ("osparams", None,
880
     ht.TOr(ht.TNone, ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
882 881
     "Cluster-wide OS parameter defaults"),
883 882
    _PDiskParams,
884
    ("candidate_pool_size", None, ht.TOr(ht.TPositiveInt, ht.TNone),
883
    ("candidate_pool_size", None, ht.TOr(ht.TNone, ht.TPositiveInt),
885 884
     "Master candidate pool size"),
886 885
    ("uid_pool", None, ht.NoType,
887 886
     "Set UID pool, must be list of lists describing UID ranges (two items,"
......
900 899
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
901 900
    ("ipolicy", None, ht.TMaybeDict,
902 901
     "Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
903
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
904
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
902
    ("drbd_helper", None, ht.TOr(ht.TNone, ht.TString), "DRBD helper program"),
903
    ("default_iallocator", None, ht.TOr(ht.TNone, ht.TString),
905 904
     "Default iallocator for cluster"),
906
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
905
    ("master_netdev", None, ht.TOr(ht.TNone, ht.TString),
907 906
     "Master network device"),
908
    ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
907
    ("master_netmask", None, ht.TOr(ht.TNone, ht.TInt),
909 908
     "Netmask of the master IP"),
910 909
    ("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString),
911 910
     "List of reserved LVs"),
......
1274 1273
    ("os_type", None, ht.TMaybeString, "Operating system"),
1275 1274
    ("pnode", None, ht.TMaybeString, "Primary node"),
1276 1275
    ("snode", None, ht.TMaybeString, "Secondary node"),
1277
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1276
    ("source_handshake", None, ht.TOr(ht.TNone, ht.TList),
1278 1277
     "Signed handshake from source (remote import only)"),
1279 1278
    ("source_instance_name", None, ht.TMaybeString,
1280 1279
     "Source instance name (remote import only)"),
......
1843 1842
     "Whether to ignore failures while removing instances"),
1844 1843
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1845 1844
     "Export mode"),
1846
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1845
    ("x509_key_name", None, ht.TOr(ht.TNone, ht.TList),
1847 1846
     "Name of X509 key (remote export only)"),
1848 1847
    ("destination_x509_ca", None, ht.TMaybeString,
1849 1848
     "Destination X509 CA (remote export only)"),

Also available in: Unified diff