]> pere.pagekite.me Git - homepage.git/commitdiff
New post.
authorPetter Reinholdtsen <pere@hungry.com>
Thu, 6 Dec 2012 09:24:13 +0000 (09:24 +0000)
committerPetter Reinholdtsen <pere@hungry.com>
Thu, 6 Dec 2012 09:24:13 +0000 (09:24 +0000)
blog/data/2012-12-06-bofhd-scripting.txt [new file with mode: 0644]

diff --git a/blog/data/2012-12-06-bofhd-scripting.txt b/blog/data/2012-12-06-bofhd-scripting.txt
new file mode 100644 (file)
index 0000000..a74babd
--- /dev/null
@@ -0,0 +1,42 @@
+Title: Scripting the Cerebrum/bofhd user administration system using XML-RPC
+Tags: english
+Date: 2012-12-06 10:30
+
+<p>Where I work at the <a href="http://www.uio.no/">University of
+Oslo</a>, we use the
+<a href="http://sourceforge.net/projects/cerebrum/">Cerebrum user
+administration system</a> to maintain users, groups, DNS, DHCP, etc.
+I've known since the system was written that the server was providing
+an <a href="http://en.wikipedia.org/wiki/XML-RPC">XML-RPC</a> API, but
+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.  Here are a few
+notes on how to use it with Python.</p>
+
+<p>I started by looking at the source of the Java
+<a href="http://cerebrum.svn.sourceforge.net/viewvc/cerebrum/trunk/cerebrum/clients/jbofh/">bofh
+client</a>, 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 href="http://tldp.org/HOWTO/XML-RPC-HOWTO/xmlrpc-howto-python.html">a
+simple example in</a> the XML-RPC howto.</p>
+
+<p>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:</p>
+
+<blockquote><pre>
+#!/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
+</pre></blockquote>
+
+<p>Armed with this knowledge I can now move forward and script the DNS
+and DHCP updates I wanted to do.</p>