Where I work at the University of Oslo, we use the Cerebrum user administration system to maintain users, groups, DNS, DHCP, etc. I've known since the system was written that the server is providing an XML-RPC API, but I have never spent time to try to figure out how to use it, as we always use the bofh command line client at work. Until today. I want to script the updating of DNS and DHCP to make it easier to set up virtual machines. Here are a few notes on how to use it with Python.
I started by looking at the source of the Java bofh client, to figure out how it connected to the API server. I also googled for python examples on how to use XML-RPC, and found a simple example in the XML-RPC howto.
This simple example code show how to connect, get the list of commands (as a JSON dump), and how to get the information about the user currently logged in:
#!/usr/bin/env python import getpass import xmlrpclib server_url = 'https://cerebrum-uio.uio.no:8000'; username = getpass.getuser() password = getpass.getpass() server = xmlrpclib.Server(server_url); #print server.get_commands(sessionid) sessionid = server.login(username, password) print server.run_command(sessionid, "user_info", username) result = server.logout(sessionid) print result
Armed with this knowledge I can now move forward and script the DNS and DHCP updates I wanted to do.