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

[libvirt] [PATCH] virsh: add command net-info



To list basic information about the network.

* tools/virsh.c
---
 tools/virsh.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index e704799..54643f2 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -4088,6 +4088,64 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
     return TRUE;
 }

+/*
+ * "net-info" command
+ */
+static const vshCmdInfo info_network_info[] = {
+    {"help", N_("network information")},
+    {"desc", "Returns basic information about the network"},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_network_info[] = {
+    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, N_("network name")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
+{
+    virNetworkPtr network;
+    char uuid[VIR_UUID_STRING_BUFLEN];
+    int autostart;
+    int persistent = -1;
+    int active = -1;
+    char *bridge = NULL;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return FALSE;
+
+    if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
+                                           VSH_BYNAME)))
+        return FALSE;
+
+    vshPrint(ctl, "%-15s %s\n", _("Name"), virNetworkGetName(network));
+
+    if (virNetworkGetUUIDString(network, uuid) == 0)
+        vshPrint(ctl, "%-15s %s\n", _("UUID"), uuid);
+
+    active = virNetworkIsActive(network);
+    if (active >= 0)
+        vshPrint(ctl, "%-15s %s\n", _("Active:"), active? _("yes") : _("no"));
+
+    persistent = virNetworkIsPersistent(network);
+    if (persistent < 0)
+        vshPrint(ctl, "%-15s %s\n", _("Persistent:"), _("unknown"));
+    else
+        vshPrint(ctl, "%-15s %s\n", _("Persistent:"), persistent ? _("yes") : _("no"));
+
+    if (virNetworkGetAutostart(network, &autostart) < 0)
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+    else
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
+
+    bridge = virNetworkGetBridgeName(network);
+    if (bridge)
+        vshPrint(ctl, "%-15s %s\n", _("Bridge:"), bridge);
+
+    virNetworkFree(network);
+    return TRUE;
+}

 /**************************************************************************/
 /*
@@ -9924,6 +9982,7 @@ static const vshCmdDef commands[] = {
     {"net-start", cmdNetworkStart, opts_network_start, info_network_start},
     {"net-undefine", cmdNetworkUndefine, opts_network_undefine, info_network_undefine},
     {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid},
+    {"net-info", cmdNetworkInfo, opts_network_info, info_network_info},

     {"iface-list", cmdInterfaceList, opts_interface_list, info_interface_list},
     {"iface-name", cmdInterfaceName, opts_interface_name, info_interface_name},
--
1.7.2.3


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