X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/cbfa4f0f4df293b3f774d4dd7d2160c130f45fb4..3b7218422467e12322b6b628f3bd71d69eb9337a:/lib/client/gnt_node.py diff --git a/lib/client/gnt_node.py b/lib/client/gnt_node.py index 07d2497..e893b5e 100644 --- a/lib/client/gnt_node.py +++ b/lib/client/gnt_node.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,12 +20,15 @@ """Node related commands""" -# pylint: disable-msg=W0401,W0613,W0614,C0103 +# pylint: disable=W0401,W0613,W0614,C0103 # W0401: Wildcard import ganeti.cli # W0613: Unused argument, since all functions follow the same API # W0614: Unused import %s from wildcard import (since we need cli) # C0103: Invalid name gnt-node +import itertools +import errno + from ganeti.cli import * from ganeti import cli from ganeti import bootstrap @@ -34,8 +37,13 @@ from ganeti import utils from ganeti import constants from ganeti import errors from ganeti import netutils +from ganeti import pathutils +from ganeti import ssh +from ganeti import compat from cStringIO import StringIO +from ganeti import confd +from ganeti.confd import client as confd_client #: default list of field for L{ListNodes} _LIST_DEF_FIELDS = [ @@ -99,10 +107,12 @@ _REPAIRABLE_STORAGE_TYPES = \ _MODIFIABLE_STORAGE_TYPES = constants.MODIFIABLE_STORAGE_FIELDS.keys() +_OOB_COMMAND_ASK = compat.UniqueFrozenset([ + constants.OOB_POWER_OFF, + constants.OOB_POWER_CYCLE, + ]) -_OOB_COMMAND_ASK = frozenset([constants.OOB_POWER_OFF, - constants.OOB_POWER_CYCLE]) - +_ENV_OVERRIDE = compat.UniqueFrozenset(["list"]) NONODE_SETUP_OPT = cli_option("--no-node-setup", default=True, action="store_false", dest="node_setup", @@ -114,9 +124,6 @@ IGNORE_STATUS_OPT = cli_option("--ignore-status", default=False, help=("Ignore the Node(s) offline status" " (potentially DANGEROUS)")) -OOB_TIMEOUT_OPT = cli_option("--oob-timeout", dest="oob_timeout", type="int", - default=constants.OOB_TIMEOUT, - help="Maximum time to wait for out-of-band helper") def ConvertStorageType(user_storage_type): """Converts a user storage type to its internal name. @@ -129,34 +136,86 @@ def ConvertStorageType(user_storage_type): errors.ECODE_INVAL) -def _RunSetupSSH(options, nodes): - """Wrapper around utils.RunCmd to call setup-ssh +def _TryReadFile(path): + """Tries to read a file. + + If the file is not found, C{None} is returned. + + @type path: string + @param path: Filename + @rtype: None or string + @todo: Consider adding a generic ENOENT wrapper + + """ + try: + return utils.ReadFile(path) + except EnvironmentError, err: + if err.errno == errno.ENOENT: + return None + else: + raise + + +def _ReadSshKeys(keyfiles, _tostderr_fn=ToStderr): + """Reads SSH keys according to C{keyfiles}. + + @type keyfiles: dict + @param keyfiles: Dictionary with keys of L{constants.SSHK_ALL} and two-values + tuples (private and public key file) + @rtype: list + @return: List of three-values tuples (L{constants.SSHK_ALL}, private and + public key as strings) + + """ + result = [] + + for (kind, (private_file, public_file)) in keyfiles.items(): + private_key = _TryReadFile(private_file) + public_key = _TryReadFile(public_file) + + if public_key and private_key: + result.append((kind, private_key, public_key)) + elif public_key or private_key: + _tostderr_fn("Couldn't find a complete set of keys for kind '%s'; files" + " '%s' and '%s'", kind, private_file, public_file) - @param options: The command line options - @param nodes: The nodes to setup + return result + + +def _SetupSSH(options, cluster_name, node): + """Configures a destination node's SSH daemon. + + @param options: Command line options + @type cluster_name + @param cluster_name: Cluster name + @type node: string + @param node: Destination node name """ - cmd = [constants.SETUP_SSH] - - # Pass --debug|--verbose to the external script if set on our invocation - # --debug overrides --verbose - if options.debug: - cmd.append("--debug") - elif options.verbose: - cmd.append("--verbose") - if not options.ssh_key_check: - cmd.append("--no-ssh-key-check") if options.force_join: - cmd.append("--force-join") + ToStderr("The \"--force-join\" option is no longer supported and will be" + " ignored.") + + host_keys = _ReadSshKeys(constants.SSH_DAEMON_KEYFILES) - cmd.extend(nodes) + (_, root_keyfiles) = \ + ssh.GetAllUserFiles(constants.SSH_LOGIN_USER, mkdir=False, dircheck=False) - result = utils.RunCmd(cmd, interactive=True) + root_keys = _ReadSshKeys(root_keyfiles) - if result.failed: - errmsg = ("Command '%s' failed with exit code %s; output %r" % - (result.cmd, result.exit_code, result.output)) - raise errors.OpExecError(errmsg) + (_, cert_pem) = \ + utils.ExtractX509Certificate(utils.ReadFile(pathutils.NODED_CERT_FILE)) + + data = { + constants.SSHS_CLUSTER_NAME: cluster_name, + constants.SSHS_NODE_DAEMON_CERTIFICATE: cert_pem, + constants.SSHS_SSH_HOST_KEY: host_keys, + constants.SSHS_SSH_ROOT_KEY: root_keys, + } + + bootstrap.RunNodeSetupCmd(cluster_name, node, pathutils.PREPARE_NODE_JOIN, + options.debug, options.verbose, False, + options.ssh_key_check, options.ssh_key_check, data) @UsesRPC @@ -175,9 +234,9 @@ def AddNode(opts, args): readd = opts.readd try: - output = cl.QueryNodes(names=[node], fields=['name', 'sip'], + output = cl.QueryNodes(names=[node], fields=["name", "sip", "master"], use_locking=False) - node_exists, sip = output[0] + node_exists, sip, is_master = output[0] except (errors.OpPrereqError, errors.OpExecError): node_exists = "" sip = None @@ -187,6 +246,9 @@ def AddNode(opts, args): ToStderr("Node %s not in the cluster" " - please retry without '--readd'", node) return 1 + if is_master: + ToStderr("Node %s is the master, cannot readd", node) + return 1 else: if node_exists: ToStderr("Node %s already in the cluster (as %s)" @@ -195,8 +257,7 @@ def AddNode(opts, args): sip = opts.secondary_ip # read the cluster name from the master - output = cl.QueryConfigValues(['cluster_name']) - cluster_name = output[0] + (cluster_name, ) = cl.QueryConfigValues(["cluster_name"]) if not readd and opts.node_setup: ToStderr("-- WARNING -- \n" @@ -207,14 +268,23 @@ def AddNode(opts, args): "and grant full intra-cluster ssh root access to/from it\n", node) if opts.node_setup: - _RunSetupSSH(opts, [node]) + _SetupSSH(opts, cluster_name, node) - bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check) + bootstrap.SetupNodeDaemon(opts, cluster_name, node) + + if opts.disk_state: + disk_state = utils.FlatToDict(opts.disk_state) + else: + disk_state = {} + + hv_state = dict(opts.hv_state) op = opcodes.OpNodeAdd(node_name=args[0], secondary_ip=sip, readd=opts.readd, group=opts.nodegroup, vm_capable=opts.vm_capable, ndparams=opts.ndparams, - master_capable=opts.master_capable) + master_capable=opts.master_capable, + disk_state=disk_state, + hv_state=hv_state) SubmitOpCode(op, opts=opts) @@ -233,9 +303,12 @@ def ListNodes(opts, args): fmtoverride = dict.fromkeys(["pinst_list", "sinst_list", "tags"], (",".join, False)) + cl = GetClient(query=True) + return GenericList(constants.QR_NODE, selected_fields, args, opts.units, opts.separator, not opts.no_headers, - format_override=fmtoverride, verbose=opts.verbose) + format_override=fmtoverride, verbose=opts.verbose, + force_filter=opts.force_filter, cl=cl) def ListNodeFields(opts, args): @@ -248,8 +321,10 @@ def ListNodeFields(opts, args): @return: the desired exit code """ + cl = GetClient(query=True) + return GenericListFields(constants.QR_NODE, args, opts.separator, - not opts.no_headers) + not opts.no_headers, cl=cl) def EvacuateNode(opts, args): @@ -262,47 +337,73 @@ def EvacuateNode(opts, args): @return: the desired exit code """ + if opts.dst_node is not None: + ToStderr("New secondary node given (disabling iallocator), hence evacuating" + " secondary instances only.") + opts.secondary_only = True + opts.primary_only = False + + if opts.secondary_only and opts.primary_only: + raise errors.OpPrereqError("Only one of the --primary-only and" + " --secondary-only options can be passed", + errors.ECODE_INVAL) + elif opts.primary_only: + mode = constants.NODE_EVAC_PRI + elif opts.secondary_only: + mode = constants.NODE_EVAC_SEC + else: + mode = constants.NODE_EVAC_ALL + + # Determine affected instances + fields = [] + + if not opts.secondary_only: + fields.append("pinst_list") + if not opts.primary_only: + fields.append("sinst_list") + cl = GetClient() - force = opts.force - dst_node = opts.dst_node - iallocator = opts.iallocator + qcl = GetClient(query=True) + result = qcl.QueryNodes(names=args, fields=fields, use_locking=False) + qcl.Close() - op = opcodes.OpNodeEvacStrategy(nodes=args, - iallocator=iallocator, - remote_node=dst_node) + instances = set(itertools.chain(*itertools.chain(*itertools.chain(result)))) - result = SubmitOpCode(op, cl=cl, opts=opts) - if not result: - # no instances to migrate - ToStderr("No secondary instances on node(s) %s, exiting.", + if not instances: + # No instances to evacuate + ToStderr("No instances to evacuate on node(s) %s, exiting.", utils.CommaJoin(args)) return constants.EXIT_SUCCESS - if not force and not AskUser("Relocate instance(s) %s from node(s) %s?" % - (",".join("'%s'" % name[0] for name in result), - utils.CommaJoin(args))): + if not (opts.force or + AskUser("Relocate instance(s) %s from node(s) %s?" % + (utils.CommaJoin(utils.NiceSort(instances)), + utils.CommaJoin(args)))): return constants.EXIT_CONFIRMATION + # Evacuate node + op = opcodes.OpNodeEvacuate(node_name=args[0], mode=mode, + remote_node=opts.dst_node, + iallocator=opts.iallocator, + early_release=opts.early_release) + result = SubmitOrSend(op, opts, cl=cl) + + # Keep track of submitted jobs jex = JobExecutor(cl=cl, opts=opts) - for row in result: - iname = row[0] - node = row[1] - ToStdout("Will relocate instance %s to node %s", iname, node) - op = opcodes.OpInstanceReplaceDisks(instance_name=iname, - remote_node=node, disks=[], - mode=constants.REPLACE_DISK_CHG, - early_release=opts.early_release) - jex.QueueJob(iname, op) + + for (status, job_id) in result[constants.JOB_IDS_KEY]: + jex.AddJobId(None, status, job_id) + results = jex.GetResults() bad_cnt = len([row for row in results if not row[0]]) if bad_cnt == 0: - ToStdout("All %d instance(s) failed over successfully.", len(results)) + ToStdout("All instances evacuated successfully.") rcode = constants.EXIT_SUCCESS else: - ToStdout("There were errors during the failover:\n" - "%d error(s) out of %d instance(s).", bad_cnt, len(results)) + ToStdout("There were %s errors during the evacuation.", bad_cnt) rcode = constants.EXIT_FAILURE + return rcode @@ -322,8 +423,10 @@ def FailoverNode(opts, args): # these fields are static data anyway, so it doesn't matter, but # locking=True should be safer + qcl = GetClient(query=True) result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False) + qcl.Close() node, pinst = result[0] if not pinst: @@ -341,7 +444,8 @@ def FailoverNode(opts, args): jex = JobExecutor(cl=cl, opts=opts) for iname in pinst: op = opcodes.OpInstanceFailover(instance_name=iname, - ignore_consistency=opts.ignore_consistency) + ignore_consistency=opts.ignore_consistency, + iallocator=opts.iallocator) jex.QueueJob(iname, op) results = jex.GetResults() bad_cnt = len([row for row in results if not row[0]]) @@ -361,8 +465,10 @@ def MigrateNode(opts, args): force = opts.force selected_fields = ["name", "pinst_list"] + qcl = GetClient(query=True) result = cl.QueryNodes(names=args, fields=selected_fields, use_locking=False) - node, pinst = result[0] + qcl.Close() + ((node, pinst), ) = result if not pinst: ToStdout("No primary instances on node %s, exiting." % node) @@ -370,9 +476,10 @@ def MigrateNode(opts, args): pinst = utils.NiceSort(pinst) - if not force and not AskUser("Migrate instance(s) %s?" % - (",".join("'%s'" % name for name in pinst))): - return 2 + if not (force or + AskUser("Migrate instance(s) %s?" % + utils.CommaJoin(utils.NiceSort(pinst)))): + return constants.EXIT_CONFIRMATION # this should be removed once --non-live is deprecated if not opts.live and opts.migration_mode is not None: @@ -383,8 +490,31 @@ def MigrateNode(opts, args): mode = constants.HT_MIGRATION_NONLIVE else: mode = opts.migration_mode - op = opcodes.OpNodeMigrate(node_name=args[0], mode=mode) - SubmitOpCode(op, cl=cl, opts=opts) + + op = opcodes.OpNodeMigrate(node_name=args[0], mode=mode, + iallocator=opts.iallocator, + target_node=opts.dst_node, + allow_runtime_changes=opts.allow_runtime_chgs, + ignore_ipolicy=opts.ignore_ipolicy) + + result = SubmitOrSend(op, opts, cl=cl) + + # Keep track of submitted jobs + jex = JobExecutor(cl=cl, opts=opts) + + for (status, job_id) in result[constants.JOB_IDS_KEY]: + jex.AddJobId(None, status, job_id) + + results = jex.GetResults() + bad_cnt = len([row for row in results if not row[0]]) + if bad_cnt == 0: + ToStdout("All instances migrated successfully.") + rcode = constants.EXIT_SUCCESS + else: + ToStdout("There were %s errors during the node migration.", bad_cnt) + rcode = constants.EXIT_FAILURE + + return rcode def ShowNodeConfig(opts, args): @@ -399,7 +529,7 @@ def ShowNodeConfig(opts, args): @return: the desired exit code """ - cl = GetClient() + cl = GetClient(query=True) result = cl.QueryNodes(fields=["name", "pip", "sip", "pinst_list", "sinst_list", "master_candidate", "drained", "offline", @@ -474,7 +604,7 @@ def PowercycleNode(opts, args): return 2 op = opcodes.OpNodePowercycle(node_name=node, force=opts.force) - result = SubmitOpCode(op, opts=opts) + result = SubmitOrSend(op, opts) if result: ToStderr(result) return 0 @@ -523,7 +653,8 @@ def PowerNode(opts, args): opcodelist.append(opcodes.OpOobCommand(node_names=args, command=oob_command, ignore_status=opts.ignore_status, - timeout=opts.oob_timeout)) + timeout=opts.oob_timeout, + power_delay=opts.power_delay)) cli.SetGenericOpcodeOpts(opcodelist, opts) @@ -551,7 +682,7 @@ def PowerNode(opts, args): data.append([node_name, "invoked"]) else: errs += 1 - data.append([node_name, cli.FormatResultError(data_status)]) + data.append([node_name, cli.FormatResultError(data_status, True)]) data = GenerateTable(separator=opts.separator, headers=headers, fields=["node", "status"], data=data) @@ -597,7 +728,7 @@ def Health(opts, args): data.append(["", "%s=%s" % (item, status)]) else: errs += 1 - data.append([node_name, cli.FormatResultError(data_status)]) + data.append([node_name, cli.FormatResultError(data_status, True)]) data = GenerateTable(separator=opts.separator, headers=headers, fields=["node", "status"], data=data) @@ -735,7 +866,7 @@ def ModifyStorage(opts, args): storage_type=storage_type, name=volume_name, changes=changes) - SubmitOpCode(op, opts=opts) + SubmitOrSend(op, opts) else: ToStderr("No changes to perform, exiting.") @@ -758,7 +889,7 @@ def RepairStorage(opts, args): storage_type=storage_type, name=volume_name, ignore_consistency=opts.ignore_consistency) - SubmitOpCode(op, opts=opts) + SubmitOrSend(op, opts) def SetNodeParams(opts, args): @@ -774,10 +905,18 @@ def SetNodeParams(opts, args): all_changes = [opts.master_candidate, opts.drained, opts.offline, opts.master_capable, opts.vm_capable, opts.secondary_ip, opts.ndparams] - if all_changes.count(None) == len(all_changes): + if (all_changes.count(None) == len(all_changes) and + not (opts.hv_state or opts.disk_state)): ToStderr("Please give at least one of the parameters.") return 1 + if opts.disk_state: + disk_state = utils.FlatToDict(opts.disk_state) + else: + disk_state = {} + + hv_state = dict(opts.hv_state) + op = opcodes.OpNodeSetParams(node_name=args[0], master_candidate=opts.master_candidate, offline=opts.offline, @@ -788,7 +927,9 @@ def SetNodeParams(opts, args): force=opts.force, ndparams=opts.ndparams, auto_promote=opts.auto_promote, - powered=opts.node_powered) + powered=opts.node_powered, + hv_state=hv_state, + disk_state=disk_state) # even if here we process the result, we allow submit only result = SubmitOrSend(op, opts) @@ -800,40 +941,176 @@ def SetNodeParams(opts, args): return 0 +def RestrictedCommand(opts, args): + """Runs a remote command on node(s). + + @param opts: Command line options selected by user + @type args: list + @param args: Command line arguments + @rtype: int + @return: Exit code + + """ + cl = GetClient() + + if len(args) > 1 or opts.nodegroup: + # Expand node names + nodes = GetOnlineNodes(nodes=args[1:], cl=cl, nodegroup=opts.nodegroup) + else: + raise errors.OpPrereqError("Node group or node names must be given", + errors.ECODE_INVAL) + + op = opcodes.OpRestrictedCommand(command=args[0], nodes=nodes, + use_locking=opts.do_locking) + result = SubmitOrSend(op, opts, cl=cl) + + exit_code = constants.EXIT_SUCCESS + + for (node, (status, text)) in zip(nodes, result): + ToStdout("------------------------------------------------") + if status: + if opts.show_machine_names: + for line in text.splitlines(): + ToStdout("%s: %s", node, line) + else: + ToStdout("Node: %s", node) + ToStdout(text) + else: + exit_code = constants.EXIT_FAILURE + ToStdout(text) + + return exit_code + + +class ReplyStatus(object): + """Class holding a reply status for synchronous confd clients. + + """ + def __init__(self): + self.failure = True + self.answer = False + + +def ListDrbd(opts, args): + """Modifies a node. + + @param opts: the command line options selected by the user + @type args: list + @param args: should contain only one element, the node name + @rtype: int + @return: the desired exit code + + """ + if len(args) != 1: + ToStderr("Please give one (and only one) node.") + return constants.EXIT_FAILURE + + if not constants.ENABLE_CONFD: + ToStderr("Error: this command requires confd support, but it has not" + " been enabled at build time.") + return constants.EXIT_FAILURE + + status = ReplyStatus() + + def ListDrbdConfdCallback(reply): + """Callback for confd queries""" + if reply.type == confd_client.UPCALL_REPLY: + answer = reply.server_reply.answer + reqtype = reply.orig_request.type + if reqtype == constants.CONFD_REQ_NODE_DRBD: + if reply.server_reply.status != constants.CONFD_REPL_STATUS_OK: + ToStderr("Query gave non-ok status '%s': %s" % + (reply.server_reply.status, + reply.server_reply.answer)) + status.failure = True + return + if not confd.HTNodeDrbd(answer): + ToStderr("Invalid response from server: expected %s, got %s", + confd.HTNodeDrbd, answer) + status.failure = True + else: + status.failure = False + status.answer = answer + else: + ToStderr("Unexpected reply %s!?", reqtype) + status.failure = True + + node = args[0] + hmac = utils.ReadFile(pathutils.CONFD_HMAC_KEY) + filter_callback = confd_client.ConfdFilterCallback(ListDrbdConfdCallback) + counting_callback = confd_client.ConfdCountingCallback(filter_callback) + cf_client = confd_client.ConfdClient(hmac, [constants.IP4_ADDRESS_LOCALHOST], + counting_callback) + req = confd_client.ConfdClientRequest(type=constants.CONFD_REQ_NODE_DRBD, + query=node) + + def DoConfdRequestReply(req): + counting_callback.RegisterQuery(req.rsalt) + cf_client.SendRequest(req, async=False) + while not counting_callback.AllAnswered(): + if not cf_client.ReceiveReply(): + ToStderr("Did not receive all expected confd replies") + break + + DoConfdRequestReply(req) + + if status.failure: + return constants.EXIT_FAILURE + + fields = ["node", "minor", "instance", "disk", "role", "peer"] + if opts.no_headers: + headers = None + else: + headers = {"node": "Node", "minor": "Minor", "instance": "Instance", + "disk": "Disk", "role": "Role", "peer": "PeerNode"} + + data = GenerateTable(separator=opts.separator, headers=headers, + fields=fields, data=sorted(status.answer), + numfields=["minor"]) + for line in data: + ToStdout(line) + + return constants.EXIT_SUCCESS + + commands = { - 'add': ( + "add": ( AddNode, [ArgHost(min=1, max=1)], [SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT, NODE_FORCE_JOIN_OPT, NONODE_SETUP_OPT, VERBOSE_OPT, NODEGROUP_OPT, PRIORITY_OPT, - CAPAB_MASTER_OPT, CAPAB_VM_OPT, NODE_PARAMS_OPT], + CAPAB_MASTER_OPT, CAPAB_VM_OPT, NODE_PARAMS_OPT, HV_STATE_OPT, + DISK_STATE_OPT], "[-s ip] [--readd] [--no-ssh-key-check] [--force-join]" " [--no-node-setup] [--verbose]" " ", "Add a node to the cluster"), - 'evacuate': ( - EvacuateNode, [ArgNode(min=1)], + "evacuate": ( + EvacuateNode, ARGS_ONE_NODE, [FORCE_OPT, IALLOCATOR_OPT, NEW_SECONDARY_OPT, EARLY_RELEASE_OPT, - PRIORITY_OPT], - "[-f] {-I | -n } ", - "Relocate the secondary instances from a node" - " to other nodes (only for instances with drbd disk template)"), - 'failover': ( - FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT, PRIORITY_OPT], + PRIORITY_OPT, PRIMARY_ONLY_OPT, SECONDARY_ONLY_OPT, SUBMIT_OPT], + "[-f] {-I | -n } [-p | -s] [options...] ", + "Relocate the primary and/or secondary instances from a node"), + "failover": ( + FailoverNode, ARGS_ONE_NODE, [FORCE_OPT, IGNORE_CONSIST_OPT, + IALLOCATOR_OPT, PRIORITY_OPT], "[-f] ", "Stops the primary instances on a node and start them on their" " secondary node (only for instances with drbd disk template)"), - 'migrate': ( + "migrate": ( MigrateNode, ARGS_ONE_NODE, - [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, PRIORITY_OPT], + [FORCE_OPT, NONLIVE_OPT, MIGRATION_MODE_OPT, DST_NODE_OPT, + IALLOCATOR_OPT, PRIORITY_OPT, IGNORE_IPOLICY_OPT, + NORUNTIME_CHGS_OPT, SUBMIT_OPT], "[-f] ", "Migrate all the primary instance on a node away from it" " (only for instances of type drbd)"), - 'info': ( + "info": ( ShowNodeConfig, ARGS_MANY_NODES, [], "[...]", "Show information about the node(s)"), - 'list': ( + "list": ( ListNodes, ARGS_MANY_NODES, - [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT], + [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT, + FORCE_FILTER_OPT], "[nodes...]", "Lists the nodes in the cluster. The available fields can be shown using" " the \"list-fields\" command (see the man page for details)." @@ -844,70 +1121,87 @@ commands = { [NOHDR_OPT, SEP_OPT], "[fields...]", "Lists all available fields for nodes"), - 'modify': ( + "modify": ( SetNodeParams, ARGS_ONE_NODE, [FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT, CAPAB_MASTER_OPT, CAPAB_VM_OPT, SECONDARY_IP_OPT, AUTO_PROMOTE_OPT, DRY_RUN_OPT, PRIORITY_OPT, NODE_PARAMS_OPT, - NODE_POWERED_OPT], + NODE_POWERED_OPT, HV_STATE_OPT, DISK_STATE_OPT], "", "Alters the parameters of a node"), - 'powercycle': ( + "powercycle": ( PowercycleNode, ARGS_ONE_NODE, - [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT], + [FORCE_OPT, CONFIRM_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT], "", "Tries to forcefully powercycle a node"), - 'power': ( + "power": ( PowerNode, [ArgChoice(min=1, max=1, choices=_LIST_POWER_COMMANDS), ArgNode()], [SUBMIT_OPT, AUTO_PROMOTE_OPT, PRIORITY_OPT, IGNORE_STATUS_OPT, - FORCE_OPT, NOHDR_OPT, SEP_OPT, OOB_TIMEOUT_OPT], + FORCE_OPT, NOHDR_OPT, SEP_OPT, OOB_TIMEOUT_OPT, POWER_DELAY_OPT], "on|off|cycle|status [nodes...]", "Change power state of node by calling out-of-band helper."), - 'remove': ( + "remove": ( RemoveNode, ARGS_ONE_NODE, [DRY_RUN_OPT, PRIORITY_OPT], "", "Removes a node from the cluster"), - 'volumes': ( + "volumes": ( ListVolumes, [ArgNode()], [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, PRIORITY_OPT], "[...]", "List logical volumes on node(s)"), - 'list-storage': ( + "list-storage": ( ListStorage, ARGS_MANY_NODES, [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, _STORAGE_TYPE_OPT, PRIORITY_OPT], "[...]", "List physical volumes on node(s). The available" " fields are (see the man page for details): %s." % (utils.CommaJoin(_LIST_STOR_HEADERS))), - 'modify-storage': ( + "modify-storage": ( ModifyStorage, [ArgNode(min=1, max=1), ArgChoice(min=1, max=1, choices=_MODIFIABLE_STORAGE_TYPES), ArgFile(min=1, max=1)], - [ALLOCATABLE_OPT, DRY_RUN_OPT, PRIORITY_OPT], + [ALLOCATABLE_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT], " ", "Modify storage volume on a node"), - 'repair-storage': ( + "repair-storage": ( RepairStorage, [ArgNode(min=1, max=1), ArgChoice(min=1, max=1, choices=_REPAIRABLE_STORAGE_TYPES), ArgFile(min=1, max=1)], - [IGNORE_CONSIST_OPT, DRY_RUN_OPT, PRIORITY_OPT], + [IGNORE_CONSIST_OPT, DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT], " ", "Repairs a storage volume on a node"), - 'list-tags': ( + "list-tags": ( ListTags, ARGS_ONE_NODE, [], "", "List the tags of the given node"), - 'add-tags': ( - AddTags, [ArgNode(min=1, max=1), ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT], + "add-tags": ( + AddTags, [ArgNode(min=1, max=1), ArgUnknown()], + [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT], " tag...", "Add tags to the given node"), - 'remove-tags': ( + "remove-tags": ( RemoveTags, [ArgNode(min=1, max=1), ArgUnknown()], - [TAG_SRC_OPT, PRIORITY_OPT], + [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT], " tag...", "Remove tags from the given node"), "health": ( Health, ARGS_MANY_NODES, - [NOHDR_OPT, SEP_OPT, SUBMIT_OPT, PRIORITY_OPT, OOB_TIMEOUT_OPT], + [NOHDR_OPT, SEP_OPT, PRIORITY_OPT, OOB_TIMEOUT_OPT], "[...]", "List health of node(s) using out-of-band"), + "list-drbd": ( + ListDrbd, ARGS_ONE_NODE, + [NOHDR_OPT, SEP_OPT], + "[]", "Query the list of used DRBD minors on the given node"), + "restricted-command": ( + RestrictedCommand, [ArgUnknown(min=1, max=1)] + ARGS_MANY_NODES, + [SYNC_OPT, PRIORITY_OPT, SUBMIT_OPT, SHOW_MACHINE_OPT, NODEGROUP_OPT], + " [...]", + "Executes a restricted command on node(s)"), + } + +#: dictionary with aliases for commands +aliases = { + "show": "info", } def Main(): - return GenericMain(commands, override={"tag_type": constants.TAG_NODE}) + return GenericMain(commands, aliases=aliases, + override={"tag_type": constants.TAG_NODE}, + env_override=_ENV_OVERRIDE)