[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [et-mgmt-tools] Cobbler netboot_enable utility



On Wed, May 23, 2007 at 10:42:49AM -0400, Matt Hyclak enlightened us:
> I just shared this with Michael on IRC and he suggested I posted it to the
> list, so here it is. 
> 
> Running koan on a target machine seemed too cumbersome sometimes, so I wrote
> this little app to more or less flip the netboot_enabled bit on a system, so
> that you could run this utility:
> 
> cobbler_change_netboot.py enable mysystem
> 
> and simply reboot the target machine.
> 
> The next logical step, then, is to have the system phone home when it is
> finished reinstalling to flip the bit back to 0. I've done this in the past
> (on a homegrown system) by having the target wget a webpage which was a
> script that changed the status from 'reinstall' to 'installed'. This could
> also be done via some ssh magic.
> 
> I would also like to add in some sort of trigger ability much like cobbler
> has to do things like 'puppetca --clean hostname' when preparing for a
> reinstall.
> 
> This is a very basic proof of concept of the idea, but to be a good "release
> early, release often" type guy, here it is. 
> 

This time with an attachment...

Matt

-- 
Matt Hyclak
Department of Mathematics 
Department of Social Work
Ohio University
(740) 593-1263
#!/usr/bin/env python

from cobbler import api
import getopt, sys

def usage():
	print """
Usage: cobbler_change_netboot.py [-hv] COMMAND SYSTEMNAME
"""

def extended_usage():
	print """
Usage: cobbler_change_netboot.py [-hv] COMMAND SYSTEMNAME

Options:
	-h|--help			Print help
	-v|--verbose		Turns on more verbose messages

Commands:
	enable		Enables netboot for this system (causes reinstall)
	disable		Disables netboot for this system (causes default boot)
"""

def vprint(msg):
	try:
		if verbose:
			print msg
	except NameError:
		pass

try:
	opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose"])
except getopt.GetoptError:
	usage()
	sys.exit(1)

verbose = 0

for o, a in opts:
	if o in ("-h", "--help"):
		extended_usage()
		sys.exit(0)
	if o in ("-v", "--verbose"):
		verbose = 1

if len(args) != 2:
	usage()
	sys.exit(1)
else:
	command = args[0]
	systemname = args[1]

if command not in ["enable", "disable"]:
	extended_usage()
	sys.exit(1)
elif (command == "enable"):
	netboot = 1
else:
	netboot = 0
	

shoehorn = api.BootAPI()
systems = shoehorn.systems()

found = systems.find(systemname)

if (found):
	found.netboot_enabled = netboot
	retval = shoehorn.serialize()
	syncval = shoehorn.sync()

# vim:tabstop=4

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]