fence_xvm/fence_virt: Add support for the validate-all status op

Add support for the validate-all status operation. In this mode,
the fence agent will validate the arguments given on either the
command line or standard input. If validation succeeds, it will
exit with code 0, otherwise it will exit with code 1.

Resolves: rhbz#1447700
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
This commit is contained in:
Ryan McCabe 2017-05-03 23:22:34 -04:00
parent 53cb4ec362
commit 286e0c61e4
4 changed files with 27 additions and 15 deletions

View File

@ -114,13 +114,17 @@ main(int argc, char **argv)
}
if (args.flags & F_ERR) {
args_usage(argv[0], my_options, (argc == 1));
if (args.op != FENCE_VALIDATEALL)
args_usage(argv[0], my_options, (argc == 1));
exit(1);
}
if (args.op == FENCE_VALIDATEALL)
exit(0);
if (args.op == FENCE_METADATA) {
args_metadata(argv[0], my_options);
return 0;
exit(0);
}
if (args.delay > 0 &&
@ -186,5 +190,5 @@ main(int argc, char **argv)
out:
closelog();
return ret;
exit(ret);
}

View File

@ -255,6 +255,8 @@ assign_op(fence_virt_args_t *args, struct arg_info *arg, char *value)
args->op = FENCE_HOSTLIST;
} else if (!strcasecmp(value, "metadata")) {
args->op = FENCE_METADATA;
} else if (!strcasecmp(value, "validate-all")) {
args->op = FENCE_VALIDATEALL;
} else {
printf("Unsupported operation: %s\n", value);
args->flags |= F_ERR;
@ -490,12 +492,12 @@ static struct arg_info _arg_info[] = {
{ '\xff', NULL, "option",
/* Deprecated */
0, "string", "reboot",
"Fencing option (null, off, on, [reboot], status, list, monitor, metadata)",
"Fencing option (null, off, on, [reboot], status, list, list-status, monitor, validate-all, metadata)",
assign_op },
{ 'o', "-o <operation>", "action",
0, "string", "reboot",
"Fencing action (null, off, on, [reboot], status, list, monitor, metadata)",
"Fencing action (null, off, on, [reboot], status, list, list-status, monitor, validate-all, metadata)",
assign_op },
{ 'H', "-H <domain>", "port",
@ -801,6 +803,7 @@ args_metadata(char *progname, const char *optstr)
printf("\t<action name=\"monitor\" />\n");
printf("\t<action name=\"list\" />\n");
printf("\t<action name=\"list-status\" />\n");
printf("\t<action name=\"validate-all\" />\n");
printf("</actions>\n");
printf("</resource-agent>\n");
}

View File

@ -52,14 +52,15 @@ typedef enum {
#define DEFAULT_AUTH AUTH_SHA256
typedef enum {
FENCE_NULL = 0x0,
FENCE_OFF = 0x1, /* Turn the VM off */
FENCE_REBOOT = 0x2, /* Hit the reset button */
FENCE_ON = 0x3, /* Turn the VM on */
FENCE_STATUS = 0x4, /* virtual machine status (off/on) */
FENCE_DEVSTATUS = 0x5, /* Status of the fencing device */
FENCE_HOSTLIST = 0x6, /* List VMs controllable */
FENCE_METADATA = 0x7
FENCE_NULL = 0x0,
FENCE_OFF = 0x1, /* Turn the VM off */
FENCE_REBOOT = 0x2, /* Hit the reset button */
FENCE_ON = 0x3, /* Turn the VM on */
FENCE_STATUS = 0x4, /* virtual machine status (off/on) */
FENCE_DEVSTATUS = 0x5, /* Status of the fencing device */
FENCE_HOSTLIST = 0x6, /* List VMs controllable */
FENCE_METADATA = 0x7, /* Print fence agent metadata */
FENCE_VALIDATEALL = 0x8 /* Validate command-line or stdin arguments and exit */
} fence_cmd_t;
#define DEFAULT_TTL 4

View File

@ -37,7 +37,7 @@ Virtual machine (domain UUID or name) to fence
.TP
.B -o
.
Fencing action (null, off, on, reboot, status, monitor, list, list-status, or metadata) (Default Value: reboot). See the FENCING ACTIONS section.
Fencing action (null, off, on, reboot, status, monitor, list, list-status, validate-all, or metadata) (Default Value: reboot). See the FENCING ACTIONS section.
.TP
.B -t
@ -145,7 +145,7 @@ Virtual machine (domain UUID or name) to fence
.TP
.B action
.
Fencing action (null, off, on, reboot, status, monitor, list, or metadata) (Default Value: reboot). See the FENCING ACTIONS section.
Fencing action (null, off, on, reboot, status, monitor, list, list-status, validate-all, or metadata) (Default Value: reboot). See the FENCING ACTIONS section.
.TP
.B timeout
@ -254,6 +254,10 @@ Check the health of fence_virtd's backend plugin.
List virtual machines which may be fenced by fence_virtd (not supported
on all backends).
.TP
\fBvalidate-all\fP
Validate arguments given on either the command line or standard input. If validation fails, the fence agent will exit with code 1, otherwise it will exit with code 0.
.TP
\fBmetadata \fP
Print XML metadata to standard output.