Created
March 19, 2012 19:54
-
-
Save handyman5/2125931 to your computer and use it in GitHub Desktop.
Use of the Cobbler API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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