[PATCH v3 6/6] virt-admin: Introduce cmdSrvList

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

 



Since we introduced listing API earlier in these series, it's time
to wire up the API to the virt-admin client.
---
 tools/virt-admin.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 1372963..d54087a 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -300,6 +300,57 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
     return !!priv->conn;
 }
 
+
+/* ---------------
+ * Command Srv-list
+ * ---------------
+ */
+
+static const vshCmdInfo info_srv_list[] = {
+    {.name = "help",
+     .data = N_("list available servers on a daemon")
+    },
+    {.name = "desc",
+     .data = N_("List all manageable servers on a daemon.")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    int nsrvs = 0;
+    size_t i;
+    bool ret = false;
+    const char *uri = NULL;
+    virAdmServerPtr *srvs = NULL;
+    vshAdmControlPtr priv = ctl->privData;
+
+    /* Obtain a list of available servers on the daemon */
+    if ((nsrvs = virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) {
+        uri = virAdmConnectGetURI(priv->conn);
+        vshError(ctl, _("failed to obtain list of available servers from %s"),
+                 NULLSTR(uri));
+        goto cleanup;
+    }
+
+    printf(" %-5s %-15s\n", "Id", "Name");
+    printf("---------------\n");
+    for (i = 0; i < nsrvs; i++)
+        vshPrint(ctl, " %-5zu %-15s\n", i, virAdmGetServerName(srvs[i]));
+
+    ret = true;
+ cleanup:
+    if (srvs) {
+        for (i = 0; i < nsrvs; i++)
+            virAdmServerFree(srvs[i]);
+        VIR_FREE(srvs);
+    }
+
+    return ret;
+}
+
+
 static void *
 vshAdmConnectionHandler(vshControl *ctl)
 {
@@ -592,8 +643,19 @@ static const vshCmdDef vshAdmCmds[] = {
     {.name = NULL}
 };
 
+static const vshCmdDef monitoringCmds[] = {
+    {.name = "srv-list",
+     .handler = cmdSrvList,
+     .opts = NULL,
+     .info = info_srv_list,
+     .flags = 0
+    },
+    {.name = NULL}
+};
+
 static const vshCmdGrp cmdGroups[] = {
     {"Virt-admin itself", "virt-admin", vshAdmCmds},
+    {"Monitoring commands", "monitor", monitoringCmds},
     {NULL, NULL, NULL}
 };
 
-- 
2.4.3

--
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]