[PATCH 1/2] Network spoke: add hostname setting (#856456)
Radek Vykydal
rvykydal at redhat.com
Tue Dec 18 14:14:56 UTC 2012
Note: The entry is updated automatically if the hostname has not
been set yet ("localhost.localdomain" value) and NetworkManager updates
hostname based on successfull connecting (e.g. finshed dhcp) and his policy
(which is: static configuration, dhcp, static configuration in time of NM start,
reverse DNS lookup)
---
pyanaconda/network.py | 15 ++++--
pyanaconda/ui/gui/spokes/network.glade | 92 ++++++++++++++++------------------
pyanaconda/ui/gui/spokes/network.py | 44 +++++++++++++---
3 files changed, 89 insertions(+), 62 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 6e57f0b..2bf7832 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -965,11 +965,18 @@ def wait_for_dhcp():
log.debug("not connected, waited %d of %d secs" % (i, CONNECTION_TIMEOUT))
return False
-def update_hostname(ksdata):
- hostname = getHostname()
+def update_hostname(ksdata, hostname=None):
+ if not hostname:
+ hostname = getHostname()
log.debug("updating hostname %s" % hostname)
- nd = kickstartNetworkData(hostname=hostname)
- ksdata.network.network.append(nd)
+ hostname_found = False
+ for nd in ksdata.network.network:
+ if nd.hostname:
+ nd.hostname = hostname
+ hostname_found = True
+ if not hostname_found:
+ nd = kickstartNetworkData(hostname=hostname)
+ ksdata.network.network.append(nd)
def get_device_name(devspec):
diff --git a/pyanaconda/ui/gui/spokes/network.glade b/pyanaconda/ui/gui/spokes/network.glade
index 5fc0613..a19dbd3 100644
--- a/pyanaconda/ui/gui/spokes/network.glade
+++ b/pyanaconda/ui/gui/spokes/network.glade
@@ -198,7 +198,6 @@ updates available for you.</property>
<object class="GtkToolButton" id="add_toolbutton">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="icon_name">list-add-symbolic</property>
</object>
@@ -211,7 +210,6 @@ updates available for you.</property>
<object class="GtkToolButton" id="remove_toolbutton">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="icon_name">list-remove-symbolic</property>
</object>
@@ -527,7 +525,6 @@ updates available for you.</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
- <property name="use_action_appearance">False</property>
</object>
</child>
</object>
@@ -562,7 +559,6 @@ updates available for you.</property>
<property name="valign">end</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -575,27 +571,6 @@ updates available for you.</property>
<child>
<placeholder/>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="expand">True</property>
@@ -875,7 +850,6 @@ updates available for you.</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
- <property name="use_action_appearance">False</property>
</object>
</child>
</object>
@@ -1033,7 +1007,6 @@ updates available for you.</property>
<property name="valign">end</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1053,7 +1026,6 @@ updates available for you.</property>
<property name="valign">end</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1073,7 +1045,6 @@ updates available for you.</property>
<property name="valign">end</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
<packing>
@@ -1083,24 +1054,6 @@ updates available for you.</property>
<property name="height">1</property>
</packing>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="expand">True</property>
@@ -1440,7 +1393,6 @@ updates available for you.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
@@ -1726,7 +1678,6 @@ updates available for you.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
@@ -2204,7 +2155,6 @@ updates available for you.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
@@ -2245,6 +2195,48 @@ updates available for you.</property>
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">24</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">5</property>
+ <child>
+ <object class="GtkLabel" id="label_hostname">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="yalign">0.52999997138977051</property>
+ <property name="label" translatable="yes">Hostname:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="entry_hostname">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">start</property>
+ <property name="invisible_char">●</property>
+ <property name="width_chars">35</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 31145e2..45b0d5d 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -41,7 +41,7 @@ from pyanaconda.ui.gui.categories.software import SoftwareCategory
from pyanaconda.ui.gui.hubs.summary import SummaryHub
from pyanaconda.ui.gui.utils import gtk_call_once
-from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs, logIfcfgFiles
+from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs, logIfcfgFiles, update_hostname
from gi.repository import GLib, GObject, Pango, Gio, NetworkManager, NMClient
import dbus
@@ -222,7 +222,7 @@ class CellRendererSecurity(Gtk.CellRendererPixbuf):
self.set_property("icon-name", self.icon_name)
-class NetworkControlBox():
+class NetworkControlBox(object):
supported_device_types = [
NetworkManager.DeviceType.ETHERNET,
@@ -949,6 +949,14 @@ class NetworkControlBox():
return [row[DEVICES_COLUMN_OBJECT] for
row in self.builder.get_object("liststore_devices")]
+ @property
+ def hostname(self):
+ return self.builder.get_object("entry_hostname").get_text()
+
+ @hostname.setter
+ def hostname(self, value):
+ self.builder.get_object("entry_hostname").set_text(value)
+
class NetworkSpoke(NormalSpoke):
builderObjects = ["networkWindow", "liststore_wireless_network", "liststore_devices"]
mainWidgetName = "networkWindow"
@@ -962,6 +970,7 @@ class NetworkSpoke(NormalSpoke):
def __init__(self, *args, **kwargs):
NormalSpoke.__init__(self, *args, **kwargs)
self.network_control_box = NetworkControlBox(self.builder)
+ self.network_control_box.hostname = self.data.network.hostname
self.network_control_box.client.connect("notify::%s" %
NMClient.CLIENT_STATE,
self.on_nm_state_changed)
@@ -969,14 +978,14 @@ class NetworkSpoke(NormalSpoke):
device.connect("state-changed", self.on_device_state_changed)
def apply(self):
- hostname = self.data.network.hostname
+ # TODO: sanity check
self.data.network.network = []
for dev in self.network_control_box.listed_devices:
network_data = getKSNetworkData(dev)
if network_data is not None:
self.data.network.network.append(network_data)
- nd = kickstartNetworkData(hostname=hostname)
- self.data.network.network.append(nd)
+ hostname = self.network_control_box.hostname
+ update_hostname(self.data, hostname)
@property
def completed(self):
@@ -1036,6 +1045,7 @@ class NetworkSpoke(NormalSpoke):
def on_nm_state_changed(self, *args):
gtk_call_once(self._update_status)
+ gtk_call_once(self._update_hostname)
def on_device_state_changed(self, *args):
new_state = args[1]
@@ -1047,6 +1057,11 @@ class NetworkSpoke(NormalSpoke):
def _update_status(self):
communication.send_message(self.__class__.__name__, self.status)
+ def _update_hostname(self):
+ if self.network_control_box.hostname == "localhost.localdomain":
+ update_hostname(self.data)
+ self.network_control_box.hostname = self.data.network.hostname
+
class NetworkStandaloneSpoke(StandaloneSpoke):
builderObjects = ["networkStandaloneWindow", "networkControlBox_vbox", "liststore_wireless_network", "liststore_devices"]
mainWidgetName = "networkStandaloneWindow"
@@ -1058,22 +1073,26 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
def __init__(self, *args, **kwargs):
StandaloneSpoke.__init__(self, *args, **kwargs)
self.network_control_box = NetworkControlBox(self.builder)
+ self.network_control_box.hostname = self.data.network.hostname
parent = self.builder.get_object("AnacondaStandaloneWindow-action_area5")
parent.add(self.network_control_box.vbox)
+ self.network_control_box.client.connect("notify::%s" %
+ NMClient.CLIENT_STATE,
+ self.on_nm_state_changed)
+
self._initially_available = self.completed
log.debug("network standalone spoke (init): completed: %s" % self._initially_available)
self._now_available = False
def apply(self):
- hostname = self.data.network.hostname
self.data.network.network = []
for dev in self.network_control_box.listed_devices:
network_data = getKSNetworkData(dev)
if network_data is not None:
self.data.network.network.append(network_data)
- nd = kickstartNetworkData(hostname=hostname)
- self.data.network.network.append(nd)
+ hostname = self.network_control_box.hostname
+ update_hostname(self.data, hostname)
self._now_available = self.completed
@@ -1104,6 +1123,15 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
self.window.hide()
Gtk.main_quit()
+ # Use case: slow dhcp has connected when on spoke
+ def on_nm_state_changed(self, *args):
+ gtk_call_once(self._update_hostname)
+
+ def _update_hostname(self):
+ if self.network_control_box.hostname == "localhost.localdomain":
+ update_hostname(self.data)
+ self.network_control_box.hostname = self.data.network.hostname
+
def getKSNetworkData(device):
retval = None
--
1.7.11.7
More information about the anaconda-patches
mailing list