[libvirt] [PATCH 7/7] virsh: add 'guestinfo' command

Jonathon Jongsma jjongsma at redhat.com
Thu Aug 1 13:37:10 UTC 2019


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 | 53 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e79dc75342..83249768ad 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -14038,6 +14038,53 @@ 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 = NULL}
+};
+
+static bool
+cmdGuestInfo(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    bool ret = false;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    int i;
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (virDomainGetGuestInfo(dom, 0, &params, &nparams, 0) < 0)
+        goto cleanup;
+
+    for (i = 0; i < nparams; i++) {
+        char *str = vshGetTypedParamValue(ctl, &params[i]);
+        vshPrint(ctl, "%-20s: %s\n", params[i].field, str);
+        VIR_FREE(str);
+    }
+
+    ret = true;
+
+cleanup:
+    virshDomainFree(dom);
+    return ret;
+}
+
 const vshCmdDef domManagementCmds[] = {
     {.name = "attach-device",
      .handler = cmdAttachDevice,
@@ -14653,5 +14700,11 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_domblkthreshold,
      .flags = 0
     },
+    {.name = "guestinfo",
+     .handler = cmdGuestInfo,
+     .opts = opts_guestinfo,
+     .info = info_guestinfo,
+     .flags = 0
+    },
     {.name = NULL}
 };
-- 
2.21.0




More information about the libvir-list mailing list