[libvirt] [PATCHv4 4/5] domifaddr: Add virsh support
Daniel P. Berrange
berrange at redhat.com
Tue Aug 27 12:50:23 UTC 2013
On Sun, Aug 25, 2013 at 04:45:44AM +0530, Nehal J Wani wrote:
> Use virDomainInterfacesAddresses in virsh
>
> tools/virsh-domain-monitor.c
> * Introduce new command : domifaddr
> virsh # domifaddr f18
> Name MAC address IPv4 address IPv6 address
> -------------------------------------------------------------------------------
> lo 00:00:00:00:00:00 127.0.0.1/8 ::1/128
> eth0 52:54:00:89:4e:97 192.168.101.130/24 fe80::5054:ff:fe89:4e97/64
> eth0:1 52:54:00:89:4e:97 192.168.101.133/24
> eth0:2 52:54:00:89:4e:97 192.168.101.132/24
> eth1 52:54:00:89:ad:35 192.168.102.142/24 fe80::5054:ff:fe89:ad35/64
> eth1:1 52:54:00:89:ad:35 192.168.102.143/24
> eth2 52:54:00:d3:39:ee 192.168.103.183/24 fe80::5054:ff:fed3:39ee/64
> eth2:0 52:54:00:d3:39:ee 192.168.103.184/24
> eth2:1 52:54:00:d3:39:ee 192.168.103.185/24
> eth3 52:54:00:fe:4c:4f 192.168.101.197/24 fe80::5054:ff:fefe:4c4f/64
> eth3:1 52:54:00:fe:4c:4f 192.168.101.198/24
This formatting of IP addrs is broken.
We should not expose interface aliases 'eth0:1', 'eth0:2', etc. If QEMU agent
is returning such names, either we should fix the agent, or strip the ":1"
suffixes in libvirt. The aliased names are an artifact of the legacy linux IP
config tools. The new 'ip' command does not use these - it just shows 'eth0'
with multiple IPv4 and multiple IPv6 addresses, which is also how libvirt/netcf
report physical device names & config.
Our display format must allow for NICs having arbitrarily many addresses
of either type, so displaying IPv4/IPv6 side by side will not work.
I think we need a display format like:
virsh domifaddr f18
Name MAC address Protocol Address
-------------------------------------------------------------------------------
lo 00:00:00:00:00:00 ipv4 127.0.0.1/8
- - ipv6 ::1/128
eth0 52:54:00:89:4e:97 ipv4 192.168.101.130/24
- - ipv4 192.168.101.133/24
- - ipv4 192.168.101.132/24
- - ipv6 fe80::5054:ff:fe89:4e97/64
eth1 52:54:00:89:ad:35 ipv4 192.168.102.142/24
- - ipv4 192.168.102.143/24
- - ipv6 fe80::5054:ff:fe89:ad35/64
With option to fully display all fields to make life easier for scripts:
virsh domifaddr --full f18
Name MAC address Protocol Address
-------------------------------------------------------------------------------
lo 00:00:00:00:00:00 ipv4 127.0.0.1/8
lo 00:00:00:00:00:00 ipv6 ::1/128
eth0 52:54:00:89:4e:97 ipv4 192.168.101.130/24
eth0 52:54:00:89:4e:97 ipv4 192.168.101.133/24
eth0 52:54:00:89:4e:97 ipv4 192.168.101.132/24
eth0 52:54:00:89:4e:97 ipv6 fe80::5054:ff:fe89:4e97/64
eth1 52:54:00:89:ad:35 ipv4 192.168.102.142/24
eth1 52:54:00:89:ad:35 ipv4 192.168.102.143/24
eth1 52:54:00:89:ad:35 ipv6 fe80::5054:ff:fe89:ad35/64
> +
> + 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 (interface && STRNEQ(interface, iface->name)) {
> + virBufferFreeAndReset(&buf);
> + continue;
> + }
> +
> + if (iface->hwaddr)
> + hwaddr = iface->hwaddr;
> +
> + for (j = 0; j < iface->naddrs; j++) {
> + if (j)
> + virBufferAsprintf(&buf, "%25s/%d",
> + iface->addrs[j].addr,
> + iface->addrs[j].prefix);
> + else
> + virBufferAsprintf(&buf, "%s/%d",
> + iface->addrs[j].addr,
> + iface->addrs[j].prefix);
This logic is very broken not allowing for multiple addrs per device
> + }
> +
> + if (virBufferError(&buf)) {
> + virBufferFreeAndReset(&buf);
> + virReportOOMError();
> + return ret;
> + }
> +
> + 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++)
> + virDomainInterfaceFree(ifaces[i]);
> + VIR_FREE(ifaces);
> +
> + virDomainFree(dom);
> + return ret;
> +}
> +
> const vshCmdDef domMonitoringCmds[] = {
> {.name = "domblkerror",
> .handler = cmdDomBlkError,
> @@ -1944,5 +2039,11 @@ const vshCmdDef domMonitoringCmds[] = {
> .info = info_list,
> .flags = 0
> },
> + {.name = "domifaddr",
> + .handler = cmdDomIfAddr,
> + .opts = opts_domifaddr,
> + .info = info_domifaddr,
> + .flags = 0
> + },
> {.name = NULL}
> };
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list