Ñò Ã#xPc@sídZddklZlZddkZddkZddkZddkZdefd„ƒYZdefd„ƒYZdefd „ƒYZ d efd „ƒYZ d efd „ƒYZ defd„ƒYZ dei fd„ƒYZdS(sâ Base classes for standard CRUD operations. These base classes are for `Method` plugins that provide standard Create, Retrieve, Updated, and Delete operations (CRUD) for their corresponding `Object` plugin. In particuar, these base classes provide logic to automatically create the plugin args and options by inspecting the params on their corresponding `Object` plugin. This provides a single point of definition for LDAP attributes and enforces a simple, consistent API for CRUD operations. For example, say we want CRUD operations on a hypothetical "user" entry. First we need an `Object` plugin: >>> from ipalib import Object, Str >>> class user(Object): ... takes_params = ( ... Str('login', primary_key=True), ... Str('first'), ... Str('last'), ... Str('ipauniqueid', flags=['no_create', 'no_update']), ... ) ... Next we need `Create`, `Retrieve`, `Updated`, and `Delete` plugins, and optionally a `Search` plugin. For brevity, we'll just define `Create` and `Retrieve` plugins: >>> from ipalib import crud >>> class user_add(crud.Create): ... pass ... >>> class user_show(crud.Retrieve): ... pass ... Now we'll register the plugins and finalize the `plugable.API` instance: >>> from ipalib import create_api >>> api = create_api() >>> api.register(user) >>> api.register(user_add) >>> api.register(user_show) >>> api.finalize() First, notice that our ``user`` `Object` has the params we defined with the ``takes_params`` tuple: >>> list(api.Object.user.params) ['login', 'first', 'last', 'ipauniqueid'] >>> api.Object.user.params.login Str('login', primary_key=True) Although we defined neither ``takes_args`` nor ``takes_options`` for our ``user_add`` plugin, the `Create` base class automatically generated them for us: >>> list(api.Command.user_add.args) ['login'] >>> list(api.Command.user_add.options) ['first', 'last', 'all', 'raw', 'version'] Notice that ``'ipauniqueid'`` isn't included in the options for our ``user_add`` plugin. This is because of the ``'no_create'`` flag we used when defining the ``ipauniqueid`` param. Often times there are LDAP attributes that are automatically created by the server and therefor should not be supplied as an option to the `Create` plugin. Often these same attributes shouldn't be update-able either, in which case you can also supply the ``'no_update'`` flag, as we did with our ``ipauniqueid`` param. Lastly, you can also use the ``'no_search'`` flag for attributes that shouldn't be search-able (because, for example, the attribute isn't indexed). As with our ``user_add` plugin, we defined neither ``takes_args`` nor ``takes_options`` for our ``user_show`` plugin; instead the `Retrieve` base class created them for us: >>> list(api.Command.user_show.args) ['login'] >>> list(api.Command.user_show.options) ['all', 'raw', 'version'] As you can see, `Retrieve` plugins take a single argument (the primary key) and no options. If needed, you can still specify options for your `Retrieve` plugin with a ``takes_options`` tuple. Flags like ``'no_create'`` remove LDAP attributes from those that can be supplied as *input* to a `Method`, but they don't effect the attributes that can be returned as *output*. Regardless of what flags have been used, the output entry (or list of entries) can contain all the attributes defined on the `Object` plugin (in our case, the above ``user.params``). For example, compare ``user.params`` with ``user_add.output_params`` and ``user_show.output_params``: >>> list(api.Object.user.params) ['login', 'first', 'last', 'ipauniqueid'] >>> list(api.Command.user_add.output_params) ['login', 'first', 'last', 'ipauniqueid'] >>> list(api.Command.user_show.output_params) ['login', 'first', 'last', 'ipauniqueid'] Note that the above are all equal. iÿÿÿÿ(tMethodtObjectNtCreatecBs)eZdZeiZd„Zd„ZRS(s Create a new entry. ccs,|iio|iiidtƒVndS(Nt attribute(tobjt primary_keytclonetTrue(tself((s//usr/lib/python2.6/site-packages/ipalib/crud.pytget_args…s ccsþ|io)x&tt|ƒiƒD] }|Vq Wnx‘|ii|iƒD]z}d|ij}d|ijoqInd|ijo-|id|dt dt dt dt ƒVqI|id|ƒVqIW|ip)x&tt|ƒiƒD] }|VqçWndS( Ntvirtual_attributet no_createt ask_createRtquerytrequiredtautofillt alwaysask( textra_options_firsttsuperRt get_optionsRt params_minustargstflagsRtFalseR(RtoptionR((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR‰s$    (t__name__t __module__t__doc__toutputtstandard_entryt has_outputR R(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR~s  tPKQuerycBseZdZd„ZRS(s< Base class for `Retrieve`, `Update`, and `Delete`. ccs2|iio!|iiidtdtƒVndS(NRR (RRRR(R((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR ¢s (RRRR (((s//usr/lib/python2.6/site-packages/ipalib/crud.pyRstRetrievecBseZdZeiZRS(s/ Retrieve an entry by its primary key. (RRRRRR(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR ©stUpdatecBs eZdZeiZd„ZRS(s4 Update one or more attributes on an entry. ccsp|io)x&tt|ƒiƒD] }|Vq Wnx|iiƒD]ò}|i}d|ij}|io|idgƒ}nd|ijoqCnd|ijo3|i d|dt dt dt d t d |ƒVqCd |ijo'|i d|dt d t d |ƒVqC|i d|dt dt d |ƒVqCW|ip)x&tt|ƒiƒD] }|VqYWndS( NR tnonemptyt no_updatet ask_updateRR RRRRt req_update( RRR!RRtparams_minus_pkRRtunionRRR(RRt new_flagsR((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR¸s4        (RRRRRRR(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR!±s tDeletecBseZdZeiZRS(s% Delete one or more entries. (RRRRtstandard_deleteR(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR)ÙstSearchcBs)eZdZeiZd„Zd„ZRS(sB Retrieve all entries that match a given search criteria. ccstidƒVdS(Ns criteria?(t parameterstStr(R((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR èsccsV|io)x&tt|ƒiƒD] }|Vq Wnxé|ii|iƒD]Ò}d|ij}d|ijoqInd|ijo-|id|dt dt dt dt ƒVqIt |t i ƒo3|i|it id|dt dt dt ƒVqI|id|dt dt dt ƒVqIW|ip)x&tt|ƒiƒD] }|Vq?WndS( NR t no_searcht ask_searchRR RRR(RRR+RRRRRRRRt isinstanceR,tFlagt clone_retypetnametBool(RRR((s//usr/lib/python2.6/site-packages/ipalib/crud.pyRës.     (RRRRtstandard_list_of_entriesRR R(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR+ás  t CrudBackendcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s7 Base class defining generic CRUD backend API. cKstd|iƒ‚dS(sa Create a new entry. This method should take key word arguments representing the attributes the created entry will have. If this methods constructs the primary_key internally, it should raise an exception if the primary_key was passed. Likewise, if this method requires the primary_key to be passed in from the caller, it should raise an exception if the primary key was *not* passed. This method should return a dict of the exact entry as it was created in the backing store, including any automatically created attributes. s %s.create()N(tNotImplementedErrorR3(Rtkw((s//usr/lib/python2.6/site-packages/ipalib/crud.pytcreate scCstd|iƒ‚dS(sÌ Retrieve an existing entry. This method should take a two arguments: the primary_key of the entry in question and a list of the attributes to be retrieved. If the list of attributes is None then all non-operational attributes will be returned. If such an entry exists, this method should return a dict representing that entry. If no such entry exists, this method should return None. s %s.retrieve()N(R7R3(RRt attributes((s//usr/lib/python2.6/site-packages/ipalib/crud.pytretrieves cKstd|iƒ‚dS(s— Update an existing entry. This method should take one required argument, the primary_key of the entry to modify, plus optional keyword arguments for each of the attributes being updated. This method should return a dict representing the entry as it now exists in the backing store. If no such entry exists, this method should return None. s %s.update()N(R7R3(RRR8((s//usr/lib/python2.6/site-packages/ipalib/crud.pytupdate+s cCstd|iƒ‚dS(s“ Delete an existing entry. This method should take one required argument, the primary_key of the entry to delete. s %s.delete()N(R7R3(RR((s//usr/lib/python2.6/site-packages/ipalib/crud.pytdelete9scKstd|iƒ‚dS(s! Return entries matching specific criteria. This method should take keyword arguments representing the search criteria. If a key is the name of an entry attribute, the value should be treated as a filter on that attribute. The meaning of keys outside this namespace is left to the implementation. This method should return and iterable containing the matched entries, where each entry is a dict. If no entries are matched, this method should return an empty iterable. s %s.search()N(R7R3(RR8((s//usr/lib/python2.6/site-packages/ipalib/crud.pytsearchBs (RRRR9R;R<R=R>(((s//usr/lib/python2.6/site-packages/ipalib/crud.pyR6s     (RtfrontendRRtbackendR,RRRR R!R)R+t ConnectibleR6(((s//usr/lib/python2.6/site-packages/ipalib/crud.pytxs0 (%