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

Re: [et-mgmt-tools] Help using the Cobbler API in triggers



Michael DeHaan wrote:
Jennifer Cranfill wrote:
Garrett Honeycutt wrote:
My goal is to access a variable within Cobbler, $hostname for example,
and use that in a trigger that is run whenever a system is added. Below
is some pseudo code to demonstrate my aim.

os.system("/usr/local/sbin/dostuff.sh $hostname")

Cobbler passes the name of the system as the first argument to the command. If your system name is the hostname, then in python you can just use something simple like:

machine = sys.argv[1]

If your system name is not the hostname then you can query the hostname of the system from Cobbler. Here is some python code I've been using:

from cobbler import api
cobbler_api = api.BootAPI()
systems = cobbler_api.systems()
box = systems.find(sys.argv[1])

I'm sure there are other (and probably better) ways as well.

--
Jennifer Cranfill
Systems Engineer
Sony Pictures Imageworks

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools redhat com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

Right! I added that example here -- https://fedorahosted.org/cobbler/wiki/CobblerTriggers -- so other people could find it when they were
reading the docs.

Thanks!


--Michael

Thank you for all of your help. This is what I came up, not sure how optimal it is, as I do not code python.

========= getcert.trigger - add/system/post trigger ===========
#!/usr/bin/python

import os
import sys

from cobbler import api
cobbler_api = api.BootAPI()

# this is the systemname, not the hostname, so be sure to use the FQDN in the systemname
machine = sys.argv[1]

# location of getcert.sh script
getcert_cmd = "/usr/local/sbin/getcert.sh"

# set return code to 0 by default
rc = 0

# build the command string
cmd = getcert_cmd + " " + machine

# log to cobbler's logs
cobbler_api.log("running - " + cmd)

# run the command and set the return code
rc = os.system(cmd)

# exit with return code
sys.exit(rc)

==== end code ====

This allows me to run a script when I add a system that will pre-generate puppet certs.

-g

--
Garrett Honeycutt
Sr. Systems Engineer

www.speakeasy.net
Voice * Data * Managed Services


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