[virt-tools-list] [virt-manager PATCH] virtManager/interface: detect whether IP address comes from DHCP server
Cole Robinson
crobinso at redhat.com
Sun Feb 5 21:27:21 UTC 2017
On 01/19/2017 12:07 PM, Pavel Hrdina wrote:
> When the network interface is up the active XML contains only IP address
> even in case that the inactive XML was configured to get the IP address
> from DHCP server. To propagate this information back to UI we need to
> get both XMLs to figure out current IP addresses and the configuration.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1410722
>
Sorry for the review delay.
ACK, though I've long though this should be fixed in libvirt/netcf, it's not
the pattern that the other XML drivers follow
- Cole
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
> virtManager/interface.py | 25 ++++++++++++++++++-------
> 1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/virtManager/interface.py b/virtManager/interface.py
> index 3af59743..2fe61b2a 100644
> --- a/virtManager/interface.py
> +++ b/virtManager/interface.py
> @@ -117,24 +117,35 @@ class vmmInterface(vmmLibvirtObject):
> return [x[0] for x in self.get_slaves()]
>
> def _get_ip(self, iptype):
> - obj = self.get_xmlobj()
> - found = None
> - for protocol in obj.protocols:
> + # Get list of IP addresses from active XML and protocol configuration
> + # from inactive XML to figure out whether the IP address is static or
> + # from DHCP server.
> + activeObj = self.get_xmlobj()
> + inactiveObj = self.get_xmlobj(inactive=True)
> +
> + activeProto = None
> + inactiveProto = None
> + for protocol in activeObj.protocols:
> if protocol.family == iptype:
> - found = protocol
> + activeProto = protocol
> break
> - if not found:
> + for protocol in inactiveObj.protocols:
> + if protocol.family == iptype:
> + inactiveProto = protocol
> + break
> +
> + if not activeProto and not inactiveProto:
> return None, []
>
> ret = []
> - for ip in found.ips:
> + for ip in activeProto.ips:
> ipstr = ip.address
> if not ipstr:
> continue
> if ip.prefix:
> ipstr += "/%s" % ip.prefix
> ret.append(ipstr)
> - return found, ret
> + return inactiveProto or activeProto, ret
>
> def get_ipv4(self):
> proto, ips = self._get_ip("ipv4")
>
More information about the virt-tools-list
mailing list