summaryrefslogtreecommitdiffstats
path: root/cobbler
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2006-10-17 17:12:04 -0400
committerJim Meyering <jim@meyering.net>2006-10-17 17:12:04 -0400
commit77dbf67da82126d7aa8edbdb187a14914f4ee0ee (patch)
tree024b4a6341d709c45e097e435528e988651a5563 /cobbler
parent85502c7f1df16b3500a9b1acb866ad77e0bf7545 (diff)
downloadthird_party-cobbler-77dbf67da82126d7aa8edbdb187a14914f4ee0ee.tar.gz
third_party-cobbler-77dbf67da82126d7aa8edbdb187a14914f4ee0ee.tar.xz
third_party-cobbler-77dbf67da82126d7aa8edbdb187a14914f4ee0ee.zip
Working on removing the dependancy on pexpect
Diffstat (limited to 'cobbler')
-rw-r--r--cobbler/action_enchant.py36
-rw-r--r--cobbler/api.py10
-rwxr-xr-xcobbler/cobbler.py63
-rw-r--r--cobbler/cobbler_msg.py2
4 files changed, 57 insertions, 54 deletions
diff --git a/cobbler/action_enchant.py b/cobbler/action_enchant.py
index c3d71b3..8e9835e 100644
--- a/cobbler/action_enchant.py
+++ b/cobbler/action_enchant.py
@@ -17,14 +17,19 @@ import cexceptions
import os
import os.path
import pexpect
-import pxssh
+# GOING AWAY
+# import pxssh
+import sub_process
import traceback
class Enchant:
- def __init__(self,config,sysname,password=''):
+ def __init__(self,config,sysname,profile):
"""
- Constructor. If password is None it should rely on SSH key auth.
+ Constructor.
+ config: a configuration reference (see api module)
+ sysname: address of system to enchant (not necc. defined in cobbler)
+ profile: profile to make the system become
"""
self.config = config
self.settings = self.config.settings()
@@ -33,15 +38,12 @@ class Enchant:
if sysname is None:
raise cexceptions.CobblerException("enchant_failed","no system name specified")
self.profile = ''
- self.password = password
- def call(self,cmd):
+ def ssh_exec(self,cmd):
"""
- Invoke something over SSH.
+ Invoke an SSH command.
"""
- print "ssh -> %s" % cmd
- self.ssh.sendline(cmd)
- self.ssh.prompt()
+ sub_process.call("ssh root:%s %s" % (self.sysname,cmd),shell=True)
def run(self):
"""
@@ -60,17 +62,11 @@ class Enchant:
raise cexceptions.CobblerException("enchant_failed","koan is missing")
try:
- ssh = self.ssh = pxssh.pxssh()
- if not ssh.login(self.sysname, self.username, self.password):
- raise cexceptions.CobblerException("enchant_failed","SSH login denied")
- else:
- self.call("wget http://%s/cobbler/%s" % (self.settings.server, koan))
- # nodeps allows installation on older pythons
- # koan will move to /usr/share/koan shortly
- self.call("rpm -Uvh %s --force --nodeps" % koan)
- self.call("koan --replace-self --profile=%s --server=%s" % (self.profile, self.settings.server))
- #self.call("/sbin/reboot")
- return True
+ 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(self.sysname, "/sbin/reboot")
+ return True
except:
traceback.print_exc()
raise cexceptions.CobblerException("enchant_failed","exception")
diff --git a/cobbler/api.py b/cobbler/api.py
index bc95a29..0282c43 100644
--- a/cobbler/api.py
+++ b/cobbler/api.py
@@ -108,12 +108,14 @@ class BootAPI:
sync = action_sync.BootSync(self._config)
return sync.run(dryrun=dryrun)
- def enchant(self,sysname,password):
+ def enchant(self,address,profile,systemdef):
"""
- Apply a system profile to a running remote system, replacing
- the current OS.
+ 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,sysname,password)
+ enchant = action_enchant.Enchant(self._config,address,profile,systemdef)
return enchant.run()
def import_tree(self,tree_path,mirror_url,mirror_name):
diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py
index 8d23dbc..7ff3fcd 100755
--- a/cobbler/cobbler.py
+++ b/cobbler/cobbler.py
@@ -48,27 +48,27 @@ class BootCLI:
'remove' : self.profile_remove,
}
self.commands['system'] = {
- 'add' : self.system_edit,
- 'edit' : self.system_edit,
- 'delete' : self.system_remove,
- 'remove' : self.system_remove,
- 'enchant' : self.system_enchant,
- 'transmogrify' : self.system_enchant
+ 'add' : self.system_edit,
+ 'edit' : self.system_edit,
+ 'delete' : self.system_remove,
+ 'remove' : self.system_remove,
}
self.commands['toplevel'] = {
- 'check' : self.check,
- 'list' : self.list,
- 'distros' : self.distro,
- 'distro' : self.distro,
- 'profiles' : self.profile,
- 'profile' : self.profile,
- 'systems' : self.system,
- 'system' : self.system,
- 'sync' : self.sync,
- 'import' : self.import_tree,
- 'help' : self.usage,
- '--help' : self.usage,
- '/?' : self.usage
+ 'check' : self.check,
+ 'list' : self.list,
+ 'distros' : self.distro,
+ 'distro' : self.distro,
+ 'profiles' : self.profile,
+ 'profile' : self.profile,
+ 'systems' : self.system,
+ 'system' : self.system,
+ 'sync' : self.sync,
+ 'import' : self.import_tree,
+ 'enchant' : self.enchant,
+ 'transmogrify' : self.enchant,
+ 'help' : self.usage,
+ '--help' : self.usage,
+ '/?' : self.usage
}
def run(self):
@@ -125,24 +125,29 @@ class BootCLI:
return self.apply_args(args,commands,on_ok)
- def system_enchant(self,args):
+ def enchant(self,args):
"""
Reinstall a system:
'cobbler system enchant --name='foo' [--password='foo']
"""
- self.temp_password = ''
- self.temp_name = ''
- def set_password(a):
- self.temp_password = a
+ self.temp_profile = None
+ self.temp_system = None
+ self.temp_address = None
+ def set_profile(a):
+ self.temp_profile = a
return True
- def set_name(a):
- self.temp_name = a
+ def set_system(a):
+ self.temp_system = a
+ return True
+ def set_address(a):
+ self.temp_address = a
return True
def go_enchant():
- return self.api.enchant(self.temp_name,self.temp_password)
+ return self.api.enchant(self.temp_address,self.temp_profile,self.temp_system)
commands = {
- '--name' : lambda(a): set_name(a),
- '--password' : lambda(a): set_password(a),
+ '--address' : lambda(a): set_address(a),
+ '--profile' : lambda(a): set_profile(a),
+ '--system' : lambda(a): set_system(a)
}
on_ok = lambda: go_enchant()
return self.apply_args(args,commands,on_ok)
diff --git a/cobbler/cobbler_msg.py b/cobbler/cobbler_msg.py
index d9d904d..a77e537 100644
--- a/cobbler/cobbler_msg.py
+++ b/cobbler/cobbler_msg.py
@@ -42,7 +42,7 @@ cobbler list
cobbler sync
-cobbler system enchant --name=<string> [--password=<string>]
+cobbler enchant --address=<ip|hostname> [--profile=<string>|--system=<string>]
"""
_msg_table = {