self.local_ks_file.unlink()
# -------------------------------------------------------------------------
- def exec_cobbler(self, cmd, no_simulate=False):
+ def exec_cobbler(self, cmd, no_simulate=False, show_output=True):
simulate = self.simulate
if no_simulate:
cmds.append(c)
cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmds))
- return self.exec_ssh(cmd_str)
+ LOG.debug("Exec cobbler: " + cmd_str)
+ return self.exec_ssh(cmd_str, show_output=show_output)
# -------------------------------------------------------------------------
- def exec_ssh(self, cmd):
+ def exec_ssh(self, cmd, show_output=False):
ssh = None
proc = None
output = to_str(stdout.read()).strip()
err = to_str(stderr.read()).strip()
+ if show_output:
+ if output == '' and err == '':
+ LOG.debug(_("No output."))
+ if output:
+ LOG.debug(_("Output on {}:").format('STDOUT') + ' ' + output)
+ if err:
+ LOG.debug(_("Output on {}:").format('STDERR') + ' ' + err)
+
proc = CompletedProcess(cmd, retcode, output, err, start_dt=start_dt, end_dt=end_dt)
except SSHException as e:
def get_cobbler_version(self):
"""Trying to evaluate the version of Cobbler on the cobbler host."""
- proc = self.exec_cobbler('version', no_simulate=True)
+ proc = self.exec_cobbler('version', no_simulate=True, show_output=False)
if proc.returncode != 0:
err = _('No error message')
"""Trying to get a list of all configured distros."""
distro_list = []
- proc = self.exec_cobbler(('distro', 'list'), no_simulate=True)
+ proc = self.exec_cobbler(('distro', 'list'), no_simulate=True, show_output=False)
for line in proc.stdout.splitlines():
distro = line.strip()
if distro:
repo_list = []
- proc = self.exec_cobbler(('repo', 'list'), no_simulate=True)
+ proc = self.exec_cobbler(('repo', 'list'), no_simulate=True, show_output=False)
for line in proc.stdout.splitlines():
repo = line.strip()
if repo:
"""Trying to get a list of all configured cobbler profiles."""
profile_list = []
- proc = self.exec_cobbler(('profile', 'list'), no_simulate=True)
+ proc = self.exec_cobbler(('profile', 'list'), no_simulate=True, show_output=False)
for line in proc.stdout.splitlines():
profile = line.strip()
if profile:
cmd = ('profile', 'dumpvars', '--name', profile)
- proc = self.exec_cobbler(cmd, no_simulate=True)
+ proc = self.exec_cobbler(cmd, no_simulate=True, show_output=False)
vars_out += proc.stdout
parser = configparser.RawConfigParser(**kwargs)
ks_meta = ' '.join(ks_meta_list)
args = ['system', 'add']
- args.append('--clobber')
+ # args.append('--clobber')
args.append('--name')
args.append(name)
args.append('--profile')
args.append('--comment')
args.append(comment)
if ks_meta:
- args.append('--ksmeta')
+ if self.cfg.cobbler_major_version == 3:
+ args.append('--autoinstall-meta')
+ else:
+ args.append('--ksmeta')
args.append(ks_meta)
- args.append('--kickstart')
- args.append(str(self.cfg.system_ks))
+ # args.append('--kickstart')
+ # args.append(str(self.cfg.system_ks))
args.append('--power-type')
args.append('apc')
args.append('--hostname')
def sync(self):
"""Executing 'cobbler sync' to apply environment, especially DHCPD configuration."""
- proc = self.exec_cobbler('sync')
+ proc = self.exec_cobbler('sync', show_output=False)
+ LOG.info(_("Executing cobbler sync ..."))
if proc.returncode != 0:
err = _('No error message')
if not self.cfg.os_id:
msg = _("No ID for Operating system defined, please check the configuration.")
raise HandlerError(msg)
+
+ distro_info = self.cfg.current_distro
+
cur_ts = datetime.datetime.now()
cur_ts_str = cur_ts.strftime('%Y-%m-%d-%H-%M-%S')
- self.tpl_vm_hostname = self.cfg.os_id + '-' + cur_ts_str
+ self.tpl_vm_hostname = distro_info.shortname + '-' + cur_ts_str
if initialized:
self.initialized = True
self.cobbler.ensure_create_motd()
self.cobbler.ensure_postfix_files()
self.cobbler.ensure_logrotate_files()
- return 0
print_section_start('vmw_info', 'Collecting VMWare info', collapsed=True)
self.vsphere.get_about()
if self.tpl_vm:
LOG.debug(_("Created VM as {cls}: {vm!r}").format(
cls=self.tpl_vm.__class__.__name__, vm=self.tpl_vm))
- for device in self.tpl_vm.cfg.hardware.device:
+ for device in self.tpl_vm.config.hardware.device:
if isinstance(device, vim.vm.device.VirtualEthernetCard):
self.tpl_macaddress = device.macAddress
LOG.debug(_("Found Ethernet card as {}.").format(
def _get_storage_pod_obj(self, used_c_name):
content = self.vsphere.service_instance.RetrieveContent()
- dc = self.vsphere.get_obj(content, [vim.Datacenter], self.cfg.dc)
+ dc = self.vsphere.get_obj(content, [vim.Datacenter], self.cfg.vsphere_info.dc)
if not dc:
- raise VSphereDatacenterNotFoundError(self.cfg.dc)
+ raise VSphereDatacenterNotFoundError(self.cfg.vsphere_info.dc)
for child in dc.datastoreFolder.childEntity:
pod = self._get_storage_pod_obj_rec(child, used_c_name)