diff options
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | cobbler/action_enchant.py | 48 |
2 files changed, 31 insertions, 25 deletions
@@ -11,11 +11,11 @@ This means Cobbler now builds very easily on RHEL 4. As a result, this means that to run "enchant" a remote system, that system needs to have the cobbler server in the /root/.ssh/authorized_keys -file. Removing password functionality is more secure and should be -considered goodness. +file or the password will be prompted for multiple times. Use ssh-agent +if this is undesirable. -In addition, the arguments to "enchant" have changed. See the manpage -for details. +In addition, the arguments to "enchant" have changed to make it more +flexible. See the manpage for details. =================================== 0.2.6 -- Cheetah no longer required diff --git a/cobbler/action_enchant.py b/cobbler/action_enchant.py index 8e9835e..6c32d16 100644 --- a/cobbler/action_enchant.py +++ b/cobbler/action_enchant.py @@ -16,15 +16,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import cexceptions import os import os.path -import pexpect -# GOING AWAY -# import pxssh import sub_process import traceback class Enchant: - def __init__(self,config,sysname,profile): + def __init__(self,config,address,profile,system): """ Constructor. config: a configuration reference (see api module) @@ -33,38 +30,47 @@ class Enchant: """ self.config = config self.settings = self.config.settings() - self.username = "root" - self.sysname = sysname - if sysname is None: - raise cexceptions.CobblerException("enchant_failed","no system name specified") - self.profile = '' + self.address = address + self.profile = profile + self.system = system + if address is None: + raise cexceptions.CobblerException("enchant_failed","no address specified") + if system is None and profile is None: + raise cexceptions.CobblerException("enchant_failed","no profile specified") + if system is not None and self.config.systems().find(system) is None: + raise cexceptions.CobblerException("enchant_failed","system name not found") + if profile is not None and self.config.profiles().find(profile) is None: + raise cexceptions.CobblerException("enchant_failed","profile name not found") - def ssh_exec(self,cmd): + def ssh_exec(self,cmd,catch_fail=True): """ Invoke an SSH command. """ - sub_process.call("ssh root:%s %s" % (self.sysname,cmd),shell=True) + cmd2 = "ssh root@%s %s" % (self.address,cmd) + print "running: %s" % cmd2 + rc = sub_process.call(cmd2,shell=True) + print "returns: %d" % rc + if catch_fail and rc != 0: + raise cexceptions.CobblerException("enchant_failed","ssh failure") def run(self): """ Replace the OS of a remote system. """ koan = os.path.basename(self.settings.koan_path) - sys = self.config.systems().find(self.sysname) - if sys is None: - raise cexceptions.CobblerException("enchant_failed","system not in cobbler database") - pro = self.config.profiles().find(sys.profile) - self.profile = pro.name - if pro is None: - raise cexceptions.CobblerException("enchant_failed","no such profile for system (%s): %s" % (self.sysname, self.profile)) where_is_koan = os.path.join(self.settings.webdir,os.path.basename(koan)) if not os.path.exists(where_is_koan): raise cexceptions.CobblerException("enchant_failed","koan is missing") try: - self.ssh_exec(self.sysname, "wget http://%s/cobbler/%s" % (self.settings.server, koan)) - self.ssh_exec(self.sysname, "rpm -Uvh %s --force --nodeps" % koan)) - self.ssh_exec(self.sysname, "koan --replace-self --profile=%s --server=%s" % (self.profile, self.settings.server)) + 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) + self.ssh_exec("rpm -Uvh %s --force --nodeps" % koan) + if self.system: + self.ssh_exec("koan --replace-self --system=%s --server=%s" % (self.system, self.settings.server)) + else: + self.ssh_exec("koan --replace-self --profile=%s --server=%s" % (self.profile, self.settings.server)) # self.ssh_exec(self.sysname, "/sbin/reboot") return True except: |