from .xlate import XLATOR
-__version__ = '0.8.5'
+__version__ = '0.8.6'
LOG = logging.getLogger(__name__)
LOG.debug(_("Output on {}:").format('STDERR') + '\n' + proc.stderr)
# -------------------------------------------------------------------------
- def ensure_keys(self):
+ def ensure_keys(self, tmp_auth_keys_file=None):
local_keys_dir = self.base_dir / 'keys'
- auth_keys_file = local_keys_dir / "auth_keys_pp_betrieb"
+ if tmp_auth_keys_file:
+ auth_keys_file = tmp_auth_keys_file
+ else:
+ auth_keys_file = local_keys_dir / "auth_keys_pp_betrieb"
docroot = self.cfg.cobbler_ws_docroot / self.cfg.cobbler_ws_rel_filesdir
remote_dir = docroot / self.cfg.system_status / 'keys'
remote_file = remote_dir / "auth_keys_pp_betrieb"
import socket
import textwrap
import signal
+import tempfile
+import os
+
+from pathlib import Path
# Third party modules
import pytz
from .xlate import XLATOR
-__version__ = '2.2.1'
+__version__ = '2.2.2'
LOG = logging.getLogger(__name__)
TZ = pytz.timezone('Europe/Berlin')
self.cobbler = None
self.ldap = None
self.ldap_server = None
+ self.auth_keys_file = None
self.vsphere = VsphereConnection(
self.cfg.vsphere_info, cluster=self.cfg.vsphere_cluster,
self.disconnect_ldap()
+ if self.auth_keys_file:
+ if self.auth_keys_file.exists():
+ LOG.debug(_("Removing {!r} ...").format(str(self.auth_keys_file)))
+ self.auth_keys_file.unlink()
+
# -------------------------------------------------------------------------
def __call__(self):
"""Executing the underlying action."""
self.cobbler.ensure_root_authkeys()
self.cobbler.ensure_rsyslog_cfg_files()
self.cobbler.ensure_snippets()
- self.cobbler.ensure_keys()
+
+ self.cobbler.ensure_keys(self.auth_keys_file)
+ if self.auth_keys_file:
+ if self.auth_keys_file.exists():
+ LOG.debug(_("Removing {!r} ...").format(str(self.auth_keys_file)))
+ self.auth_keys_file.unlink()
+ self.auth_keys_file = None
+
self.cobbler.ensure_system_ks()
self.cobbler.ensure_repo_files()
self.cobbler.ensure_bashrc()
LOG.info(_("Creating authorized keys of root from LDAP ..."))
+ prefix = 'tmp.authorized_keys.root.'
+ (fh, tmp_keys_file) = tempfile.mkstemp(prefix=prefix, text=True)
+ self.auth_keys_file = Path(tmp_keys_file)
+ os.close(fh)
+ LOG.debug(_("Using temporary file {!r} for authorized keys of root.").format(
+ tmp_keys_file))
+
try:
self.connect_ldap()
finally:
self.disconnect_ldap()
+ self.auth_keys_file.write_text(auth_keys)
+
# -------------------------------------------------------------------------
def get_ldap_admins(self):