[libvirt] [RFC PATCH 5/5] Implement virsh monitor-command
Daniel P. Berrange
berrange at redhat.com
Fri Apr 16 11:31:45 UTC 2010
On Tue, Apr 13, 2010 at 02:36:50PM -0400, Chris Lalancette wrote:
> Signed-off-by: Chris Lalancette <clalance at redhat.com>
> ---
> tools/Makefile.am | 1 +
> tools/virsh.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/tools/Makefile.am b/tools/Makefile.am
> index 33a3216..b1c2691 100644
> --- a/tools/Makefile.am
> +++ b/tools/Makefile.am
> @@ -39,6 +39,7 @@ virsh_LDADD = \
> $(STATIC_BINARIES) \
> $(WARN_CFLAGS) \
> ../src/libvirt.la \
> + ../src/libvirt_qemu.la \
> ../gnulib/lib/libgnu.la \
> $(VIRSH_LIBS)
> virsh_CFLAGS = \
> diff --git a/tools/virsh.c b/tools/virsh.c
> index d5fe6c4..9511646 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -8627,6 +8627,70 @@ cleanup:
> }
>
> /*
> + * "monitor-command" command
> + */
> +static const vshCmdInfo info_monitor_command[] = {
> + {"help", N_("Monitor Command")},
> + {"desc", N_("Monitor Command")},
> + {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_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
> +cmdMonitorCommand(vshControl *ctl, const vshCmd *cmd)
> +{
> + virDomainPtr dom = NULL;
> + int ret = FALSE;
> + char *monitor_cmd;
> + char *result = NULL;
> + int i;
> +
> + if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
> + 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;
> + }
> +
> + /* FIXME: HACK! For the time being I convert all ^ to space so
> + * that the virsh argument parsing doesn't screw us up. We should
> + * fix the argument parsing
> + */
> + i = 0;
> + while (monitor_cmd[i] != '\0') {
> + if (monitor_cmd[i] == '^')
> + monitor_cmd[i] = ' ';
> + i++;
> + }
> +
> + if (virQemuMonitorCommand(dom, monitor_cmd, &result, 0) < 0)
> + goto cleanup;
> +
> + fprintf(stdout, "%s\n", result);
> +
> + ret = TRUE;
> +
> +cleanup:
> + VIR_FREE(result);
> + if (dom)
> + virDomainFree(dom);
> +
> + return ret;
> +}
> +
> +
> +/*
> * Commands
> */
> static const vshCmdDef commands[] = {
> @@ -8788,6 +8852,8 @@ static const vshCmdDef commands[] = {
> {"snapshot-list", cmdSnapshotList, opts_snapshot_list, info_snapshot_list},
> {"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert, info_snapshot_revert},
>
> + {"monitor-command", cmdMonitorCommand, opts_monitor_command, info_monitor_command},
Add a 'qemu-' prefix on this one.
Regards,
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
More information about the libvir-list
mailing list