summaryrefslogtreecommitdiffstats
path: root/pyanaconda
diff options
context:
space:
mode:
authorRadek Vykydal <rvykydal@redhat.com>2012-08-23 16:15:24 +0200
committerRadek Vykydal <rvykydal@redhat.com>2012-08-27 15:50:37 +0200
commit28381f5c74d6202cc2685d40db2a590e8d253286 (patch)
tree0281b95ce476aaeea3a35f89e07df4f45a896d69 /pyanaconda
parent2fe596d394981d638846aaad00fff27518db00cb (diff)
downloadanaconda-28381f5c74d6202cc2685d40db2a590e8d253286.tar.gz
anaconda-28381f5c74d6202cc2685d40db2a590e8d253286.tar.xz
anaconda-28381f5c74d6202cc2685d40db2a590e8d253286.zip
networking: remove Network() object
- We can add dhcp activation in networkInitialize in thread later - Also fixing merge (newui->master) of https://lists.fedorahosted.org/pipermail/anaconda-patches/2012-June/000023.html
Diffstat (limited to 'pyanaconda')
-rw-r--r--pyanaconda/network.py59
-rw-r--r--pyanaconda/vnc.py24
2 files changed, 43 insertions, 40 deletions
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index e5c4a881f..6a92d24ed 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -94,6 +94,25 @@ def sanityCheckHostname(hostname):
return None
+# Return a list of IP addresses for all active devices.
+def getIPs():
+ ips = []
+ for devname in getActiveNetDevs():
+ try:
+ ips += (isys.getIPAddresses(devname, version=4) +
+ isys.getIPAddresses(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
+
+# Return the first real non-local IP we find
+def getFirstRealIP():
+ for ip in getIPs():
+ if ip not in ("127.0.0.1", "::1"):
+ return ip
+ return None
+
# Try to determine what the hostname should be for this system
def getHostname():
resetResolver()
@@ -400,27 +419,12 @@ class WirelessNetworkDevice(NetworkDevice):
def write(self):
pass
-
-class Network:
-
- def __init__(self):
-
- ifcfglog.debug("Network object created called")
-
- # TODO this may need to be handled in getDevices()
- if flags.imageInstall:
- return
-
- # TODO this should go away (patch pending),
- # default ifcfg files should be created in dracut
-
- # populate self.netdevices
- devhash = isys.getDeviceProperties(dev=None)
- for iface in devhash.keys():
- if not isys.isWirelessDevice(iface):
- device = NetworkDevice(netscriptsDir, iface)
- if not os.access(device.path, os.R_OK):
- device.setDefaultConfig()
+def createMissingDefaultIfcfgs():
+ for iface in getDevices():
+ if not isys.isWirelessDevice(iface):
+ device = NetworkDevice(netscriptsDir, iface)
+ if not os.access(device.path, os.R_OK):
+ device.setDefaultConfig()
def getDevices():
# TODO: filter with existence of ifcfg file?
@@ -878,3 +882,16 @@ def writeNetworkConf(storage, ksdata, instClass):
# NM_CONTROLLED is not mirrored in ksdata
disableNMForStorageDevices(storage)
autostartFCoEDevices(storage, ksdata)
+
+# networking initialization and ksdata object update
+def networkInitialize(ksdata):
+ from pyanaconda.kickstart import NetworkData
+
+ if not flags.imageInstall:
+ # XXX: this should go to anaconda dracut
+ createMissingDefaultIfcfgs()
+
+ if ksdata.network.hostname is None:
+ hostname = getHostname()
+ nd = NetworkData(hostname=hostname)
+ ksdata.network.network.append(nd)
diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index b06ac8743..22e758c6c 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -77,25 +77,11 @@ class VncServer:
def initialize(self):
"""Here is were all the relative vars get initialized. """
- # see if we can sniff out network info
- netinfo = network.Network()
-
- active_devs = network.getActiveNetDevs()
-
- self.ip = None
- if active_devs != []:
- devname = active_devs[0]
- try:
- ips = (isys.getIPAddresses(devname, version=4) +
- isys.getIPAddresses(devname, version=6))
- except Exception as e:
- log.warning("Got an exception trying to get the self.ip addr "
- "of %s: %s" % (devname, e))
- else:
- if ips and ips[0] not in ("127.0.0.1", "::1"):
- log.info("IPs (using first) of device %s: %s" % (devname,
- ips))
- self.ip = ips[0]
+ self.ip = network.getFirstRealIP()
+
+ if not self.ip:
+ # Raise this here which will be caught higher up
+ raise Exception("No IP addresses found.")
ipstr = self.ip