return utils.UnescapeAndSplit(value)
+def check_maybefloat(option, opt, value): # pylint: disable=W0613
+ """Custom parser for float numbers which might be also defaults.
+
+ """
+ value = value.lower()
+
+ if value == constants.VALUE_DEFAULT:
+ return value
+ else:
+ return float(value)
+
+
# completion_suggestion is normally a list. Using numeric values not evaluating
# to False for dynamic completion.
(OPT_COMPL_MANY_NODES,
"unit",
"bool",
"list",
+ "maybefloat",
)
TYPE_CHECKER = Option.TYPE_CHECKER.copy()
TYPE_CHECKER["identkeyval"] = check_ident_key_val
TYPE_CHECKER["unit"] = check_unit
TYPE_CHECKER["bool"] = check_bool
TYPE_CHECKER["list"] = check_list
+ TYPE_CHECKER["maybefloat"] = check_maybefloat
# optparse.py sets make_option, so we do it for our own option class, too
DRY_RUN_OPT = cli_option("--dry-run", default=False,
action="store_true",
help=("Do not execute the operation, just run the"
- " check steps and verify it it could be"
+ " check steps and verify if it could be"
" executed"))
VERBOSE_OPT = cli_option("-v", "--verbose", default=False,
IPOLICY_VCPU_RATIO = cli_option("--ipolicy-vcpu-ratio",
dest="ipolicy_vcpu_ratio",
- type="float", default=None,
+ type="maybefloat", default=None,
help="The maximum allowed vcpu-to-cpu ratio")
IPOLICY_SPINDLE_RATIO = cli_option("--ipolicy-spindle-ratio",
dest="ipolicy_spindle_ratio",
- type="float", default=None,
+ type="maybefloat", default=None,
help=("The maximum allowed instances to"
" spindle ratio"))
DISK_STATE_OPT = cli_option("--disk-state", default=[], dest="disk_state",
action="append",
- help=("Specify disk state information in the format"
- " storage_type/identifier:option=value,..."),
+ help=("Specify disk state information in the"
+ " format"
+ " storage_type/identifier:option=value,...;"
+ " note this is unused for now"),
type="identkeyval")
HV_STATE_OPT = cli_option("--hypervisor-state", default=[], dest="hv_state",
action="append",
help=("Specify hypervisor state information in the"
- " format hypervisor:option=value,..."),
+ " format hypervisor:option=value,...;"
+ " note this is unused for now"),
type="identkeyval")
IGNORE_IPOLICY_OPT = cli_option("--ignore-ipolicy", dest="ignore_ipolicy",
return choice
+def _MaybeParseUnit(elements):
+ """Parses and returns an array of potential values with units.
+
+ """
+ parsed = {}
+ for k, v in elements.items():
+ if v == constants.VALUE_DEFAULT:
+ parsed[k] = v
+ else:
+ parsed[k] = utils.ParseUnit(v)
+ return parsed
+
+
def CreateIPolicyFromOpts(ispecs_mem_size=None,
ispecs_cpu_count=None,
ispecs_disk_count=None,
"""
try:
if ispecs_mem_size:
- for k in ispecs_mem_size:
- ispecs_mem_size[k] = utils.ParseUnit(ispecs_mem_size[k])
+ ispecs_mem_size = _MaybeParseUnit(ispecs_mem_size)
if ispecs_disk_size:
- for k in ispecs_disk_size:
- ispecs_disk_size[k] = utils.ParseUnit(ispecs_disk_size[k])
+ ispecs_disk_size = _MaybeParseUnit(ispecs_disk_size)
except (TypeError, ValueError, errors.UnitParseError), err:
raise errors.OpPrereqError("Invalid disk (%s) or memory (%s) size"
" in policy: %s" %