ipaplatform: Move Fedora-specific implementations of tasks to fedora base platform file
https://fedorahosted.org/freeipa/ticket/4052 Reviewed-By: Petr Viktorin <pviktori@redhat.com>
This commit is contained in:
1 parent
3edfabb4c4
commit
a7c2327a36
4 files changed
+124
-108
No files matched your search
@@ -50,63 +50,6 @@ __all__ = ['authconfig', 'service', 'knownservices',
|
||||
# Just copy a referential list of timedate services
|
||||
timedate_services = list(base.timedate_services)
|
||||
|
||||
def backup_and_replace_hostname(fstore, statestore, hostname):
|
||||
old_hostname = socket.gethostname()
|
||||
try:
|
||||
ipautil.run(['/bin/hostname', hostname])
|
||||
except ipautil.CalledProcessError, e:
|
||||
print >>sys.stderr, "Failed to set this machine hostname to %s (%s)." % (hostname, str(e))
|
||||
|
||||
filepath = '/etc/hostname'
|
||||
if os.path.exists(filepath):
|
||||
# read old hostname
|
||||
with open(filepath, 'r') as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
# skip comment or empty line
|
||||
continue
|
||||
old_hostname = line
|
||||
break
|
||||
fstore.backup_file(filepath)
|
||||
|
||||
with open(filepath, 'w') as f:
|
||||
f.write("%s\n" % hostname)
|
||||
os.chmod(filepath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
||||
os.chown(filepath, 0, 0)
|
||||
restore_context(filepath)
|
||||
|
||||
# store old hostname
|
||||
statestore.backup_state('network', 'hostname', old_hostname)
|
||||
|
||||
def restore_network_configuration(fstore, statestore):
|
||||
old_filepath = '/etc/sysconfig/network'
|
||||
old_hostname = statestore.get_state('network', 'hostname')
|
||||
hostname_was_configured = False
|
||||
|
||||
if fstore.has_file(old_filepath):
|
||||
# This is Fedora >=18 instance that was upgraded from previous
|
||||
# Fedora version which held network configuration
|
||||
# in /etc/sysconfig/network
|
||||
old_filepath_restore = '/etc/sysconfig/network.ipabkp'
|
||||
fstore.restore_file(old_filepath, old_filepath_restore)
|
||||
print "Deprecated configuration file '%s' was restored to '%s'" \
|
||||
% (old_filepath, old_filepath_restore)
|
||||
hostname_was_configured = True
|
||||
|
||||
filepath = '/etc/hostname'
|
||||
if fstore.has_file(filepath):
|
||||
fstore.restore_file(filepath)
|
||||
hostname_was_configured = True
|
||||
|
||||
if not hostname_was_configured and old_hostname:
|
||||
# hostname was not configured before but was set by IPA. Delete
|
||||
# /etc/hostname to restore previous configuration
|
||||
try:
|
||||
os.remove(filepath)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
authconfig = fedora16.authconfig
|
||||
service = fedora16.service
|
||||
knownservices = fedora16.knownservices
|
||||
|
||||
@@ -70,51 +70,3 @@ service = fedora18.service
|
||||
knownservices = fedora18.knownservices
|
||||
restore_context = fedora18.restore_context
|
||||
check_selinux_status = fedora18.check_selinux_status
|
||||
|
||||
systemwide_ca_store = '/etc/pki/ca-trust/source/anchors/'
|
||||
|
||||
|
||||
def insert_ca_cert_into_systemwide_ca_store(cacert_path):
|
||||
# Add the 'ipa-' prefix to cert name to avoid name collisions
|
||||
cacert_name = os.path.basename(cacert_path)
|
||||
new_cacert_path = os.path.join(systemwide_ca_store, 'ipa-%s' % cacert_name)
|
||||
|
||||
# Add the CA to the systemwide CA trust database
|
||||
try:
|
||||
shutil.copy(cacert_path, new_cacert_path)
|
||||
run(['/usr/bin/update-ca-trust'])
|
||||
except OSError, e:
|
||||
root_logger.info("Failed to copy %s to %s" % (cacert_path,
|
||||
new_cacert_path))
|
||||
except CalledProcessError, e:
|
||||
root_logger.info("Failed to add CA to the systemwide "
|
||||
"CA trust database: %s" % str(e))
|
||||
else:
|
||||
root_logger.info('Added the CA to the systemwide CA trust database.')
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def remove_ca_cert_from_systemwide_ca_store(cacert_path):
|
||||
# Derive the certificate name in the store
|
||||
cacert_name = os.path.basename(cacert_path)
|
||||
new_cacert_path = os.path.join(systemwide_ca_store, 'ipa-%s' % cacert_name)
|
||||
|
||||
# Remove CA cert from systemwide store
|
||||
if os.path.exists(new_cacert_path):
|
||||
try:
|
||||
os.remove(new_cacert_path)
|
||||
run(['/usr/bin/update-ca-trust'])
|
||||
except OSError, e:
|
||||
root_logger.error('Could not remove: %s, %s'
|
||||
% (new_cacert_path, str(e)))
|
||||
return False
|
||||
except CalledProcessError, e:
|
||||
root_logger.error('Could not update systemwide CA trust '
|
||||
'database: %s' % str(e))
|
||||
return False
|
||||
else:
|
||||
root_logger.info('Systemwide CA database updated.')
|
||||
|
||||
return True
|
||||
Reference in new issue
Block a user