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:

  1. 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.

  2. Synchronized model adapters. Each of these classes describe how a model can be synchronized with a specific data store.

  3. 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

add_local_obj(local_obj_id, local_obj_data, *, pretend=False)[source]
add_remote_obj(remote_obj_id, remote_obj_data, *, pretend=False)[source]
bulk_add_local_objs(local_objs, *, pretend=False)[source]
bulk_add_remote_objs(remote_objs, *, pretend=False)[source]
bulk_delete_local_objs(local_objs, *, pretend=False)[source]
bulk_delete_remote_objs(remote_objs, *, pretend=False)[source]
bulk_update_objs(objs, *, pretend=False)[source]
delete_local_obj(local_obj_id, *, pretend=False)[source]
delete_remote_obj(remote_obj_id, *, pretend=False)[source]
get_obj_diff(local_obj_id, local_obj_data, remote_obj_id, remote_obj_data)[source]

Compare two existing objects and determines which fields need to be updated accordingly.

Returns

a mapping of field names to an (old_value, new_value) tuple.

sync(local_objects, remote_objects, obj_map, *, pretend=False)[source]
update_obj(local_obj_id, local_obj_data, remote_obj_id, remote_obj_data, *, pretend=False)[source]
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

classmethod get_sync_remote_queryset()[source]
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

classmethod get_sync_objects_map(local_objects, remote_objects)[source]
sync_engine_class

alias of cri_models.sync.ldapmodelengine.SyncRemoteLDAPModelEngine

class cri_models.sync.SyncedModelAdapter(obj)[source]

Bases: object

classmethod get_sync_engine()[source]
classmethod get_sync_engine_class()[source]
get_sync_local_data()[source]
get_sync_local_data_multi()[source]
get_sync_local_obj_id()[source]
get_sync_local_obj_id_multi()[source]
classmethod get_sync_local_queryset(model)[source]
classmethod get_sync_objects_map(local_objects, remote_objects)[source]
static get_sync_remote_data(remote_obj)[source]
classmethod get_sync_remote_model()[source]
get_sync_remote_obj_id(remote_objects)[source]
get_sync_remote_obj_id_multi(remote_objects)[source]
classmethod get_sync_remote_queryset()[source]
classmethod partial_sync(local_objects, *, pretend=False)[source]
sync(*, pretend=False)[source]
classmethod sync_all(model, *, pretend=False)[source]
sync_engine_class

alias of cri_models.sync.modelengine.SyncRemoteModelEngine

sync_local_queryset = None
sync_remote_model = None
sync_remote_queryset = None
class cri_models.sync.SyncedModelMixin[source]

Bases: object

classmethod get_sync_adapters()[source]
classmethod partial_sync(local_objects, *, pretend=False)[source]
sync(*, pretend=False)[source]
classmethod sync_all(*, pretend=False)[source]
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:
  1. We remove the remote objects who are not related to a local objects.

  2. We create the missing remote objects for which a corresponding local objects exists.

  3. 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

Submodules