1 <?xml version=
"1.0" encoding=
"ISO-8859-1"?>
2 <rss version='
2.0' xmlns:lj='http://www.livejournal.org/rss/lj/
1.0/'
>
4 <title>Petter Reinholdtsen - Entries from December
2012</title>
5 <description>Entries from December
2012</description>
6 <link>http://people.skolelinux.org/pere/blog/
</link>
10 <title>Scripting the Cerebrum/bofhd user administration system using XML-RPC
</title>
11 <link>http://people.skolelinux.org/pere/blog/Scripting_the_Cerebrum_bofhd_user_administration_system_using_XML_RPC.html
</link>
12 <guid isPermaLink=
"true">http://people.skolelinux.org/pere/blog/Scripting_the_Cerebrum_bofhd_user_administration_system_using_XML_RPC.html
</guid>
13 <pubDate>Thu,
6 Dec
2012 10:
30:
00 +
0100</pubDate>
14 <description><p
>Where I work at the
<a href=
"http://www.uio.no/
">University of
15 Oslo
</a
>, we use the
16 <a href=
"http://sourceforge.net/projects/cerebrum/
">Cerebrum user
17 administration system
</a
> to maintain users, groups, DNS, DHCP, etc.
18 I
've known since the system was written that the server is providing
19 an
<a href=
"http://en.wikipedia.org/wiki/XML-RPC
">XML-RPC
</a
> API, but
20 I have never spent time to try to figure out how to use it, as we
21 always use the bofh command line client at work. Until today. I want
22 to script the updating of DNS and DHCP to make it easier to set up
23 virtual machines. Here are a few notes on how to use it with
26 <p
>I started by looking at the source of the Java
27 <a href=
"http://cerebrum.svn.sourceforge.net/viewvc/cerebrum/trunk/cerebrum/clients/jbofh/
">bofh
28 client
</a
>, to figure out how it connected to the API server. I also
29 googled for python examples on how to use XML-RPC, and found
30 <a href=
"http://tldp.org/HOWTO/XML-RPC-HOWTO/xmlrpc-howto-python.html
">a
31 simple example in
</a
> the XML-RPC howto.
</p
>
33 <p
>This simple example code show how to connect, get the list of
34 commands (as a JSON dump), and how to get the information about the
35 user currently logged in:
</p
>
37 <blockquote
><pre
>
41 server_url =
'https://cerebrum-uio.uio.no:
8000';
42 username = getpass.getuser()
43 password = getpass.getpass()
44 server = xmlrpclib.Server(server_url);
45 #print server.get_commands(sessionid)
46 sessionid = server.login(username, password)
47 print server.run_command(sessionid,
"user_info
", username)
48 result = server.logout(sessionid)
50 </pre
></blockquote
>
52 <p
>Armed with this knowledge I can now move forward and script the DNS
53 and DHCP updates I wanted to do.
</p
>