From 2ccbb4b130afac3d1707433b3988259ea109db7f Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 15 Apr 2008 17:34:50 -0400 Subject: Replaced the existing cobbler pre/post install triggers system with a much more flexible model that (for each system) passes in the following. First arg: the word "system" or "profile", Second arg: the name of the said system or profile, Third: the MAC if available, Fourth: the IP. This is all logged by a default "status" trigger to /var/log/cobbler/install.log, for being read by the soon-to-be-revamped cobbler check. The check system logs all of this in order, followed by the word "start" or "stop", followed by the number of seconds since Epoch. --- scripts/install_trigger.cgi | 92 ++++++++++++++++++++++++++++++++++++++++ scripts/post_install_trigger.cgi | 72 ------------------------------- 2 files changed, 92 insertions(+), 72 deletions(-) create mode 100644 scripts/install_trigger.cgi delete mode 100644 scripts/post_install_trigger.cgi (limited to 'scripts') diff --git a/scripts/install_trigger.cgi b/scripts/install_trigger.cgi new file mode 100644 index 0000000..493591f --- /dev/null +++ b/scripts/install_trigger.cgi @@ -0,0 +1,92 @@ +#!/usr/bin/env python + +# This software may be freely redistributed under the terms of the GNU +# general public license. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# This script runs post install triggers in /var/lib/cobbler/triggers/install/post +# if the triggers are enabled in the settings file. +# +# (C) Tim Verhoeven , 2007 +# tweaked: Michael DeHaan , 2007-2008 + +import cgi +import cgitb +import time +import os +import sys +import socket +import xmlrpclib +from cobbler import sub_process as sub_process + +COBBLER_BASE = "/var/www/cobbler" +XMLRPC_SERVER = "http://127.0.0.1/cobbler_api" + +#---------------------------------------------------------------------- + +class ServerProxy(xmlrpclib.ServerProxy): + + def __init__(self, url=None): + xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) + +#---------------------------------------------------------------------- + +def parse_query(): + """ + Read arguments from query string. + """ + + form = cgi.parse() + + mac = "?" + if os.environ.has_key("HTTP_X_RHN_PROVISIONING_MAC_0"): + devicepair = os.environ["HTTP_X_RHN_PROVISIONING_MAC_0"] + mac = devicepair.split()[1].strip() + + ip = "?" + if os.environ.has_key("REMOTE_ADDR"): + ip = os.environ["REMOTE_ADDR"] + + name = "?" + objtype = "?" + if form.has_key("system"): + name = form["system"][0] + objtype = "system" + elif form.has_key("profile"): + name = form["profile"][0] + objtype = "profile" + + mode = "?" + if form.has_key("mode"): + mode = form["mode"][0] + + return (mode,objtype,name,mac,ip) + +def invoke(mode,objtype,name,mac,ip): + """ + Determine if this feature is enabled. + """ + + xmlrpc_server = ServerProxy(XMLRPC_SERVER) + print xmlrpc_server.run_install_triggers(mode,objtype,name,mac,ip) + + return True + +#---------------------------------------------------------------------- + +def header(): + print "Content-type: text/plain" + print + +#---------------------------------------------------------------------- + +if __name__ == "__main__": + cgitb.enable(format='text') + header() + (mode,objtype,name,mac,ip) = parse_query() + invoke(mode,objtype,name,mac,ip) + + diff --git a/scripts/post_install_trigger.cgi b/scripts/post_install_trigger.cgi deleted file mode 100644 index 4a79c8b..0000000 --- a/scripts/post_install_trigger.cgi +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# This software may be freely redistributed under the terms of the GNU -# general public license. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# This script runs post install triggers in /var/lib/cobbler/triggers/install/post -# if the triggers are enabled in the settings file. -# -# (C) Tim Verhoeven , 2007 -# tweaked: Michael DeHaan - -import cgi -import cgitb -import time -import os -import sys -import socket -import xmlrpclib -from cobbler import sub_process as sub_process - -COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1/cobbler_api" - -#---------------------------------------------------------------------- - -class ServerProxy(xmlrpclib.ServerProxy): - - def __init__(self, url=None): - xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) - -#---------------------------------------------------------------------- - -def parse_query(): - """ - Read arguments from query string. - """ - - form = cgi.parse() - - if form.has_key("system"): - return form["system"][0] - return 0 - -def invoke(name): - """ - Determine if this feature is enabled. - """ - - xmlrpc_server = ServerProxy(XMLRPC_SERVER) - print xmlrpc_server.run_post_install_triggers(name) - - return True - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - cgitb.enable(format='text') - header() - name = parse_query() - invoke(name) - - -- cgit