[libvirt] [PATCH v4 3/4] virsh: add 'guestinfo' command
Michal Privoznik
mprivozn at redhat.com
Thu Aug 29 10:04:10 UTC 2019
On 8/27/19 10:35 PM, Jonathon Jongsma wrote:
> The 'guestinfo' command uses the new virDomainGetGuestInfo() API to
> query information about the specified domain and print it out for the
> user. The output is modeled roughly on the 'domstats' command.
>
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
> ---
> tools/virsh-domain.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
> tools/virsh.pod | 64 +++++++++++++++++++++++++++++++++
> 2 files changed, 149 insertions(+)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 8984c2f3b4..533df4c813 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -14051,6 +14051,85 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
> return ret;
> }
>
> +/*
> + * "guestinfo" command
> + */
> +static const vshCmdInfo info_guestinfo[] = {
> + {.name = "help",
> + .data = N_("query information about the guest (via agent)")
> + },
> + {.name = "desc",
> + .data = N_("Use the guest agent to query various information from guest's "
> + "point of view")
> + },
> + {.name = NULL}
> +};
> +
> +static const vshCmdOptDef opts_guestinfo[] = {
> + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
> + {.name = "user",
> + .type = VSH_OT_BOOL,
> + .help = N_("report active users"),
> + },
> + {.name = "os",
> + .type = VSH_OT_BOOL,
> + .help = N_("report operating system information"),
> + },
> + {.name = "timezone",
> + .type = VSH_OT_BOOL,
> + .help = N_("report timezone information"),
> + },
> + {.name = "hostname",
> + .type = VSH_OT_BOOL,
> + .help = N_("report hostname"),
> + },
> + {.name = "filesystem",
> + .type = VSH_OT_BOOL,
> + .help = N_("report filesystem information"),
> + },
> + {.name = NULL}
> +};
> +
> +static bool
> +cmdGuestInfo(vshControl *ctl, const vshCmd *cmd)
> +{
> + virDomainPtr dom;
> + bool ret = false;
> + virTypedParameterPtr params = NULL;
> + int nparams = 0;
> + size_t i;
> + unsigned int types = 0;
> +
> + if (vshCommandOptBool(cmd, "user"))
> + types |= VIR_DOMAIN_GUEST_INFO_USERS;
> + if (vshCommandOptBool(cmd, "os"))
> + types |= VIR_DOMAIN_GUEST_INFO_OS;
> + if (vshCommandOptBool(cmd, "timezone"))
> + types |= VIR_DOMAIN_GUEST_INFO_TIMEZONE;
> + if (vshCommandOptBool(cmd, "hostname"))
> + types |= VIR_DOMAIN_GUEST_INFO_HOSTNAME;
> + if (vshCommandOptBool(cmd, "filesystem"))
> + types |= VIR_DOMAIN_GUEST_INFO_FILESYSTEM;
> +
> + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
> + return false;
> +
> + if (virDomainGetGuestInfo(dom, types, ¶ms, &nparams, 0) < 0)
> + goto cleanup;
> +
> + for (i = 0; i < nparams; i++) {
> + char *str = vshGetTypedParamValue(ctl, ¶ms[i]);
> + vshPrint(ctl, "%-20s: %s\n", params[i].field, str);
> + VIR_FREE(str);
> + }
> +
> + ret = true;
> +
> + cleanup:
As I've pointed out in my review in v3, this leaks @params.
> + virshDomainFree(dom);
> + return ret;
> +}
> +
> const vshCmdDef domManagementCmds[] = {
> {.name = "attach-device",
> .handler = cmdAttachDevice,
> @@ -14666,5 +14745,11 @@ const vshCmdDef domManagementCmds[] = {
> .info = info_domblkthreshold,
> .flags = 0
> },
> + {.name = "guestinfo",
> + .handler = cmdGuestInfo,
> + .opts = opts_guestinfo,
> + .info = info_guestinfo,
> + .flags = 0
> + },
> {.name = NULL}
> };
Reviewed-by: Michal Privoznik <mprivozn at redhat.com>
Michal
More information about the libvir-list
mailing list