[libvirt] [PATCH] [RESEND] To list basic information about the network.

* tools/virsh.c --- tools/virsh.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/virsh.c diff --git a/tools/virsh.c b/tools/virsh.c old mode 100644 new mode 100755 index d15a8df..3a74053 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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}, -- 1.7.3.2

On Tue, Nov 16, 2010 at 03:48:47PM +0800, Osier Yang wrote:
* tools/virsh.c --- tools/virsh.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/virsh.c
diff --git a/tools/virsh.c b/tools/virsh.c old mode 100644 new mode 100755 index d15a8df..3a74053 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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},
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On 11/16/2010 06:14 AM, Daniel P. Berrange wrote:
On Tue, Nov 16, 2010 at 03:48:47PM +0800, Osier Yang wrote:
* tools/virsh.c --- tools/virsh.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/virsh.c
The mode change is bogus. I've fixed it, but you may want to figure out how you accidentally marked it as executable in the first place.
ACK
Pushed, after squashing in some documentation: diff --git i/tools/virsh.pod w/tools/virsh.pod index b21e916..8032256 100644 --- i/tools/virsh.pod +++ w/tools/virsh.pod @@ -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 -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

于 2010年11月17日 00:18, Eric Blake 写道:
On 11/16/2010 06:14 AM, Daniel P. Berrange wrote:
On Tue, Nov 16, 2010 at 03:48:47PM +0800, Osier Yang wrote:
* tools/virsh.c --- tools/virsh.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/virsh.c
The mode change is bogus. I've fixed it, but you may want to figure out how you accidentally marked it as executable in the first place.
urgh, it should by my carelessly "chmod".
ACK
Pushed, after squashing in some documentation:
forgot to update the docs, thanks :-) - Osier
diff --git i/tools/virsh.pod w/tools/virsh.pod index b21e916..8032256 100644 --- i/tools/virsh.pod +++ w/tools/virsh.pod @@ -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

Hey Osier, Do you have a few minutes to write up the "net-info" command, for the virsh Command Reference? You don't need to do it in DocBook or anything, just standard text is fine. I can convert it into the DocBook format we're using fairly quickly now. :) Regards and best wishes, Justin Clift

于 2010年11月17日 01:49, Justin Clift 写道:
Hey Osier,
Do you have a few minutes to write up the "net-info" command, for the virsh Command Reference?
You don't need to do it in DocBook or anything, just standard text is fine. I can convert it into the DocBook format we're using fairly quickly now. :)
yep, sure, will send it in another mail thread if I finished. Regards - Osier
Regards and best wishes,
Justin Clift
participants (4)
-
Daniel P. Berrange
-
Eric Blake
-
Justin Clift
-
Osier Yang