cri_models.sync package
Model synchronization module
This module offers various classes to deal with Djando model synchronization. The end goal is to easily synchronize model instances with other data store (LDAP, Kerberos, …).
To achieve this, we have three kind of classes:
Synchronization engines, all of them are subclasses of
SyncEngine
. They can tell which objects need to be added, updated or deleted and how to perform these actions.Synchronized model adapters. Each of these classes describe how a model can be synchronized with a specific data store.
A model mixin. This mixin is intended to be added to the Django models you want to synchronize. It will enumerate and call the relevant adapters.
All operations are based on dictionary representing the data of a specific object. Comparison between objects are done by looking at their respective dictionaries.
A synchronization engine is given two mappings between objects unique id and their dictionnaries, one for the local objects and one for the remote objects. Local_objects are simply the one from which the synchronization is initiated. It is also given a mapping between local objects IDs and remote objects IDs to know how to associate them.
- class cri_models.sync.SyncEngine(*args, **kwargs)[source]
Bases:
object
Base class for synchronization engines
- class cri_models.sync.SyncRemoteModelEngine(*args, local_model, remote_model, **kwargs)[source]
Bases:
cri_models.sync.modelengine.RemoteModelSyncMixin
,cri_models.sync.engine.UnidirectionalSyncEngine
- class cri_models.sync.SyncedKerberosPrincipalAdapter(obj)[source]
Bases:
cri_models.sync.modelengine.SyncedModelAdapter
- sync_engine_class
alias of
cri_models.sync.kerberosmodelengine.SyncKerberosPrincipalEngine
- sync_remote_model
alias of
cri_models.kerberos.models.Principal
- class cri_models.sync.SyncedLDAPModelAdapter(obj)[source]
Bases:
cri_models.sync.modelengine.SyncedModelAdapter
- sync_engine_class
alias of
cri_models.sync.ldapmodelengine.SyncRemoteLDAPModelEngine
- class cri_models.sync.SyncedModelAdapter(obj)[source]
Bases:
object
- sync_engine_class
- sync_local_queryset = None
- sync_remote_model = None
- sync_remote_queryset = None
- class cri_models.sync.UnidirectionalSyncEngine(*args, **kwargs)[source]
Bases:
cri_models.sync.engine.SyncEngine
This synchronization engine always brings the remote objects to the state of the local objects.
- sync(local_objects, remote_objects, obj_map, *, pretend=False)[source]
Synchronize objects.
- The synchronization is done according to a three steps process:
We remove the remote objects who are not related to a local objects.
We create the missing remote objects for which a corresponding local objects exists.
We update the remote objects for which a corresponding local objects exists.
- Parameters
local_objects – a mapping between local objects ID and data
remote_objects – a mapping between remote objects ID and data
obj_map – a mapping between existing local objects IDs and existing remote objects IDs.
pretend – if True no action is effectively performed.
- Returns
a tuple containing added, updated, deleted objects and failed operations