Skip to content

Instantly share code, notes, and snippets.

@handyman5
Created March 19, 2012 19:54
Show Gist options
  • Save handyman5/2125931 to your computer and use it in GitHub Desktop.
Save handyman5/2125931 to your computer and use it in GitHub Desktop.
Use of the Cobbler API
cobbler_api = ServerProxy("http://cobbler/cobbler_api")
token = cobbler_api.login("USERNAME", "PASSWORD")
asset_list = ["server01", "server02"]
for system in asset_list:
print "Managing system %s" % system
print "System name is %s" % a
try:
handle = cobbler_api.get_system_handle(a, token)
if handle and options.skip:
continue
cobbler_api.remove_system(a, token)
except Error:
pass
handle = cobbler_api.new_system(token)
try:
for k, v in get_data(a):
print "Updating system %s with %s = %s" % (a.name, k, v)
cobbler_api.modify_system(handle, k, v, token)
cobbler_api.save_system(handle, token)
except Fault as e:
print str(e)
##############
# implementation of get_data omitted for brevity
# output looks like:
#
# {'modify_interface': {'dnsname-eth0': 'hostname.fqdn',
# 'ipaddress-eth0': '1.2.3.4',
# 'macaddress-eth0': '00:01:02:03:04:05',
# 'static-eth0': True,
# 'staticroutes-eth0': '0.0.0.0/0:1.1.1.1',
# 'subnet-eth0': '255.255.255.0'},
# 'name': 'server01',
# 'profile': 'cobbler-profile-name'}
##############
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment