1 Title: Scripting the Cerebrum/bofhd user administration system using XML-RPC
2 Tags: english, sysadmin
5 <p>Where I work at the <a href="http://www.uio.no/">University of
7 <a href="http://sourceforge.net/projects/cerebrum/">Cerebrum user
8 administration system</a> to maintain users, groups, DNS, DHCP, etc.
9 I've known since the system was written that the server is providing
10 an <a href="http://en.wikipedia.org/wiki/XML-RPC">XML-RPC</a> API, but
11 I have never spent time to try to figure out how to use it, as we
12 always use the bofh command line client at work. Until today. I want
13 to script the updating of DNS and DHCP to make it easier to set up
14 virtual machines. Here are a few notes on how to use it with
17 <p>I started by looking at the source of the Java
18 <a href="http://cerebrum.svn.sourceforge.net/viewvc/cerebrum/trunk/cerebrum/clients/jbofh/">bofh
19 client</a>, to figure out how it connected to the API server. I also
20 googled for python examples on how to use XML-RPC, and found
21 <a href="http://tldp.org/HOWTO/XML-RPC-HOWTO/xmlrpc-howto-python.html">a
22 simple example in</a> the XML-RPC howto.</p>
24 <p>This simple example code show how to connect, get the list of
25 commands (as a JSON dump), and how to get the information about the
26 user currently logged in:</p>
32 server_url = 'https://cerebrum-uio.uio.no:8000';
33 username = getpass.getuser()
34 password = getpass.getpass()
35 server = xmlrpclib.Server(server_url);
36 #print server.get_commands(sessionid)
37 sessionid = server.login(username, password)
38 print server.run_command(sessionid, "user_info", username)
39 result = server.logout(sessionid)
43 <p>Armed with this knowledge I can now move forward and script the DNS
44 and DHCP updates I wanted to do.</p>