Skip to content

Instantly share code, notes, and snippets.

@sjmh
Created January 25, 2016 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjmh/1950f594e21ec62c3895 to your computer and use it in GitHub Desktop.
Save sjmh/1950f594e21ec62c3895 to your computer and use it in GitHub Desktop.
import distutils.sysconfig
import sys
import salt.client
plib = distutils.sysconfig.get_python_lib()
mod_path = '{0}/cobbler'.format(plib)
sys.path.insert(0, mod_path)
def register():
# This registers the trigger as a post-install trigger
return '/var/lib/cobbler/triggers/install/pre/*'
def run(api, args, logger):
(objtype, name, ip) = args
if objtype != 'system':
# something bad happened here, so get out
return 0
system = api.find_system(name)
if not system:
# something worse - we couldn't find the system
# that just called us, so bail
return 0
if 'notify_qb' not in system.ks_meta and 'rid' not in system.ks_meta:
# don't touch systems that don't want to be flipped
return 0
caller = salt.client.Caller()
rid = system.ks_meta['rid']
data = {
'rid': rid,
'stage': 'pxe_wait',
'status': 'complete',
'pause': False,
}
if logger:
logger.info('Updating quickbase for record {0}'.format(rid))
# If oob = true, that means there is an OOB interface
# that is rebooting/pxe booting the host. If there is not
# an OOB interface, we need to execute the os_wait function
# by sending a 'next' event
oob = system.ks_meta.get('oob', 'false')
if oob == 'true':
caller.cmd('event.send', 'example/prov/v1/pxe_done/{0}'.format(rid), data)
elif oob == 'false':
caller.cmd('event.send', 'example/prov/v1/next', data)
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment