Save the value of hostname even if it doesn't appear in /etc/sysconfig/network

https://fedorahosted.org/freeipa/ticket/1871
This commit is contained in:
Rob Crittenden 2011-10-13 17:58:27 -04:00
parent 58918c4593
commit 16fc9f847c

View File

@ -23,6 +23,7 @@ import re
import os import os
import stat import stat
import sys import sys
import socket
from ipapython import ipautil from ipapython import ipautil
from ipapython.platform import base from ipapython.platform import base
@ -133,6 +134,7 @@ def restore_context(filepath):
ipautil.run(["/sbin/restorecon", filepath], raiseonerr=False) ipautil.run(["/sbin/restorecon", filepath], raiseonerr=False)
def backup_and_replace_hostname(fstore, statestore, hostname): def backup_and_replace_hostname(fstore, statestore, hostname):
old_hostname = socket.gethostname()
try: try:
ipautil.run(['/bin/hostname', hostname]) ipautil.run(['/bin/hostname', hostname])
except ipautil.CalledProcessError, e: except ipautil.CalledProcessError, e:
@ -144,4 +146,5 @@ def backup_and_replace_hostname(fstore, statestore, hostname):
restore_context("/etc/sysconfig/network") restore_context("/etc/sysconfig/network")
if 'HOSTNAME' in old_values: if 'HOSTNAME' in old_values:
statestore.backup_state('network', 'hostname', old_values['HOSTNAME']) statestore.backup_state('network', 'hostname', old_values['HOSTNAME'])
else:
statestore.backup_state('network', 'hostname', old_hostname)