[PATCH 07/15] remove Network(): hostname attribute

Radek Vykydal rvykydal at redhat.com
Thu Jul 19 10:02:40 UTC 2012


NM is setting hostname and we might be resetting it in kickstart.py.
It is stored in ksdata with unfortunate access (iterating over
network commands).
Hostname handling will need some more work in newui. Here I am just
giving another stab to Network() object.
---
 pyanaconda/iw/lvm_dialog_gui.py  |    3 ++-
 pyanaconda/iw/network_gui.py     |    3 +--
 pyanaconda/kickstart.py          |    3 ---
 pyanaconda/network.py            |   28 +++++++---------------------
 pyanaconda/textw/network_text.py |    3 +--
 pyanaconda/vnc.py                |    2 +-
 6 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/pyanaconda/iw/lvm_dialog_gui.py b/pyanaconda/iw/lvm_dialog_gui.py
index abc47e8..2097542 100644
--- a/pyanaconda/iw/lvm_dialog_gui.py
+++ b/pyanaconda/iw/lvm_dialog_gui.py
@@ -32,6 +32,7 @@ from pyanaconda.constants import *
 from pyanaconda.storage.devices import *
 from pyanaconda.storage.deviceaction import *
 from pyanaconda.partIntfHelpers import *
+from pyanaconda.network import getHostname
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -1376,7 +1377,7 @@ class VolumeGroupEditor:
             if not self.isNew:
                 self.volnameEntry.set_text(self.vg.name)
             else:
-                self.volnameEntry.set_text(self.storage.suggestContainerName(hostname=anaconda.network.hostname,
+                self.volnameEntry.set_text(self.storage.suggestContainerName(hostname=getHostname(),
                                                                              prefix="vg"))
         else:
             lbl = createAlignedLabel(_("Volume Group Name:"))
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py
index cf20c39..8df2038 100644
--- a/pyanaconda/iw/network_gui.py
+++ b/pyanaconda/iw/network_gui.py
@@ -40,7 +40,7 @@ class NetworkWindow(InstallWindow):
     def getScreen(self, anaconda):
         self.intf = anaconda.intf
         self.anaconda = anaconda
-        self.hostname = network.getDefaultHostname(anaconda)
+        self.hostname = network.getHostname()
 
         # load the UI
         (self.xml, self.align) = gui.getGladeWidget("network.glade",
@@ -95,7 +95,6 @@ class NetworkWindow(InstallWindow):
                                     custom_icon="error")
             self.hostnameError()
 
-        self.anaconda.network.hostname = hostname
         network.setHostname(hostname)
         return None
 
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 37a37bc..4a2cbb7 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -645,7 +645,6 @@ class NetworkData(commands.network.F16_NetworkData):
     def execute(self):
         if flags.imageInstall:
             if self.hostname != "":
-                self.anaconda.network.hostname = self.hostname
                 network.setHostname(self.hostname)
 
             # Only set hostname
@@ -655,7 +654,6 @@ class NetworkData(commands.network.F16_NetworkData):
         # only set hostname
         if self.essid:
             if self.hostname != "":
-                self.anaconda.network.hostname = self.hostname
                 network.setHostname(self.hostname)
             return
 
@@ -708,7 +706,6 @@ class NetworkData(commands.network.F16_NetworkData):
                     break
 
         if self.hostname != "":
-            self.anaconda.network.hostname = self.hostname
             network.setHostname(self.hostname)
             if not dev:
                 # Only set hostname
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index c7f11b7..65ef239 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -94,7 +94,7 @@ def sanityCheckHostname(hostname):
     return None
 
 # Try to determine what the hostname should be for this system
-def getDefaultHostname(anaconda):
+def getHostname():
     resetResolver()
 
     hn = None
@@ -114,14 +114,6 @@ def getDefaultHostname(anaconda):
                     hn = hinfo[0]
                     break
 
-    if hn and hn not in ('(none)', 'localhost', 'localhost.localdomain'):
-        return hn
-
-    try:
-        hn = anaconda.network.hostname
-    except:
-        hn = None
-
     if not hn or hn in ('(none)', 'localhost', 'localhost.localdomain'):
         hn = socket.gethostname()
 
@@ -436,8 +428,6 @@ class Network:
 
     def __init__(self):
 
-        self.hostname = socket.gethostname()
-
         self.update()
 
     def update(self):
@@ -460,11 +450,6 @@ class Network:
                 else:
                     device.setDefaultConfig()
 
-            # TODORV - the last iface in loop wins, might be ok,
-            #          not worthy of special juggling
-            if device.get('HOSTNAME'):
-                self.hostname = device.get('HOSTNAME')
-
             device.description = isys.getNetDevDesc(iface)
 
             self.netdevices[iface] = device
@@ -494,9 +479,10 @@ class Network:
         if len(devNames) == 0:
             return
 
+        hostname = getHostname()
         for devName in devNames:
             dev = self.netdevices[devName]
-            line = "%s" % kickstartNetworkData(dev, self.hostname)
+            line = "%s" % kickstartNetworkData(dev, hostname)
             f.write(line)
 
     def disableNMForStorageDevices(self, anaconda):
@@ -546,9 +532,9 @@ class Network:
         f.write("NETWORKING=yes\n")
         f.write("HOSTNAME=")
 
-        # use instclass hostname if set(kickstart) to override
-        if self.hostname:
-            f.write(self.hostname + "\n")
+        hostname = getHostname()
+        if hostname:
+            f.write(hostname + "\n")
         else:
             f.write("localhost.localdomain\n")
 
@@ -616,7 +602,7 @@ class Network:
 
         return dracutBootArguments(self.netdevices[nic],
                                    networkStorageDevice.host_address,
-                                   self.hostname)
+                                   getHostname())
 
 def getDevices():
     # TODO: filter with existence of ifcfg file?
diff --git a/pyanaconda/textw/network_text.py b/pyanaconda/textw/network_text.py
index 58eb81e..a33d7f5 100644
--- a/pyanaconda/textw/network_text.py
+++ b/pyanaconda/textw/network_text.py
@@ -26,8 +26,7 @@ from pyanaconda import network
 
 class HostnameWindow:
     def __call__(self, screen, anaconda):
-        hname = network.getDefaultHostname(anaconda)
-        anaconda.network.hostname = hname
+        hname = network.getHostname()
         return INSTALL_OK
 
 # vim:tw=78:ts=4:et:sw=4
diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index a7ccc76..b38f233 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -105,7 +105,7 @@ class VncServer:
         except Exception as e:
             log.debug("Exception caught trying to get host name of %s: %s" %
                       (ipstr, e))
-            self.name = network.getDefaultHostname(self.anaconda)
+            self.name = network.getHostname()
         else:
             if len(hinfo) == 3:
                 self.name = hinfo[0]
-- 
1.7.4



More information about the anaconda-patches mailing list