---
tools/virsh-domain-monitor.c | 93 ++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 10 +++++
2 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 151a8d0..fb6fe23 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1683,6 +1683,98 @@ cleanup:
}
#undef FILTER
+/* "domifaddr" command
+ */
+static const vshCmdInfo info_domifaddr[] = {
+ {"help", N_("get network interfaces addresses for a domain")},
+ {"desc", N_("Get network interfaces addresses for a running
domain")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_domifaddr[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"interface", VSH_OT_DATA, VSH_OFLAG_NONE, N_("network interface
name")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom = NULL;
+ const char *device = NULL;
+ virDomainInterfacePtr ifaces = NULL;
+ int i, j, ifaces_count = 0;
+ unsigned int flags = 0;
+ bool ret = false;
+
+ if (!vshConnectionUsability(ctl, ctl->conn))
+ return false;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (vshCommandOptString(cmd, "interface", &device) < 0) {
+ goto cleanup;
+ }
+
+ ifaces_count = virDomainInterfacesAddresses(dom, &ifaces, flags);
+ if (ifaces_count < 0) {
+ vshError(ctl, _("Failed to query for interfaces addresses"));
+ goto cleanup;
+ }
+
+ vshPrintExtra(ctl, " %-10s %-17s %s\n%s\n",
+ _("Name"), _("HW address"), _("IP
address"),
+ "---------------------------------------------------");
+
+ for (i = 0; i < ifaces_count; i++) {
+ virDomainInterfacePtr iface = &(ifaces[i]);
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ const char *hwaddr = "";
+ const char *ip_addr_str = NULL;
+
+ if (device && STRNEQ(device, iface->name))
+ continue;
+
+ if (iface->hwaddr)
+ hwaddr = iface->hwaddr;
+
+ for (j = 0; j < iface->ip_addrs_count; j++) {
+ if (j)
+ virBufferAddChar(&buf, ' ');
+ virBufferAsprintf(&buf, "%s/%d",
+ iface->ip_addrs[j].addr,
+ iface->ip_addrs[j].prefix);
+ }
+
+ ip_addr_str = virBufferContentAndReset(&buf);
+
+ if (!ip_addr_str)
+ ip_addr_str = "";
+
+ vshPrintExtra(ctl, " %-10s %-17s %s\n",
+ iface->name, hwaddr, ip_addr_str);
+
+ virBufferFreeAndReset(&buf);
+ }
+
+ ret = true;
+
+cleanup:
+ for (i = 0; i < ifaces_count; i++) {
+ VIR_FREE(ifaces[i].name);
+ VIR_FREE(ifaces[i].hwaddr);
+ for (j = 0; j < ifaces[i].ip_addrs_count; j++)
+ VIR_FREE(ifaces[i].ip_addrs[j].addr);
+ VIR_FREE(ifaces[i].ip_addrs);
+ }
+ VIR_FREE(ifaces);
+
+ if (dom)
+ virDomainFree(dom);
+ return ret;
+}
+
static const vshCmdDef domMonitoringCmds[] = {
{"domblkerror", cmdDomBlkError, opts_domblkerror, info_domblkerror, 0},
{"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
@@ -1690,6 +1782,7 @@ static const vshCmdDef domMonitoringCmds[] = {
{"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
{"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0},
{"domif-getlink", cmdDomIfGetLink, opts_domif_getlink, info_domif_getlink,
0},
+ {"domifaddr", cmdDomIfAddr, opts_domifaddr, info_domifaddr, 0},
{"domiflist", cmdDomiflist, opts_domiflist, info_domiflist, 0},
{"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
{"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 35613c4..daf5889 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -605,6 +605,16 @@ B<Explanation of fields> (fields appear in the folowing
order):
flush_total_times - total time flush operations took (ns)
<-- other fields provided by hypervisor -->
+=item B<domifaddr> I<domain> [I<interface-device>]
+
+Get a list of interfaces of domain among with their IP and hardware
+addresses, or if I<interface-device> is specified limit output just
+for that one interface. Note, that interface name can be driver
+dependent meaning it can be name within guest OS or the name you would
+see in domain XML. Moreover, the whole command may require a guest
+agent to be configured for the queried domain under some drivers,
+notably qemu.
+
=item B<domifstat> I<domain> I<interface-device>
Get network interface stats for a running domain.
--
1.7.8.6