diff options
| author | Michael DeHaan <mdehaan@redhat.com> | 2008-04-15 17:34:50 -0400 |
|---|---|---|
| committer | Michael DeHaan <mdehaan@redhat.com> | 2008-04-15 17:34:50 -0400 |
| commit | 2ccbb4b130afac3d1707433b3988259ea109db7f (patch) | |
| tree | 40b7a789997832f510acc7bed20a851f26f1cdbb /scripts/install_trigger.cgi | |
| parent | 51119d1acc532cfad68b9fe4a1daa945fe7cd3f0 (diff) | |
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.
Diffstat (limited to 'scripts/install_trigger.cgi')
| -rw-r--r-- | scripts/install_trigger.cgi | 92 |
1 files changed, 92 insertions, 0 deletions
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 <tim.verhoeven.be@gmail.com>, 2007 +# tweaked: Michael DeHaan <mdehaan@redhat.com>, 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) + + |
