[PATCH] Give priority to IPv4 addresses when showing VNC & SSH IP (#1056420)

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 24 16:12:08 UTC 2014


On Fri, 2014-01-24 at 16:13 +0100, Martin Kolman wrote:
> Only if no IPv4 non-localhost addresses are found, show
> an IPv6 address (if there are some IPv6 addresses available).
> 
> Signed-off-by: Martin Kolman <mkolman at redhat.com>
> ---
>  pyanaconda/network.py | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/pyanaconda/network.py b/pyanaconda/network.py
> index 30693fe..ee295cf 100644
> --- a/pyanaconda/network.py
> +++ b/pyanaconda/network.py
> @@ -126,15 +126,23 @@ def sanityCheckHostname(hostname):
>  
>  # Return a list of IP addresses for all active devices.
>  def getIPs():
> -    ips = []
> +    ipv4_addresses = []
> +    ipv6_addresses = []
>      for devname in nm.nm_activated_devices():
>          try:
> -            ips += (nm.nm_device_ip_addresses(devname, version=4) +
> -                    nm.nm_device_ip_addresses(devname, version=6))
> +            ipv4_addresses += nm.nm_device_ip_addresses(devname, version=4)
> +            ipv6_addresses += nm.nm_device_ip_addresses(devname, version=6)
>          except Exception as e:
>              log.warning("Got an exception trying to get the ip addr "
>                          "of %s: %s" % (devname, e))
> -    return ips
> +    # Extend the list of IPv4 addresses by IPv6 addresses,
> +    # so that all detected IPv4 addresses (if any) are followed by all
> +    # detected IPv6 addresses (if any).
> +    # Like this we can easily give priority to IPv4 addresses
> +    # but still automatically fall back to IPv6 addresses if
> +    # IPv4 is not used on the given system.
> +    ipv4_addresses += ipv6_addresses
> +    return ipv4_addresses
I'd suggest simply 'return ipv4_addresses + ipv6_addresses' with a short
comment 'prefer IPv4 addressses of IPv6' right above that statement.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list