diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-10-14 13:41:41 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-10-14 14:48:51 -1000 |
commit | 49d36b72b4e3985bc0f1a9e91812859624899267 (patch) | |
tree | db268da62a3a6bc287567fd1c69bfbb74d1877d8 /network.py | |
parent | cf696b5fcad672e6d4a7771eb0288383001de3ae (diff) | |
download | anaconda-49d36b72b4e3985bc0f1a9e91812859624899267.tar.gz anaconda-49d36b72b4e3985bc0f1a9e91812859624899267.tar.xz anaconda-49d36b72b4e3985bc0f1a9e91812859624899267.zip |
Try to look up the hostname by the IP address NM reports (#466775)
NetworkManager stopped providing the Hostname property (thanks!),
so get the IP address now and shove that through gethostbyaddr() and
see if it produces anything useful.
Diffstat (limited to 'network.py')
-rw-r--r-- | network.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/network.py b/network.py index 1fa4d35db..d546b747d 100644 --- a/network.py +++ b/network.py @@ -28,6 +28,7 @@ import shutil import isys import iutil import socket +import struct import os import time import minihal @@ -71,6 +72,41 @@ def sanityCheckHostname(hostname): # Try to determine what the hostname should be for this system def getDefaultHostname(anaconda): + isys.resetResolv() + + hn = None + bus = dbus.SystemBus() + nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) + nm_props_iface = dbus.Interface(nm, isys.DBUS_PROPS_IFACE) + + active_connections = nm_props_iface.Get(isys.NM_MANAGER_IFACE, "ActiveConnections") + + # XXX: account for Ip6Config objects when NetworkManager supports them + for connection in active_connections: + active_connection = bus.get_object(isys.NM_SERVICE, connection) + active_connection_props_iface = dbus.Interface(active_connection, isys.DBUS_PROPS_IFACE) + devices = active_connection_props_iface.Get(isys.NM_MANAGER_IFACE, 'Devices') + + for device_path in devices: + device = bus.get_object(isys.NM_SERVICE, device_path) + device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE) + + ip4_config_path = device_props_iface.Get(isys.NM_MANAGER_IFACE, 'Ip4Config') + ip4_config_obj = bus.get_object(isys.NM_SERVICE, ip4_config_path) + ip4_config_props = dbus.Interface(ip4_config_obj, isys.DBUS_PROPS_IFACE) + + # addresses (3-element list: ipaddr, netmask, gateway) + addrs = ip4_config_props.Get(isys.NM_MANAGER_IFACE, "Addresses")[0] + try: + tmp = struct.pack('I', addrs[0]) + ipaddr = socket.inet_ntop(socket.AF_INET, tmp) + (hn, aliases, addresses) = socket.gethostbyaddr(ipaddr) + except: + continue + + if not hn and hn != 'localhost' or hn != 'localhost.localdomain': + return hn + hn = anaconda.id.network.hostname if not hn or hn == '(none)' or hn == 'localhost' or hn == 'localhost.localdomain': |