from .xlate import XLATOR
-__version__ = '0.8.6'
+__version__ = '0.8.7'
LOG = logging.getLogger(__name__)
if self.verbose > 1:
LOG.debug(_("Connecting to {h!r}, port {p} as {u!r} per SSH ...").format(
h=self.host, p=self.ssh_port, u=self.ssh_user))
- ssh.connect(
- self.host, port=self.ssh_port, timeout=self.ssh_timeout,
- username=self.ssh_user, key_filename=self.private_ssh_key)
- sftp = ssh.open_sftp()
+ if self.simulate:
+ if self.verbose > 1:
+ LOG.debug(_(
+ "Simulating SCP of {local!r} to {user}@{host}:{remote} ...").format(
+ local=str(local_file), user=self.ssh_user,
+ host=self.host, remote=str(remote_file)))
- if self.verbose > 1:
- LOG.debug(_("SCP of {local!r} to {host}@{remote} ...").format(
- local=str(local_file), host=self.host, remote=str(remote_file)))
- sftp.put(str(local_file), str(remote_file))
+ else:
+ ssh.connect(
+ self.host, port=self.ssh_port, timeout=self.ssh_timeout,
+ username=self.ssh_user, key_filename=self.private_ssh_key)
+
+ sftp = ssh.open_sftp()
+
+ if self.verbose > 1:
+ LOG.debug(_("SCP of {local!r} to {user}@{host}:{remote} ...").format(
+ local=str(local_file), user=self.ssh_user,
+ host=self.host, remote=str(remote_file)))
+
+ sftp.put(str(local_file), str(remote_file))
except SSHException as e:
msg = _("Could not connect via {w} to {user}@{host}: {e}").format(
return proc.stdout
# -------------------------------------------------------------------------
- def ensure_root_authkeys(self):
+ def ensure_root_authkeys(self, tmp_auth_keys_file=None):
bname = 'auth_keys_pp_betrieb'
- local_file = self.base_dir / 'keys' / bname
+ if tmp_auth_keys_file:
+ local_file = tmp_auth_keys_file
+ else:
+ local_file = self.base_dir / 'keys' / bname
remote_file = self.cfg.cobbler_ws_docroot / self.cfg.cobbler_ws_rel_filesdir / bname
self.ensure_remote_file(local_file, remote_file)
LOG.debug(_("Checking existing profile {!r} ...").format(profile))
remote_file = self.cfg.cobbler_profile_dir / (self.cfg.cobbler_profile + '.json')
+ return
+
fcontent = self.get_remote_filecontent(remote_file)
if self.verbose > 2:
LOG.debug(
LOG.info(_("Creating new profile {!r} ...").format(profile))
os_id = self.cfg.os_id
- comment = "Profile for creating a {} profile.".format(os_id)
+ distro_info = self.cfg.current_distro
+ comment = "Profile for creating a {} VM.".format(distro_info.description)
+
+ LOG.debug("Using kickstart file {!r}".format(self.cfg.cobbler_profile_ks))
+
+ repos = []
+ if distro_info.repos:
+ repos = distro_info.repos.as_list()
args = ['profile', 'add']
args.append('--name')
args.append(self.cfg.cobbler_profile)
args.append('--distro')
- args.append(self.cfg.cobbler_distro)
+ args.append(distro_info.distro)
args.append('--enable-menu')
args.append('1')
- args.append('--kickstart')
- args.append(str(self.cfg.cobbler_profile_ks))
- if self.cfg.cobbler_profile_repos:
+ if self.cfg.cobbler_major_version == 3:
+ args.append('--autoinstall')
+ args.append(str(self.cfg.cobbler_profile_ks.name))
+ else:
+ args.append('--kickstart')
+ args.append(str(self.cfg.cobbler_profile_ks))
+ if repos:
args.append('--repos')
- args.append(' '.join(self.cfg.cobbler_profile_repos))
+ args.append(' '.join(repos))
args.append('--comment')
args.append(comment)
args.append('--virt-cpus')
args.append('2')
args.append('--virt-file-size')
- args.append('32')
+ args.append('20')
args.append('--virt-ram')
args.append('4096')
args.append('--virt-type')
args.append('vmware')
args.append('--virt-bridge')
args.append('br0')
+ args.append('--virt-disk-driver')
+ args.append('vmdk')
args.append('--name-servers')
args.append(' '.join(self.cfg.cobbler_nameservers))
args.append('--name-servers-search')
proc = self.exec_cobbler(args)
+ if self.verbose > 1:
+ LOG.debug(_("Completed SSH process:") + "\n{}".format(proc))
+
if proc.returncode:
err = _('No error message')
if proc.stderr:
rc=proc.returncode, err=err)
raise ExpectedCobblerError(msg)
+ if proc.stderr:
+ msg = _("There was an error message on creating profile {!r}:").format(
+ self.cfg.cobbler_profile)
+ msg += ' ' + proc.stderr
+ LOG.error(msg)
+
+ if self.simulate:
+ return
+
+ profile_list = self.get_profile_list()
+ if self.cfg.cobbler_profile not in profile_list:
+ msg = _("Did not found profile {!r} after trying creation.").format(
+ self.cfg.cobbler_profile)
+ raise ExpectedCobblerError(msg)
+
# -------------------------------------------------------------------------
def ensure_system_ks(self):
return assigments[mac]
return None
+ # -------------------------------------------------------------------------
+ def ensure_webroot(self):
+
+ docroot = self.cfg.cobbler_ws_docroot / self.cfg.cobbler_ws_rel_filesdir
+ webroot = docroot / self.cfg.system_status
+ desc = _("Webroot directory")
+ LOG.info(_("Ensuring existence of {what} {dir!r}...").format(what=desc, dir=webroot))
+
+ self.ensure_remote_directory(webroot, desc)
+
# =============================================================================
if __name__ == "__main__":
from .xlate import XLATOR
-__version__ = '2.2.2'
+__version__ = '2.2.3'
LOG = logging.getLogger(__name__)
TZ = pytz.timezone('Europe/Berlin')
LOG.debug(_("Closing ..."))
self.vsphere.disconnect()
self.vsphere = None
+ 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()
return retval
# -------------------------------------------------------------------------
def run(self):
+ if self.verbose > 1:
+ LOG.debug(_("Current configuration:") + '\n' + pp(self.cfg.as_dict()))
+
LOG.debug(_("Starting handling ..."))
self.cobbler.get_cobbler_version()
self.check_for_cobbler_distro()
self.cobbler.ensure_profile_ks()
self.create_root_authkeys()
- return 0
self.cobbler.ensure_profile()
- self.cobbler.ensure_root_authkeys()
+ self.cobbler.ensure_webroot()
+ self.cobbler.ensure_root_authkeys(self.auth_keys_file)
self.cobbler.ensure_rsyslog_cfg_files()
self.cobbler.ensure_snippets()
self.auth_keys_file.unlink()
self.auth_keys_file = None
+ return 0
self.cobbler.ensure_system_ks()
self.cobbler.ensure_repo_files()
self.cobbler.ensure_bashrc()
auth_keys += used_key + '\n'
auth_keys += line
- if self.verbose > 1:
+ if self.verbose > 2:
msg = _("Generated authorized keys for root:") + '\n' + auth_keys
LOG.debug(msg)