]> pere.pagekite.me Git - homepage.git/blob - blog/archive/2012/12/12.rss
Nytt oppslag.
[homepage.git] / blog / archive / 2012 / 12 / 12.rss
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
3 <channel>
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>
7
8
9 <item>
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>&lt;p&gt;Where I work at the &lt;a href=&quot;http://www.uio.no/&quot;&gt;University of
15 Oslo&lt;/a&gt;, we use the
16 &lt;a href=&quot;http://sourceforge.net/projects/cerebrum/&quot;&gt;Cerebrum user
17 administration system&lt;/a&gt; to maintain users, groups, DNS, DHCP, etc.
18 I&#39;ve known since the system was written that the server is providing
19 an &lt;a href=&quot;http://en.wikipedia.org/wiki/XML-RPC&quot;&gt;XML-RPC&lt;/a&gt; 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
24 Python.&lt;/p&gt;
25
26 &lt;p&gt;I started by looking at the source of the Java
27 &lt;a href=&quot;http://cerebrum.svn.sourceforge.net/viewvc/cerebrum/trunk/cerebrum/clients/jbofh/&quot;&gt;bofh
28 client&lt;/a&gt;, 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 &lt;a href=&quot;http://tldp.org/HOWTO/XML-RPC-HOWTO/xmlrpc-howto-python.html&quot;&gt;a
31 simple example in&lt;/a&gt; the XML-RPC howto.&lt;/p&gt;
32
33 &lt;p&gt;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:&lt;/p&gt;
36
37 &lt;blockquote&gt;&lt;pre&gt;
38 #!/usr/bin/env python
39 import getpass
40 import xmlrpclib
41 server_url = &#39;https://cerebrum-uio.uio.no:8000&#39;;
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, &quot;user_info&quot;, username)
48 result = server.logout(sessionid)
49 print result
50 &lt;/pre&gt;&lt;/blockquote&gt;
51
52 &lt;p&gt;Armed with this knowledge I can now move forward and script the DNS
53 and DHCP updates I wanted to do.&lt;/p&gt;
54 </description>
55 </item>
56
57 </channel>
58 </rss>