mirror of https://gitee.com/openkylin/libvirt.git
Implement virsh qemu-monitor-command.
Now that the virsh parsing has been revamped, we can implement qemu-monitor-command. This is basically the same as it was in previous iterations, but has now been tested to work both with the plain text monitor and the QMP monitor. Signed-off-by: Chris Lalancette <clalance@redhat.com>
This commit is contained in:
parent
a59dde7869
commit
a5b5307da2
|
@ -45,6 +45,7 @@ virsh_LDADD = \
|
||||||
$(STATIC_BINARIES) \
|
$(STATIC_BINARIES) \
|
||||||
$(WARN_CFLAGS) \
|
$(WARN_CFLAGS) \
|
||||||
../src/libvirt.la \
|
../src/libvirt.la \
|
||||||
|
../src/libvirt-qemu.la \
|
||||||
../gnulib/lib/libgnu.la \
|
../gnulib/lib/libgnu.la \
|
||||||
$(VIRSH_LIBS)
|
$(VIRSH_LIBS)
|
||||||
virsh_CFLAGS = \
|
virsh_CFLAGS = \
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "libvirt/libvirt-qemu.h"
|
||||||
|
|
||||||
static char *progname;
|
static char *progname;
|
||||||
|
|
||||||
|
@ -9807,6 +9808,58 @@ cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* "qemu-monitor-command" command
|
||||||
|
*/
|
||||||
|
static const vshCmdInfo info_qemu_monitor_command[] = {
|
||||||
|
{"help", N_("Qemu Monitor Command")},
|
||||||
|
{"desc", N_("Qemu Monitor Command")},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const vshCmdOptDef opts_qemu_monitor_command[] = {
|
||||||
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
||||||
|
{"cmd", VSH_OT_DATA, VSH_OFLAG_REQ, N_("command")},
|
||||||
|
{NULL, 0, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
|
||||||
|
{
|
||||||
|
virDomainPtr dom = NULL;
|
||||||
|
int ret = FALSE;
|
||||||
|
char *monitor_cmd;
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
||||||
|
if (dom == NULL)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
monitor_cmd = vshCommandOptString(cmd, "cmd", NULL);
|
||||||
|
if (monitor_cmd == NULL) {
|
||||||
|
vshError(ctl, "%s", _("missing monitor command"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, 0) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
printf("%s\n", result);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(result);
|
||||||
|
if (dom)
|
||||||
|
virDomainFree(dom);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Commands
|
* Commands
|
||||||
*/
|
*/
|
||||||
|
@ -9976,6 +10029,8 @@ static const vshCmdDef commands[] = {
|
||||||
{"snapshot-list", cmdSnapshotList, opts_snapshot_list, info_snapshot_list},
|
{"snapshot-list", cmdSnapshotList, opts_snapshot_list, info_snapshot_list},
|
||||||
{"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert, info_snapshot_revert},
|
{"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert, info_snapshot_revert},
|
||||||
|
|
||||||
|
{"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command},
|
||||||
|
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1138,6 +1138,22 @@ variables, and defaults to C<vi>.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
=head1 QEMU-SPECIFIC COMMANDS
|
||||||
|
|
||||||
|
NOTE: Use of the following commands is B<strongly> discouraged. They
|
||||||
|
can cause libvirt to become confused and do the wrong thing on subsequent
|
||||||
|
operations. Once you have used this command, please do not report
|
||||||
|
problems to the libvirt developers; the reports will be ignored.
|
||||||
|
|
||||||
|
=over 4
|
||||||
|
|
||||||
|
=item B<qemu-monitor-command> I<domain> I<command>
|
||||||
|
|
||||||
|
Send an arbitrary monitor command I<command> to domain I<domain> through the
|
||||||
|
qemu monitor. The results of the command will be printed on stdout.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
=head1 ENVIRONMENT
|
=head1 ENVIRONMENT
|
||||||
|
|
||||||
The following environment variables can be set to alter the behaviour
|
The following environment variables can be set to alter the behaviour
|
||||||
|
|
Loading…
Reference in New Issue