* fields starting with - are special and relate to row selection, i.e. sorting and clipping
* '-SORT' : a field name, or an ordered list of field names that are used for sorting
- * these fields may start with + (default) or - for denoting increasing or decreasing order
+ these fields may start with + (default) or - for denoting increasing or decreasing order
example : filter = { '-SORT' : [ '+node_id', '-hostname' ] }
* '-OFFSET' : the number of first rows to be ommitted
* '-LIMIT' : the amount of rows to be returned
- example : filter = { '-OFFSET' : 100, 'LIMIT':25}
+ example : filter = { '-OFFSET' : 100, '-LIMIT':25}
A realistic example would read
GetNodes ( { 'hostname' : '*.edu' , '-SORT' : 'hostname' , '-OFFSET' : 30 , '-LIMIT' : 25 } )
from xml.dom.minidom import Element, Text
import codecs
-from PLC.Method import *
-import DocBookLocal
+from PLC.Parameter import Parameter, Mixed, xmlrpc_type, python_type
# xml.dom.minidom.Text.writexml adds surrounding whitespace to textual
# data when pretty-printing. Override this behavior.
for subparam in param:
itemizedlist.appendChild(paramElement(None, subparam))
-api_func_list = DocBookLocal.get_func_list()
-for func in api_func_list:
- method = func.name
-
- if func.status == "deprecated":
- continue
-
- (min_args, max_args, defaults) = func.args()
-
- section = Element('section')
- section.setAttribute('id', func.name)
- section.appendChild(simpleElement('title', func.name))
-
- prototype = "%s (%s)" % (method, ", ".join(max_args))
- para = paraElement('Prototype:')
- para.appendChild(blockquoteElement(prototype))
- section.appendChild(para)
-
- para = paraElement('Description:')
- para.appendChild(blockquoteElement(func.__doc__))
- section.appendChild(para)
-
- para = paraElement('Allowed Roles:')
- para.appendChild(blockquoteElement(", ".join(func.roles)))
- section.appendChild(para)
-
- section.appendChild(paraElement('Parameters:'))
- params = Element('itemizedlist')
- if func.accepts:
- for name, param, default in zip(max_args, func.accepts, defaults):
- params.appendChild(paramElement(name, param))
- else:
- listitem = Element('listitem')
- listitem.appendChild(paraElement('None'))
- params.appendChild(listitem)
- section.appendChild(params)
-
- section.appendChild(paraElement('Returns:'))
- returns = Element('itemizedlist')
- returns.appendChild(paramElement(None, func.returns))
- section.appendChild(returns)
-
- print section.toprettyxml(encoding = "UTF-8")
+class DocBook:
+
+ def __init__ (self,functions_list):
+ self.functions_list = functions_list
+
+ def Process (self):
+
+ for func in self.functions_list:
+ method = func.name
+
+ if func.status == "deprecated":
+ continue
+
+ (min_args, max_args, defaults) = func.args()
+
+ section = Element('section')
+ section.setAttribute('id', func.name)
+ section.appendChild(simpleElement('title', func.name))
+
+ prototype = "%s (%s)" % (method, ", ".join(max_args))
+ para = paraElement('Prototype:')
+ para.appendChild(blockquoteElement(prototype))
+ section.appendChild(para)
+
+ para = paraElement('Description:')
+ para.appendChild(blockquoteElement(func.__doc__))
+ section.appendChild(para)
+
+ para = paraElement('Allowed Roles:')
+ para.appendChild(blockquoteElement(", ".join(func.roles)))
+ section.appendChild(para)
+
+ section.appendChild(paraElement('Parameters:'))
+ params = Element('itemizedlist')
+ if func.accepts:
+ for name, param, default in zip(max_args, func.accepts, defaults):
+ params.appendChild(paramElement(name, param))
+ else:
+ listitem = Element('listitem')
+ listitem.appendChild(paraElement('None'))
+ params.appendChild(listitem)
+ section.appendChild(params)
+
+ section.appendChild(paraElement('Returns:'))
+ returns = Element('itemizedlist')
+ returns.appendChild(paramElement(None, func.returns))
+ section.appendChild(returns)
+
+ print section.toprettyxml(encoding = "UTF-8")
# plcsh code fragment (see below)
GetNodes([1,2,3])
GetNodes({'node_id': [1,2,3]})
-GetNodes({'node_id': 1}) + GetNodes({'node_id': 2}) + GetNodes({'node_id': 3})
</programlisting>
- <para>Would all be equivalent queries. Attributes that are
+ <para>Would be equivalent queries. Attributes that are
themselves arrays (such as <literal>nodenetwork_ids</literal>
and <literal>slice_ids</literal> for nodes) cannot be used in
filters.</para>
+
+ <para> Filters support a few extra features illustrated in the following examples.</para>
+ <itemizedlist>
+ <listitem>
+ <para> <emphasis> Pattern Matching </emphasis> </para>
+ <programlisting>GetNodes ( { 'hostname' : '*.fr' } ) </programlisting>
+ </listitem>
+ <listitem>
+ <para> <emphasis> Negation </emphasis> </para>
+ <programlisting>GetNodes( { '~peer_id' : None } ) </programlisting>
+ </listitem>
+ <listitem>
+ <para> <emphasis> Numeric comparisons </emphasis> </para>
+ <programlisting>GetEvents( { '>time' : 1178531418 } ) </programlisting>
+ <programlisting>GetEvents( { ']event_id' : 2305 } ) </programlisting>
+ </listitem>
+ <listitem>
+ <para> <emphasis> Sorting and Clipping </emphasis> </para>
+ <programlisting> GetNodes( { '-SORT' : 'hostname' , '-OFFSET' : 30 , '-LIMIT' : 25 }</programlisting>
+ </listitem>
+ </itemizedlist>
</section>
<section>