Always set hostname

This prevents cases when hostname on system is set inconsistently
(transient and static hostname differs) and may cause IPA errors.

This commit ensures that all hostnames are set properly.

https://fedorahosted.org/freeipa/ticket/5794

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Martin Basti
2016-04-19 18:36:32 +02:00
parent 14ee02dcbd
commit c5686295f1
6 changed files with 36 additions and 64 deletions

View File

@@ -1475,18 +1475,6 @@ def dn_attribute_property(private_name):
return property(getter, setter)
def restore_hostname(statestore):
"""
Restore hostname of a machine, if it was set before
"""
old_hostname = statestore.restore_state('network','hostname')
system_hostname = socket.gethostname()
if old_hostname is not None and old_hostname != system_hostname:
try:
run([paths.BIN_HOSTNAME, old_hostname])
except CalledProcessError as e:
print("Failed to set this machine hostname back to %s: %s" % (old_hostname, str(e)), file=sys.stderr)
def posixify(string):
"""
Convert a string to a more strict alpha-numeric representation.