Commit 84a5b33c authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli: Add option definition for priority


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent e71c8147
......@@ -122,6 +122,7 @@ __all__ = [
"OS_OPT",
"OS_SIZE_OPT",
"PRIMARY_IP_VERSION_OPT",
"PRIORITY_OPT",
"RAPI_CERT_OPT",
"READD_OPT",
"REBOOT_TYPE_OPT",
......@@ -203,6 +204,18 @@ __all__ = [
NO_PREFIX = "no_"
UN_PREFIX = "-"
#: Priorities (sorted)
_PRIORITY_NAMES = [
("low", constants.OP_PRIO_LOW),
("normal", constants.OP_PRIO_NORMAL),
("high", constants.OP_PRIO_HIGH),
]
#: Priority dictionary for easier lookup
# TODO: Replace this and _PRIORITY_NAMES with a single sorted dictionary once
# we migrate to Python 2.6
_PRIONAME_TO_VALUE = dict(_PRIORITY_NAMES)
class _Argument:
def __init__(self, min=0, max=None): # pylint: disable-msg=W0622
......@@ -1037,6 +1050,11 @@ PRIMARY_IP_VERSION_OPT = \
constants.IP6_VERSION),
help="Cluster-wide IP version for primary IP")
PRIORITY_OPT = cli_option("--priority", default=None, dest="priority",
metavar="|".join(name for name, _ in _PRIORITY_NAMES),
choices=_PRIONAME_TO_VALUE.keys(),
help="Priority for opcode(s) processing")
#: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT]
......
......@@ -442,5 +442,13 @@ class TestParseFields(unittest.TestCase):
["def", "ault", "name", "foo"])
class TestConstants(unittest.TestCase):
def testPriority(self):
self.assertEqual(set(cli._PRIONAME_TO_VALUE.values()),
set(constants.OP_PRIO_SUBMIT_VALID))
self.assertEqual(list(value for _, value in cli._PRIORITY_NAMES),
sorted(constants.OP_PRIO_SUBMIT_VALID, reverse=True))
if __name__ == '__main__':
testutils.GanetiTestProgram()
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