Commit a604f165 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add cli function for beparams validation

This is used to validate the parameters in both “gnt-instance add” and
“gnt-backup import”.

Reviewed-by: ultrotter
parent cd3ab26e
......@@ -49,6 +49,7 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"ListTags", "AddTags", "RemoveTags", "TAG_SRC_OPT",
"FormatError", "SplitNodeOption", "SubmitOrSend",
"JobSubmittedException", "FormatTimestamp", "ParseTimespec",
"ValidateBeParams",
]
......@@ -401,6 +402,27 @@ def SplitNodeOption(value):
return (value, None)
def ValidateBeParams(bep):
"""Parse and check the given beparams.
The function will update in-place the given dictionary.
@type bep: dict
@param bep: input beparams
@raise errors.ParameterError: if the input values are not OK
@raise errors.UnitParseError: if the input values are not OK
"""
if constants.BE_MEMORY in bep:
bep[constants.BE_MEMORY] = utils.ParseUnit(bep[constants.BE_MEMORY])
if constants.BE_VCPUS in bep:
try:
bep[constants.BE_VCPUS] = int(bep[constants.BE_VCPUS])
except ValueError:
raise errors.ParameterError("Invalid number of VCPUs")
def AskUser(text, choices=None):
"""Ask the user a question.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment