[node-patches] Change in ovirt-node[master]: [DRAFT] Migrate to hostnamectl (if possible)
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Fri Apr 12 12:53:39 UTC 2013
Fabian Deutsch has uploaded a new change for review.
Change subject: [DRAFT] Migrate to hostnamectl (if possible)
......................................................................
[DRAFT] Migrate to hostnamectl (if possible)
hostnamectl is a tool which allows to configure the hostname.
This patch migrates away from sysconfig towards hostnamectl.
Legacy scripts (like the old UI) are not migrated.
rhbz#882206
Change-Id: I282192ddb27ac4596a3938d2e812cda38384b660
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/ovirt-auto-install.py
M scripts/tui/src/ovirt/node/config/defaults.py
M scripts/tui/src/ovirt/node/config/network.py
3 files changed, 29 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/36/13836/1
diff --git a/scripts/ovirt-auto-install.py b/scripts/ovirt-auto-install.py
index 38804a6..a25edc3 100755
--- a/scripts/ovirt-auto-install.py
+++ b/scripts/ovirt-auto-install.py
@@ -26,7 +26,7 @@
from ovirtnode.network import *
from ovirtnode.log import *
from ovirtnode.kdump import *
-
+from ovirt.node.config import defaults
def config_networking():
# network configuration
@@ -34,10 +34,9 @@
if OVIRT_VARS["OVIRT_BOOTIF"] != "":
network_auto()
if "OVIRT_HOSTNAME" in OVIRT_VARS:
- augtool("set", "/files/etc/sysconfig/network/HOSTNAME", \
- OVIRT_VARS["OVIRT_HOSTNAME"])
- system("hostname %s" % OVIRT_VARS["OVIRT_HOSTNAME"])
- ovirt_store_config("/etc/sysconfig/network")
+ cfg = defaults.Hostname()
+ tx = cfg.transaction()
+ tx()
# setup network before storage for iscsi installs
if is_iscsi_install():
diff --git a/scripts/tui/src/ovirt/node/config/defaults.py b/scripts/tui/src/ovirt/node/config/defaults.py
index 7c127fa..0f905c3 100644
--- a/scripts/tui/src/ovirt/node/config/defaults.py
+++ b/scripts/tui/src/ovirt/node/config/defaults.py
@@ -418,8 +418,9 @@
config.network.hostname(self.hostname)
- ovirtfunctions.ovirt_store_config("/etc/sysconfig/network")
ovirtfunctions.ovirt_store_config("/etc/hosts")
+ ovirtfunctions.ovirt_store_config("/etc/hostname")
+ ovirtfunctions.ovirt_store_config("/etc/sysconfig/network")
utils.network.reset_resolver()
diff --git a/scripts/tui/src/ovirt/node/config/network.py b/scripts/tui/src/ovirt/node/config/network.py
index 754998e..5a3a8e6 100644
--- a/scripts/tui/src/ovirt/node/config/network.py
+++ b/scripts/tui/src/ovirt/node/config/network.py
@@ -131,6 +131,29 @@
def hostname(new_hostname=None):
"""Get or set the current hostname in the config files
+ Using the hostnamectl tool
+ """
+ hostnamefile = "/etc/hostname"
+
+ if not os.path.isfile(hostnamefile):
+ return __legacy_hostname(new_hostname)
+
+ if new_hostname:
+ # hostnamectl set's runtime and config file
+ utils.process.check_call("hostnamectl --static set-hostname %s" %
+ new_hostname)
+
+ current_hostname = utils.fs.get_contents(hostnamefile)
+ if new_hostname and current_hostname != new_hostname:
+ raise RuntimeError(("Runtime hostname '%s' doesn't match" +
+ "configured one: %s") % (current_hostname,
+ new_hostname))
+
+ return current_hostname
+
+
+def __legacy_hostname(new_hostname=None):
+ """The legacy way of setting a hostname.
"""
aug = utils.AugeasWrapper()
augpath = "/files/etc/sysconfig/network/HOSTNAME"
--
To view, visit http://gerrit.ovirt.org/13836
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I282192ddb27ac4596a3938d2e812cda38384b660
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list