Revision 6d846d0e lib/client/gnt_node.py
b/lib/client/gnt_node.py | ||
---|---|---|
968 | 968 |
return 0 |
969 | 969 |
|
970 | 970 |
|
971 |
def RestrictedCommand(opts, args): |
|
972 |
"""Runs a remote command on node(s). |
|
973 |
|
|
974 |
@param opts: Command line options selected by user |
|
975 |
@type args: list |
|
976 |
@param args: Command line arguments |
|
977 |
@rtype: int |
|
978 |
@return: Exit code |
|
979 |
|
|
980 |
""" |
|
981 |
cl = GetClient() |
|
982 |
|
|
983 |
if len(args) > 1 or opts.nodegroup: |
|
984 |
# Expand node names |
|
985 |
nodes = GetOnlineNodes(nodes=args[1:], cl=cl, nodegroup=opts.nodegroup) |
|
986 |
else: |
|
987 |
raise errors.OpPrereqError("Node group or node names must be given", |
|
988 |
errors.ECODE_INVAL) |
|
989 |
|
|
990 |
op = opcodes.OpRestrictedCommand(command=args[0], nodes=nodes, |
|
991 |
use_locking=opts.do_locking) |
|
992 |
result = SubmitOrSend(op, opts, cl=cl) |
|
993 |
|
|
994 |
exit_code = constants.EXIT_SUCCESS |
|
995 |
|
|
996 |
for (node, (status, text)) in zip(nodes, result): |
|
997 |
ToStdout("------------------------------------------------") |
|
998 |
if status: |
|
999 |
if opts.show_machine_names: |
|
1000 |
for line in text.splitlines(): |
|
1001 |
ToStdout("%s: %s", node, line) |
|
1002 |
else: |
|
1003 |
ToStdout("Node: %s", node) |
|
1004 |
ToStdout(text) |
|
1005 |
else: |
|
1006 |
exit_code = constants.EXIT_FAILURE |
|
1007 |
ToStdout(text) |
|
1008 |
|
|
1009 |
return exit_code |
|
1010 |
|
|
1011 |
|
|
971 | 1012 |
class ReplyStatus(object): |
972 | 1013 |
"""Class holding a reply status for synchronous confd clients. |
973 | 1014 |
|
... | ... | |
1058 | 1099 |
|
1059 | 1100 |
return constants.EXIT_SUCCESS |
1060 | 1101 |
|
1102 |
|
|
1061 | 1103 |
commands = { |
1062 | 1104 |
"add": ( |
1063 | 1105 |
AddNode, [ArgHost(min=1, max=1)], |
... | ... | |
1173 | 1215 |
ListDrbd, ARGS_ONE_NODE, |
1174 | 1216 |
[NOHDR_OPT, SEP_OPT], |
1175 | 1217 |
"[<node_name>]", "Query the list of used DRBD minors on the given node"), |
1218 |
"restricted-command": ( |
|
1219 |
RestrictedCommand, [ArgUnknown(min=1, max=1)] + ARGS_MANY_NODES, |
|
1220 |
[SYNC_OPT, PRIORITY_OPT, SUBMIT_OPT, SHOW_MACHINE_OPT, NODEGROUP_OPT], |
|
1221 |
"<command> <node_name> [<node_name>...]", |
|
1222 |
"Executes a restricted command on node(s)"), |
|
1176 | 1223 |
} |
1177 | 1224 |
|
1178 | 1225 |
#: dictionary with aliases for commands |
Also available in: Unified diff