From 10ad449671f383177b2ee51ecbd7dfd98b613339 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 22 Dec 2006 11:15:58 -0500 Subject: Allow "cobbler enchant" commands to also remotely install Xen on systems in the same way the command already supported destructive re-provisioning. Syntax is "cobbler enchant --address=foo --profile=foo --virt=yes" or "--system=foo" can replace "--profile" if you want to set the Xen mac address and so forth. --- cobbler/action_enchant.py | 27 +++++++++++++++++++++------ cobbler/api.py | 4 ++-- cobbler/cobbler.py | 12 ++++++++++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cobbler/action_enchant.py b/cobbler/action_enchant.py index b77eabf..3007c5d 100644 --- a/cobbler/action_enchant.py +++ b/cobbler/action_enchant.py @@ -21,7 +21,7 @@ import traceback class Enchant: - def __init__(self,config,address,profile,system): + def __init__(self,config,address,profile,system,is_virt): """ Constructor. config: a configuration reference (see api module) @@ -33,6 +33,7 @@ class Enchant: self.address = address self.profile = profile self.system = system + self.is_virt = is_virt if address is None: raise cexceptions.CobblerException("enchant_failed","no address specified") if system is None and profile is None: @@ -71,6 +72,8 @@ class Enchant: known_hosts.write("\n") known_hosts.close() + # make sure the koan rpm is present, if it's not there, user didn't run sync first + # or it's not configured in /var/lib/cobbler/settings koan = os.path.basename(self.settings.koan_path) where_is_koan = os.path.join(self.settings.webdir,os.path.basename(koan)) if not os.path.exists(where_is_koan) or os.path.isdir(where_is_koan): @@ -78,14 +81,26 @@ class Enchant: try: self.ssh_exec("wget http://%s/cobbler/%s" % (self.settings.server, koan)) - self.ssh_exec("up2date install syslinux",catch_fail=False) - self.ssh_exec("yum -y install syslinux",catch_fail=False) + # koan doesn't require libvirt, but uses it for koan --virt options if available + # so, if --virt is requested, we have to make sure it's installed. + extra_virt_packages = "" + if self.is_virt: + extra_virt_packages = " libvirt-python libvirt xen" + # package installation without knowing whether the target is yum-based or not + self.ssh_exec("up2date install syslinux%s" % (extra_virt_packages), catch_fail=False) + self.ssh_exec("yum -y install syslinux%s" % (extra_virt_packages), catch_fail=False) self.ssh_exec("rpm -Uvh %s --force --nodeps" % koan) + # choose SSH command line based on whether this command was given --virt or not + operation = "--replace-self" + if self.is_virt: + operation = "--virt" if self.system: - self.ssh_exec("koan --replace-self --system=%s --server=%s" % (self.system, self.settings.server)) + self.ssh_exec("koan %s --system=%s --server=%s" % (operation, self.system, self.settings.server)) else: - self.ssh_exec("koan --replace-self --profile=%s --server=%s" % (self.profile, self.settings.server)) - self.ssh_exec("/sbin/reboot") + self.ssh_exec("koan %s --profile=%s --server=%s" % (operation, self.profile, self.settings.server)) + # don't have to reboot for virt installs + if not self.is_virt: + self.ssh_exec("/sbin/reboot") return True except: traceback.print_exc() diff --git a/cobbler/api.py b/cobbler/api.py index 2ebb2e6..50d500e 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -126,14 +126,14 @@ class BootAPI: sync = action_reposync.RepoSync(self._config) return sync.run(dryrun=dryrun) - def enchant(self,address,profile,systemdef): + def enchant(self,address,profile,systemdef,is_virt): """ Re-kickstart a running system. Either profile or systemdef should be a name of a profile or system definition, the other should be None. address is an address reachable by SSH. """ - enchant = action_enchant.Enchant(self._config,address,profile,systemdef) + enchant = action_enchant.Enchant(self._config,address,profile,systemdef,is_virt) return enchant.run() def import_tree(self,tree_path,mirror_url,mirror_name): diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py index e9274b8..1c2f5f1 100755 --- a/cobbler/cobbler.py +++ b/cobbler/cobbler.py @@ -231,6 +231,13 @@ class BootCLI: self.temp_profile = None self.temp_system = None self.temp_address = None + self.is_virt = False + def set_is_virt(a): + if a.lower() in [ "1", "true", "yes", "y", "on" ]: + self.is_virt = True + return True + elif a.lower() not in [ "0", "false", "no", "n", "off" ]: + return False def set_profile(a): self.temp_profile = a return True @@ -241,11 +248,12 @@ class BootCLI: self.temp_address = a return True def go_enchant(): - return self.api.enchant(self.temp_address,self.temp_profile,self.temp_system) + return self.api.enchant(self.temp_address,self.temp_profile,self.temp_system,self.is_virt) commands = { '--address' : lambda(a): set_address(a), '--profile' : lambda(a): set_profile(a), - '--system' : lambda(a): set_system(a) + '--system' : lambda(a): set_system(a), + '--virt' : lambda(a): set_is_virt(a) } on_ok = lambda: go_enchant() return self.apply_args(args,commands,on_ok) -- cgit