import hashlib
import textwrap
import ipaddress
+import tempfile
+import os
from json import JSONDecodeError
from .xlate import XLATOR
-__version__ = '0.8.3'
+__version__ = '0.8.4'
LOG = logging.getLogger(__name__)
self.root_dir = CrTplConfiguration.default_cobbler_rootdir
self.cfg = cfg
self.cobbler_version = None
+ self.local_ks_file = None
super(Cobbler, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
if initialized:
self.initialized = True
+ # -------------------------------------------------------------------------
+ def __del__(self):
+
+ if self.local_ks_file:
+ if self.local_ks_file.exists():
+ self.local_ks_file.unlink()
+
# -------------------------------------------------------------------------
def exec_cobbler(self, cmd, no_simulate=False):
# -------------------------------------------------------------------------
def ensure_profile_ks(self):
- local_ks = self.base_dir / 'kickstart' / ('profile.' + self.cfg.cobbler_profile + '.ks')
+ prefix = 'tmp.' + self.cfg.cobbler_profile + '.'
+ (fh, tmp_ks) = tempfile.mkstemp(prefix=prefix, suffix='.ks', text=True)
+ os.close(fh)
+ self.local_ks_file = Path(tmp_ks)
+ LOG.debug(_("Using temporary kickstart file {!r}.").format(tmp_ks))
+
+ jinja_env = jinja2.Environment(
+ loader=jinja2.FileSystemLoader(str(self.base_dir / 'templates')),
+ autoescape=jinja2.select_autoescape(),
+ )
+ ks_template = jinja_env.get_template('el-standard.ks')
+ ks_content = ks_template.render(distro=self.cfg.current_distro) + '\n\n'
+ if self.verbose > 1:
+ LOG.debug(_("Generated kickstart file content:") + '\n' + ks_content)
+
+ self.local_ks_file.write_text(ks_content)
+
+ # local_ks = self.base_dir / 'kickstart' / ('profile.' + self.cfg.cobbler_profile + '.ks')
remote_ks = self.cfg.cobbler_profile_ks
LOG.info(_("Ensuring currentness of profile kickstart script {!r}.").format(
str(remote_ks)))
- self.ensure_remote_file(local_ks, remote_ks)
+ self.ensure_remote_file(self.local_ks_file, remote_ks)
+
+ LOG.debug(_("Removing {!r} ...").format(str(self.local_ks_file)))
+ self.local_ks_file.unlink()
+ self.local_ks_file = None
# -------------------------------------------------------------------------
def ensure_profile(self):
"""Ensure the existence and the correctnes of the given profile."""
- self.ensure_profile_ks()
profile = self.cfg.cobbler_profile
LOG.info(_("Ensuring profile {!r} ...").format(profile))
from .xlate import XLATOR
-__version__ = '1.9.4'
+__version__ = '1.9.5'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
valid_system_status = ('development', 'testing', 'acceptance', 'production')
default_system_status = 'development'
- default_cobbler_profile = 'vmware-template-' + default_os_id + '-' + default_system_status
+ default_cobbler_profile = 'vmware-template.' + default_os_id + '.' + default_system_status
default_swap_size_mb = 512
self.template_name = self.os_id + '-template'
if not self.cobbler_profile_given:
- self.cobbler_profile = 'vmware-template-' + self.os_id + '-' + self.system_status
+ self.cobbler_profile = 'vmware-template.' + self.os_id + '.' + self.system_status
self.verify_cobbler_distros()
from .xlate import XLATOR
-__version__ = '2.1.2'
+__version__ = '2.1.3'
LOG = logging.getLogger(__name__)
TZ = pytz.timezone('Europe/Berlin')
LOG.debug(_("Starting handling ..."))
self.cobbler.get_cobbler_version()
self.check_for_cobbler_distro()
- self.cobbler.ensure_system_ks()
+ self.cobbler.ensure_profile_ks()
return 0
self.cobbler.ensure_profile()
self.cobbler.ensure_root_authkeys()
self.cobbler.ensure_rsyslog_cfg_files()
self.cobbler.ensure_snippets()
self.cobbler.ensure_keys()
+ self.cobbler.ensure_system_ks()
self.cobbler.ensure_repo_files()
self.cobbler.ensure_bashrc()
self.cobbler.ensure_vimrc()