]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: add net-info command
authorOsier Yang <jyang@redhat.com>
Tue, 16 Nov 2010 07:48:47 +0000 (15:48 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 16 Nov 2010 16:18:06 +0000 (09:18 -0700)
To list basic information about the network.

* tools/virsh.c
* tools/virsh.pod

tools/virsh.c
tools/virsh.pod

index d15a8df74249e2ab0794c0ec20f495f93900141f..3a74053c9d602c77aad73ea23429686030a5b9f9 100644 (file)
@@ -3678,6 +3678,64 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "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;
+}
 
 /*
  * "iface-edit" command
@@ -9879,6 +9937,7 @@ static const vshCmdDef commands[] = {
     {"net-destroy", cmdNetworkDestroy, opts_network_destroy, info_network_destroy},
     {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml, info_network_dumpxml},
     {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit},
+    {"net-info", cmdNetworkInfo, opts_network_info, info_network_info},
     {"net-list", cmdNetworkList, opts_network_list, info_network_list},
     {"net-name", cmdNetworkName, opts_network_name, info_network_name},
     {"net-start", cmdNetworkStart, opts_network_start, info_network_start},
index b21e916772288f15e12d99a93724a9cd4d7801ea..80322562534cceafaceda43a9ffd1d94a15bd95e 100644 (file)
@@ -743,6 +743,10 @@ except that it does some error checking.
 The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
 variables, and defaults to C<vi>.
 
+=item B<net-info> I<network>
+
+Returns basic information about the I<network> object.
+
 =item B<net-list> optional I<--inactive> or I<--all>
 
 Returns the list of active networks, if I<--all> is specified this will also