[PATCH 3/5] virsh: add command 'guestusers' implementing VirDomainGetGuestUsers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 tools/virsh-domain.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod      |  4 +++
 2 files changed, 80 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 828ae30789..b964608987 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -14030,6 +14030,76 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "guestusers" command
+ */
+static const vshCmdInfo info_guestusers[] = {
+    {.name = "help",
+     .data = N_("query the users logged on in the guest (via agent)")
+    },
+    {.name = "desc",
+     .data = N_("Use the guest agent to query the list of logged in users from guest's "
+                "point of view")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_guestusers[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
+    {.name = NULL}
+};
+
+static bool
+cmdGuestusers(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    virDomainUserInfoPtr *userinfo = NULL;
+    int ninfo = 0;
+    size_t i;
+    bool ret = false;
+    vshTablePtr table = NULL;
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if ((ninfo = virDomainGetGuestUsers(dom, &userinfo, 0)) < 0)
+        goto cleanup;
+
+    if (userinfo != NULL) {
+        table = vshTableNew(_("User"), _("Domain"), _("Login Time"),  NULL);
+        if (!table)
+            goto cleanup;
+
+        for (i = 0; i < ninfo; i++) {
+            VIR_AUTOFREE(char *) loginstr = virTimeStringThen(userinfo[i]->loginTime);
+            if (loginstr == NULL)
+                goto cleanup;
+
+            if (vshTableRowAppend(table,
+                                  userinfo[i]->user,
+                                  userinfo[i]->domain ? userinfo[i]->domain : "",
+                                  loginstr,
+                                  NULL) < 0)
+                goto cleanup;
+        }
+
+        vshTablePrintToStdout(table, ctl);
+    } else {
+        vshPrintExtra(ctl, _("No active users in the domain"));
+    }
+
+    ret = true;
+
+cleanup:
+    if (ninfo >= 0) {
+        for (i = 0; i < ninfo; i++)
+            virDomainUserInfoFree(userinfo[i]);
+    }
+    VIR_FREE(userinfo);
+    virshDomainFree(dom);
+    return ret;
+}
+
 const vshCmdDef domManagementCmds[] = {
     {.name = "attach-device",
      .handler = cmdAttachDevice,
@@ -14645,5 +14715,11 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_domblkthreshold,
      .flags = 0
     },
+    {.name = "guestusers",
+     .handler = cmdGuestusers,
+     .opts = opts_guestusers,
+     .info = info_guestusers,
+     .flags = 0
+    },
     {.name = NULL}
 };
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 5168fa96b6..59cf3d5857 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3072,6 +3072,10 @@ provided too. The desired operation is then executed on the domain.
 
 See B<vcpupin> for information on I<cpulist>.
 
+=item B<guestusers> I<domain>
+
+Query the list of logged in users from guest's point of view using the guest agent.
+
 =item B<vncdisplay> I<domain>
 
 Output the IP address and port number for the VNC display. If the information
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux