an example using regular python
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 18 Dec 2008 20:50:46 +0000 (20:50 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 18 Dec 2008 20:50:46 +0000 (20:50 +0000)
doc/PLCAPI.xml.in

index b3777a0..2f04d35 100644 (file)
@@ -419,6 +419,49 @@ nodes = GetNodes([121], ['node_id', 'hostname'])
 nodes = plc.GetNodes([121], ['node_id', 'hostname'])
       </programlisting>
     </section>
+
+  <section id='standalone'>
+    <title>Using regular python</title>
+
+    <para>It is also possible to write simple regular-python scripts,
+    as illustrated in the example below. The only difference is that
+    all API calls need to be passed a first argument for
+    athenticating:</para>
+
+<programlisting>
+#!/usr/bin/env python
+
+import xmlrpclib
+
+plc_host='www.planet-lab.eu'
+login='thierry.parmentelat@sophia.inria.fr'
+password='xxxxxxxx'
+
+slice_name='inria_heartbeat'
+
+auth = { 'AuthMethod' : 'password',
+           'Username' : login,
+           'AuthString' : password,
+}
+
+api_url="https://%s:443/PLCAPI/"%plc_host
+
+plc_api = xmlrpclib.ServerProxy(api_url,allow_none=True)
+
+# the slice's node ids
+node_ids = plc_api.GetSlices(auth,slice_name,['node_ids'])[0]['node_ids']
+
+# get hostname for these nodes
+slice_nodes = plc_api.GetNodes(auth,node_ids,['hostname'])
+
+# store in a file
+f=open('mynodes.txt','w')
+for node in slice_nodes:
+    print >>f,node['hostname']
+f.close()
+</programlisting>
+  </section>
+
   </chapter>
 
   <chapter id="Methods">