Setting tag plcapi-7.0-0
[plcapi.git] / doc / PLCAPI.xml.in
index af48f91..da18878 100644 (file)
 <programlisting> 
 >>> tagnames=['arch','fcdistro','hrn','hmac','exempt_node_until']
 >>> for tt in GetTagTypes(tagnames,['tagname','category']): 
->>> ... print "tagname=%-18s category=%s"%(tt['tagname'], tt['category'])
+>>> ... print("tagname=%-18s category=%s"%(tt['tagname'], tt['category']))
 tagname=hrn                category=node/sfa
 tagname=hmac               category=slice/auth  
 tagname=exempt_node_until  category=node/myops
@@ -360,8 +360,8 @@ tagname=arch               category=node/slice/config/ui/header=A/rank=x
        </para></listitem>
 
        <listitem><para> 
-         The current limitation about tags as opposed to native
-         fields is that, for performance, tags won't get returned
+         The current limitations about tags, as opposed to native
+         fields, is that for performance, tags won't get returned
          when using the implicit set of columns. So for instance:
 <programlisting>
 # get all details for 'pl1.foo.com' 
@@ -369,6 +369,20 @@ tagname=arch               category=node/slice/config/ui/header=A/rank=x
 # this did not return the 'arch' tag
 >>> 'arch' in node
 False
+</programlisting>
+       </para></listitem>
+
+       <listitem><para>
+         For a similar reason, any tag used in the filter argument will <emphasis>have to</emphasis> be mentioned in the list of returned columns as well. For example:
+<programlisting>
+# if 'hrn' is not part of the result, this does not work
+>>> ns=GetNodes({'hrn':'ple.*'},['hostname'])
+Database error b59e068c-589a-4ad5-9dd8-63cc38f2a2eb:
+column "hrn" does not exist
+LINE 1: ...M view_nodes WHERE deleted IS False AND (True AND hrn ILIKE ...
+... abridged ...
+# this can be worked around by just returning 'hrn' as well
+>>> ns=GetNodes({'hrn':'ple.*'},['hrn','hostname'])
 </programlisting>
        </para></listitem>
 
@@ -405,24 +419,24 @@ False
 >>> AddNodeGroup('betanodes','deployment','beta')
 22
 ### checking contents (no node has 'deployment' set to either 'alpha' or 'beta' yet)
->>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print ng
+>>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print(ng)
 {'groupname': u'alphanodes', 'node_ids': []}
 {'groupname': u'betanodes', 'node_ids': []}
 
 ### displaying node ids 
->>> for n in GetNodes({'hostname':'*.inria.fr'},['hostname','node_id']): print n
+>>> for n in GetNodes({'hostname':'*.inria.fr'},['hostname','node_id']): print(n)
 {'hostname': u'vnode01.inria.fr', 'node_id': 1}
 {'hostname': u'vnode02.inria.fr', 'node_id': 2}
 
 ### setting 'deployment' for these two nodes
 >>> SetNodeDeployment('vnode01.inria.fr','alpha')
->>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print ng
+>>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print(ng)
 {'groupname': u'alphanodes', 'node_ids': [1]}
 {'groupname': u'betanodes', 'node_ids': []}
 >>> SetNodeDeployment('vnode02.inria.fr','beta')
 
 ### checking contents again
->>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print ng
+>>> for ng in GetNodeGroups(['alphanodes','betanodes'],['groupname','node_ids']): print(ng)
 {'groupname': u'alphanodes', 'node_ids': [1]}
 {'groupname': u'betanodes', 'node_ids': [2]}
 </programlisting>
@@ -489,7 +503,7 @@ Type "system.listMethods()" or "help(method)" for more information.
       the <function>PLC.Shell</function> module:</para>
 
       <programlisting>
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import sys
 
@@ -521,9 +535,9 @@ nodes = plc.GetNodes([121], ['node_id', 'hostname'])
     the name of all the hosts attached to a given slice.</para>
 
 <programlisting>
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
-import xmlrpclib
+import xmlrpc.client
 
 plc_host='www.planet-lab.eu'
 
@@ -536,7 +550,7 @@ auth = { 'AuthMethod' : 'password',
 
 api_url="https://%s:443/PLCAPI/"%plc_host
 
-plc_api = xmlrpclib.ServerProxy(api_url,allow_none=True)
+plc_api = xmlrpc.client.ServerProxy(api_url,allow_none=True)
 
 # the slice's node ids
 node_ids = plc_api.GetSlices(auth,slice_name,['node_ids'])[0]['node_ids']
@@ -545,9 +559,9 @@ node_ids = plc_api.GetSlices(auth,slice_name,['node_ids'])[0]['node_ids']
 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']
+with ('mynodes.txt','a') as f:
+    for node in slice_nodes:
+        f.write(node['hostname'] + "\n")
 f.close()
 </programlisting>
   </section>