From: Frank Brehm Date: Mon, 22 Jun 2020 16:28:00 +0000 (+0200) Subject: Removing system from Cobbler after installing it X-Git-Tag: 2.1.2^2~9^2~31^2~7 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=5815aca1a70a361c132043e8bbc3f242020e73e7;p=pixelpark%2Fcreate-vmware-tpl.git Removing system from Cobbler after installing it --- diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 7634e88..9ba7442 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -40,7 +40,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.5.12' +__version__ = '0.6.1' LOG = logging.getLogger(__name__) @@ -692,7 +692,7 @@ class Cobbler(BaseHandler): profile = self.config.cobbler_profile os_id = self.config.os_id - LOG.info(_("Creating new sytem {!r} ...").format(name)) + LOG.info(_("Creating new system {!r} ...").format(name)) if not comment: comment = "VMWare template for creating a {} system.".format(os_id) @@ -748,6 +748,30 @@ class Cobbler(BaseHandler): self.sync() + # ------------------------------------------------------------------------- + def remove_system(self, name): + """Removing the given system.""" + + LOG.info(_("Removing system {!r} ...").format(name)) + + args = ['system', 'remove'] + args.append('--name') + args.append(name) + + proc = self.exec_cobbler(args) + + if proc.returncode: + err = _('No error message') + if proc.stderr: + err = proc.stderr + elif proc.stdout: + err = proc.stdout + msg = _("Error removing the cobbler system {n!r} - returncode was {rc}: {err}").format( + n=name, rc=proc.returncode, err=err) + raise ExpectedCobblerError(msg) + + self.sync() + # ------------------------------------------------------------------------- def sync(self): """Executing 'cobbler sync' to apply environment, especially DHCPD configuration.""" diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index e0ea6bb..30bf869 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -42,7 +42,7 @@ from .cobbler import CobblerError, Cobbler from .xlate import XLATOR -__version__ = '1.7.2' +__version__ = '1.7.3' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -310,7 +310,8 @@ class CrTplHandler(BaseHandler): return 10 else: self.poweroff_vm() -# self.change_mac_address() + + self.cobbler.remove_system(tpl_sysname) return 0