FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 04-09-2008, 03:39 AM
Garrett Honeycutt
 
Default Help using the Cobbler API in triggers

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")

Any help in that direction would be greatly appreciated.

Thanks,
-g

--
Garrett Honeycutt
Sr. Systems Engineer

www.speakeasy.net
Voice * Data * Managed Services

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 04-09-2008, 04:15 AM
Jennifer Cranfill
 
Default Help using the Cobbler API in triggers

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
 
Old 04-09-2008, 03:03 PM
Michael DeHaan
 
Default Help using the Cobbler API in triggers

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






_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 04-10-2008, 12:30 AM
Garrett Honeycutt
 
Default 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

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 04-10-2008, 02:52 PM
Michael DeHaan
 
Default Help using the Cobbler API in triggers

Garrett Honeycutt wrote:

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.


You do now




========= 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



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

Thread Tools




All times are GMT. The time now is 11:12 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org