Hi, Attached patch creates a extra trigger (install/post) that is triggers by a cgi script (like nopxe.cgi) at the end of a installation. I've think I've covered all bases here but let me know if I missed something. Regards, Tim -- Tim Verhoeven - tim.verhoeven.be@xxxxxxxxx - 0479 / 88 11 83 Hoping the problem magically goes away by ignoring it is the "microsoft approach to programming" and should never be allowed. (Linus Torvalds)
diff --git a/MANIFEST.in b/MANIFEST.in index 7375351..1a7c3e3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -23,6 +23,7 @@ include scripts/cobblerd include scripts/findks.cgi include scripts/nopxe.cgi include scripts/webui.cgi +include scripts/postinstalltrigger.cgi include snippets/* recursive-include po *.pot recursive-include po *.po diff --git a/cobbler.spec b/cobbler.spec index 7bf245c..b3bbd85 100644 --- a/cobbler.spec +++ b/cobbler.spec @@ -78,6 +78,7 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT %dir /var/www/cgi-bin/cobbler/ /var/www/cgi-bin/cobbler/findks.cgi /var/www/cgi-bin/cobbler/nopxe.cgi +/var/www/cgi-bin/cobbler/postinstalltrigger.cgi /var/www/cgi-bin/cobbler/webui.cgi %defattr(660,apache,apache) %config(noreplace) /var/www/cgi-bin/cobbler/.htaccess @@ -167,6 +168,7 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT %dir /var/lib/cobbler/triggers/delete/repo/post %dir /var/lib/cobbler/triggers/sync/pre %dir /var/lib/cobbler/triggers/sync/post +%dir /var/lib/cobbler/triggers/install/post %dir /var/lib/cobbler/snippets/ %defattr(744,root,root) diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py index ad4143d..2943366 100644 --- a/cobbler/action_sync.py +++ b/cobbler/action_sync.py @@ -2,8 +2,9 @@ Builds out a TFTP/cobbler boot tree based on the object tree. This is the code behind 'cobbler sync'. -Copyright 2006, Red Hat, Inc +Copyright 2006,2007, Red Hat, Inc Michael DeHaan <mdehaan@xxxxxxxxxx> +Tim Verhoeven <tim.verhoeven.be@xxxxxxxxx> This software may be freely redistributed under the terms of the GNU general public license. @@ -389,6 +390,7 @@ class BootSync: pattern1 = "wget http://%s/cblr/watcher.py?%s_%s=%s -b" pattern2 = "wget http://%s/cgi-bin/cobbler/nopxe.cgi?system=%s -b" pattern3 = "wget http://%s/cobbler/%s/%s/ks.cfg -O /root/cobbler.ks" + pattern4 = "wget http://%s/cgi-bin/cobbler/postinstalltrigger.cgi?system=%s -b" blend_this = profile if system: @@ -402,6 +404,8 @@ class BootSync: buf = buf + pattern1 % (blended["server"], "system", "done", system.name) if str(self.settings.pxe_just_once).upper() in [ "1", "Y", "YES", "TRUE" ]: buf = buf + "\n" + pattern2 % (blended["server"], system.name) + if self.api.settings().run_postinstall_trigger: + buf = buf + "\n" + pattern4 % (blended["server"], system.name) if kickstart and os.path.exists(kickstart): buf = buf + "\n" + pattern3 % (blended["server"], "kickstarts_sys", system.name) diff --git a/cobbler/remote.py b/cobbler/remote.py index ff8d2db..0e30096 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -5,6 +5,7 @@ # # Copyright 2007, Red Hat, Inc # Michael DeHaan <mdehaan@xxxxxxxxxx> +# Tim Verhoeven <tim.verhoeven.be@xxxxxxxxx> # # This software may be freely redistributed under the terms of the GNU # general public license. @@ -145,6 +146,27 @@ class CobblerXMLRPCInterface: systems.add(obj,with_copy=True) return True + def run_postinstalltrigger(self,name,token=None): + """ + This is a feature used to run the post install trigger. + It passes the system named "name" to the trigger. Disabled by default as + this requires public API access and is technically a read-write operation. + """ + # used by postinstalltrigger.cgi + self.logger.debug("Starting run_postinstalltrigger") + self.api.clear() + self.api.deserialize() + if not self.api.settings().run_postinstall_trigger: + # feature disabled! + return False + systems = self.api.systems() + obj = systems.find(name=name) + if obj == None: + # system not found! + return False + utils.run_triggers(obj, "/var/lib/cobbler/triggers/install/post/*") + return True + def _refresh(self): """ Internal function to reload cobbler's configuration from disk. This is used to prevent any out diff --git a/cobbler/settings.py b/cobbler/settings.py index 8a3c7f7..43b3e06 100644 --- a/cobbler/settings.py +++ b/cobbler/settings.py @@ -43,6 +43,7 @@ DEFAULTS = { "manage_dhcp_mode" : "isc", "next_server" : "127.0.0.1", "pxe_just_once" : 0, + "run_postinstall_trigger" : 0, "server" : "127.0.0.1", "snippetsdir" : "/var/lib/cobbler/snippets", "syslog_port" : 25150, diff --git a/cobbler/webui/master.py b/cobbler/webui/master.py index 3eeb95e..89cf4a8 100644 --- a/cobbler/webui/master.py +++ b/cobbler/webui/master.py @@ -31,12 +31,12 @@ VFFSL=valueFromFrameOrSearchList VFSL=valueFromSearchList VFN=valueForName currentTime=time.time -__CHEETAH_version__ = '2.0' -__CHEETAH_versionTuple__ = (2, 0, 0, 'final', 0) -__CHEETAH_genTime__ = 1195069391.0795169 -__CHEETAH_genTimestamp__ = 'Wed Nov 14 14:43:11 2007' +__CHEETAH_version__ = '2.0rc8' +__CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 8) +__CHEETAH_genTime__ = 1196349031.5462351 +__CHEETAH_genTimestamp__ = 'Thu Nov 29 16:10:31 2007' __CHEETAH_src__ = 'webui_templates/master.tmpl' -__CHEETAH_srcLastModified__ = 'Wed Nov 7 12:24:52 2007' +__CHEETAH_srcLastModified__ = 'Thu Nov 29 14:40:41 2007' __CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine' if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple: diff --git a/config/settings b/config/settings index 85d6395..bc2949d 100644 --- a/config/settings +++ b/config/settings @@ -18,6 +18,7 @@ manage_dhcp: 0 manage_dhcp_mode: isc next_server: '127.0.0.1' pxe_just_once: 0 +run_postinstall_trigger: 0 server: '127.0.0.1' snippetsdir: /var/lib/cobbler/snippets syslog_port: 25150 diff --git a/scripts/postinstalltrigger.cgi b/scripts/postinstalltrigger.cgi new file mode 100755 index 0000000..ae2c270 --- /dev/null +++ b/scripts/postinstalltrigger.cgi @@ -0,0 +1,80 @@ +#!/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 disables the netboot flag for a given +# system if (and only if) pxe_just_once is enabled in settings. +# It must not be able to do anything else for security +# reasons. +# +# +# (C) Red Hat, 2007 +# Michael DeHaan <mdehaan@xxxxxxxxxx> +# Tim Verhoeven <tim.verhoeven.be@xxxxxxxxx> + +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:25151" + +#---------------------------------------------------------------------- + +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 disable(name): + """ + Determine if this feature is enabled. + """ + + #try: + xmlrpc_server = ServerProxy(XMLRPC_SERVER) + print xmlrpc_server.run_postinstalltrigger(name) + #except: + # print "# could not contact cobblerd at %s" % XMLRPC_SERVER + # sys.exit(1) + + return True + +#---------------------------------------------------------------------- + +def header(): + print "Content-type: text/plain" + print + +#---------------------------------------------------------------------- + +if __name__ == "__main__": + cgitb.enable(format='text') + header() + name = parse_query() + disable(name) + + diff --git a/setup.py b/setup.py index 04ba3ec..2a1acfc 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,7 @@ if __name__ == "__main__": # cgi files (cgipath, ['scripts/findks.cgi', 'scripts/nopxe.cgi']), - (cgipath, ['scripts/webui.cgi']), + (cgipath, ['scripts/webui.cgi', 'scripts/postinstalltrigger.cgi']), # miscellaneous config files (cgipath, ['config/.htaccess']), @@ -192,6 +192,7 @@ if __name__ == "__main__": ("%sdelete/repo/pre" % trigpath, []), ("%sdelete/repo/post" % trigpath, []), ("%sdelete/repo/post" % trigpath, []), + ("%sinstall/post" % trigpath, []), ("%ssync/pre" % trigpath, []), ("%ssync/post" % trigpath, [ "triggers/restart-services.trigger" ]) ],
_______________________________________________ et-mgmt-tools mailing list et-mgmt-tools@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/et-mgmt-tools