API
Models
- class morango.models.Buffer(*args, **kwargs)[source]
Bases:
AbstractStoreBufferis where records from the internal store are queued up temporarily, before being sent to another morango instance, or stored while being received from another instance, before dequeuing into the local store.- Parameters:
id (AutoField) – Id
profile (CharField) – Profile
serialized (TextField) – Serialized
deleted (BooleanField) – Deleted
hard_deleted (BooleanField) – Hard deleted
last_saved_instance (UUIDField) – Last saved instance
last_saved_counter (IntegerField) – Last saved counter
partition (TextField) – Partition
source_id (CharField) – Source id
model_name (CharField) – Model name
conflicting_serialized_data (TextField) – Conflicting serialized data
_self_ref_fk (CharField) – self ref fk
_self_ref_order (IntegerField) – self ref order
transfer_session_id (ForeignKey to
~) – Transfer sessionmodel_uuid (UUIDField) – Model uuid
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- model_uuid
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- transfer_session
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- transfer_session_id
- class morango.models.Certificate(id, parent, profile, scope_definition, scope_version, scope_params, public_key, salt, serialized, signature, _private_key)[source]
Bases:
MPTTModel,UUIDModelMixin- Parameters:
id (UUIDField) – Id
parent_id (ForeignKey to
~) – Parentprofile (CharField) – Profile
scope_definition_id (ForeignKey to
~) – Scope definitionscope_version (IntegerField) – Scope version
scope_params (TextField) – Scope params
public_key (PublicKeyField) – Public key
salt (CharField) – Salt
serialized (TextField) – Serialized
signature (TextField) – Signature
_private_key (PrivateKeyField) – private key
lft (PositiveIntegerField) – Lft
rght (PositiveIntegerField) – Rght
tree_id (PositiveIntegerField) – Tree id
level (PositiveIntegerField) – Level
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- certificate_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- level
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- lft
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- parent
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- parent_id
- property private_key
- profile
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- public_key
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- rght
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- salt
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- save(*args, **kwargs)[source]
If this is a new node, sets tree fields up before it is inserted into the database, making room in the tree structure as necessary, defaulting to making the new node the last child of its parent.
It the node’s left and right edge indicators already been set, we take this as indication that the node has already been set up for insertion, so its tree fields are left untouched.
If this is an existing node and its parent has been changed, performs reparenting in the tree structure, defaulting to making the node the last child of its new parent.
In either case, if the node’s class has its
order_insertion_bytree option set, the node will be inserted or moved to the appropriate position to maintain ordering by the specified field.
- scope_definition
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- scope_definition_id
- scope_params
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- scope_version
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- serialized
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- signature
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- syncsessions_client
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- syncsessions_server
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- tree_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- uuid_input_fields = ('public_key', 'profile', 'salt')
- class morango.models.DatabaseIDModel(*args, **kwargs)[source]
Bases:
UUIDModelMixinModel to be used for tracking database ids.
- Parameters:
id (UUIDField) – Id
current (BooleanField) – Current
date_generated (DateTimeField) – Date generated
initial_instance_id (CharField) – Initial instance id
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- current
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- date_generated
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_date_generated(*, field=<django.db.models.fields.DateTimeField: date_generated>, is_next=True, **kwargs)
- get_previous_by_date_generated(*, field=<django.db.models.fields.DateTimeField: date_generated>, is_next=False, **kwargs)
- initial_instance_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- instanceidmodel_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- objects = <morango.models.core.DatabaseIDManager object>
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- uuid_input_fields = 'RANDOM'
- class morango.models.DatabaseMaxCounter(*args, **kwargs)[source]
Bases:
AbstractCounterDatabaseMaxCounteris used to keep track of what data this database already has across all instances for a particular partition prefix. Whenever 2 morango instances sync with each other we keep track of those partition prefixes from the filters, as well as the maximum counter we received for each instance during the sync session.- Parameters:
id (AutoField) – Id
instance_id (UUIDField) – Instance id
counter (IntegerField) – Counter
partition (CharField) – Partition
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- classmethod calculate_filter_specific_instance_counters(filters, is_producer=False, v2_format=False)[source]
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- partition
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class morango.models.DeletedModels(*args, **kwargs)[source]
Bases:
ModelDeletedModelshelps us keep track of models that are deleted prior to serialization.- Parameters:
id (UUIDField) – Id
profile (CharField) – Profile
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- profile
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class morango.models.Filter(filter_str, params=None)[source]
Bases:
object- classmethod add(filter_a, filter_b)[source]
The Filter’s addition operator overload is already defensive against None being the right-hand operand, but this method is defensive against None being the left-hand operand
- contains_exact_partition(partition)[source]
Returns True if the partition exactly matches one of the partitions in this Filter
- contains_partition(partition)[source]
Returns True if the partition starts with as least one of the partitions in this Filter
- classmethod from_template(template, params=None)[source]
Create a filter from a string template, which may have params that will be replaced with values passed to params
- Parameters:
template (str) – The partition filter template
params (dict|str) – The param dictionary or JSON object string
- Returns:
The filter with params replaced
- Return type:
- class morango.models.HardDeletedModels(*args, **kwargs)[source]
Bases:
ModelHardDeletedModelshelps us keep track of models where all their data must be purged (serialized is nullified).- Parameters:
id (UUIDField) – Id
profile (CharField) – Profile
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- profile
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class morango.models.InstanceIDModel(*args, **kwargs)[source]
Bases:
ModelInstanceIDModelis used to track what the current ID of this Morango instance is based on system properties. If system properties change, the ID used to track the morango instance also changes. During serialization phase, we associate the current instance ID, as well as its counter with all the records that were serialized at the time.- Parameters:
id (UUIDField) – Id
platform (TextField) – Platform
hostname (TextField) – Hostname
sysversion (TextField) – Sysversion
node_id (CharField) – Node id
database_id (ForeignKey to
~) – Databasecounter (IntegerField) – Counter
current (BooleanField) – Current
db_path (CharField) – Db path
system_id (CharField) – System id
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- counter
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- current
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- database
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- database_id
- db_path
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod get_or_create_current_instance(clear_cache=False)[source]
Get the instance model corresponding to the current system, or create a new one if the system is new or its properties have changed (e.g. new MAC address).
- hostname
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property instance_info
Getter to access custom instance info defined in settings :return: dict
- node_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- platform
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- system_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- sysversion
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- uuid_input_fields = ('platform', 'hostname', 'sysversion', 'node_id', 'database_id', 'db_path')
- class morango.models.Nonce(*args, **kwargs)[source]
Bases:
UUIDModelMixinStores temporary nonce values used for cryptographic handshakes during syncing. These nonces are requested by the client, and then generated and stored by the server. When the client then goes to initiate a sync session, it signs the nonce value using the private key from the certificate it is using for the session, to prove to the server that it owns the certificate. The server checks that the nonce exists and hasn’t expired, and then deletes it.
- Parameters:
id (UUIDField) – Id
timestamp (DateTimeField) – Timestamp
ip (CharField) – Ip
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)
- get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)
- ip
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- timestamp
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- uuid_input_fields = 'RANDOM'
- class morango.models.RecordMaxCounter(*args, **kwargs)[source]
Bases:
AbstractCounterRecordMaxCounterkeeps track of the maximum counter each serialized record has been saved at, for each instance that has modified it. This is used to determine fast-forwards and merge conflicts during the sync process.- Parameters:
id (AutoField) – Id
instance_id (UUIDField) – Instance id
counter (IntegerField) – Counter
store_model_id (ForeignKey to
~) – Store model
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- store_model
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- store_model_id
- class morango.models.RecordMaxCounterBuffer(*args, **kwargs)[source]
Bases:
AbstractCounterRecordMaxCounterBufferis where combinations of instance ID and counters (fromRecordMaxCounter) are stored temporarily, until they are sent or received by another morango instance.- Parameters:
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- model_uuid
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- transfer_session
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- transfer_session_id
- class morango.models.ScopeDefinition(id, profile, version, primary_scope_param_key, description, read_filter_template, write_filter_template, read_write_filter_template)[source]
Bases:
Model- Parameters:
id (CharField) – Id
profile (CharField) – Profile
version (IntegerField) – Version
primary_scope_param_key (CharField) – Primary scope param key
description (TextField) – Description
read_filter_template (TextField) – Read filter template
write_filter_template (TextField) – Write filter template
read_write_filter_template (TextField) – Read write filter template
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- certificate_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- description
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- primary_scope_param_key
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- profile
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- read_filter_template
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- read_write_filter_template
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- version
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- write_filter_template
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Bases:
ModelThe public key is publically available via the
api/morango/v1/publickeyendpoint. Applications who would like to allow certificates to be pushed to the server must also enableALLOW_CERTIFICATE_PUSHING. Clients generate aCertificateobject and set thepublic_keyfield to the shared public key of the server.- Parameters:
id (AutoField) – Id
public_key (PublicKeyField) – Public key
private_key (PrivateKeyField) – Private key
current (BooleanField) – Current
Bases:
ObjectDoesNotExist
Bases:
MultipleObjectsReturned
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Create a shared public/private key pair for certificate pushing, if the settings allow.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class morango.models.Store(*args, **kwargs)[source]
Bases:
AbstractStoreStoreis the concrete model where serialized data is persisted, along with metadata about counters and history.- Parameters:
profile (CharField) – Profile
serialized (TextField) – Serialized
deleted (BooleanField) – Deleted
hard_deleted (BooleanField) – Hard deleted
last_saved_instance (UUIDField) – Last saved instance
last_saved_counter (IntegerField) – Last saved counter
partition (TextField) – Partition
source_id (CharField) – Source id
model_name (CharField) – Model name
conflicting_serialized_data (TextField) – Conflicting serialized data
_self_ref_fk (CharField) – self ref fk
_self_ref_order (IntegerField) – self ref order
id (UUIDField) – Id
dirty_bit (BooleanField) – Dirty bit
deserialization_error (TextField) – Deserialization error
deserialization_exception (CharField) – Deserialization exception
last_transfer_session_id (UUIDField) – Last transfer session id
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- deserialization_error
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- deserialization_exception
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- dirty_bit
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_transfer_session_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <morango.models.core.StoreManager object>
- recordmaxcounter_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- class morango.models.SyncSession(*args, **kwargs)[source]
Bases:
ModelSyncSessionholds metadata for a sync session which keeps track of initial settings and the current transfer happening for this sync session.- Parameters:
id (UUIDField) – Id
start_timestamp (DateTimeField) – Start timestamp
last_activity_timestamp (DateTimeField) – Last activity timestamp
active (BooleanField) – Active
is_server (BooleanField) – Is server
client_certificate_id (ForeignKey to
~) – Client certificateserver_certificate_id (ForeignKey to
~) – Server certificateprofile (CharField) – Profile
connection_kind (CharField) – Connection kind
connection_path (CharField) – Connection path
client_ip (CharField) – Client ip
server_ip (CharField) – Server ip
client_instance_id (UUIDField) – Client instance id
client_instance_json (TextField) – Client instance json
server_instance_id (UUIDField) – Server instance id
server_instance_json (TextField) – Server instance json
extra_fields (TextField) – Extra fields
process_id (IntegerField) – Process id
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- active
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- client_certificate
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- client_certificate_id
- client_instance_data
- client_instance_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- client_instance_json
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- client_ip
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- connection_kind
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- connection_path
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- extra_fields
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_connection_kind_display(*, field=<django.db.models.fields.CharField: connection_kind>)
- get_next_by_last_activity_timestamp(*, field=<django.db.models.fields.DateTimeField: last_activity_timestamp>, is_next=True, **kwargs)
- get_next_by_start_timestamp(*, field=<django.db.models.fields.DateTimeField: start_timestamp>, is_next=True, **kwargs)
- get_previous_by_last_activity_timestamp(*, field=<django.db.models.fields.DateTimeField: last_activity_timestamp>, is_next=False, **kwargs)
- get_previous_by_start_timestamp(*, field=<django.db.models.fields.DateTimeField: start_timestamp>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_server
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_activity_timestamp
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- process_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- profile
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- server_certificate
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- server_certificate_id
- server_instance_data
- server_instance_id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- server_instance_json
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- server_ip
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- start_timestamp
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- transfersession_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- class morango.models.SyncableModel(*args, **kwargs)[source]
Bases:
UUIDModelMixinSyncableModelis the base model class for syncing. Other models inherit from this class if they want to make their data syncable across devices.- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
- ID_PLACEHOLDER = '${id}'
- cached_clean_fields(fk_lookup_cache, exclude=None, sync_filter=None)[source]
Immediately validates all fields, but uses a cache for foreign key (FK) lookups to reduce repeated queries for many records with the same FK
- Parameters:
fk_lookup_cache (dict) – A dictionary to use as a cache to prevent querying the database if a FK exists in the cache, having already been validated
exclude (list[str]) – A list of field names to exclude from validation
sync_filter (Filter|None) – The current sync’s filter, if any
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- calculate_source_id()[source]
Should return a string that uniquely defines the model instance or None for a random uuid.
- calculate_uuid()[source]
Should return a 32-digit hex string for a UUID that is calculated as a function of a set of fields from the model.
- clean_fields(exclude=None, sync_filter=None)[source]
Immediately validates all fields
- Parameters:
exclude (list[str]) – A list of field names to exclude from validation
sync_filter (Filter|None) – The current sync’s filter, if any
- deferred_clean_fields(exclude=None, sync_filter=None)[source]
Calls .clean_fields() but excludes all foreign key fields and instead returns them as a dictionary for deferred batch processing
- classmethod deserialize(dict_model, sync_filter=None)[source]
Returns an unsaved class object based on the valid properties passed in.
- Parameters:
dict_model (dict) – The model data to deserialize
sync_filter (Filter|None) – The current sync’s filter, if any
- morango_fields_not_to_serialize = ()
- morango_model_dependencies = ()
- morango_ordering = ()
- morango_profile = None
- objects
- save(update_dirty_bit_to=True, *args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- serialize()[source]
All concrete fields of the
SyncableModelsubclass, except for those specifically blacklisted, are returned in a dict.
- syncing_objects
- class morango.models.SyncableModelManager(*args, **kwargs)[source]
Bases:
ManagerFromSyncableModelQuerySet
- class morango.models.SyncableModelQuerySet(model=None, query=None, using=None, hints=None)[source]
Bases:
QuerySet
- class morango.models.TransferSession(*args, **kwargs)[source]
Bases:
ModelTransferSessionholds metadata that is related to a specific transfer (push/pull) session between 2 morango instances.- Parameters:
id (UUIDField) – Id
filter (TextField) – Filter
push (BooleanField) – Push
active (BooleanField) – Active
records_transferred (IntegerField) – Records transferred
records_total (IntegerField) – Records total
bytes_sent (BigIntegerField) – Bytes sent
bytes_received (BigIntegerField) – Bytes received
sync_session_id (ForeignKey to
~) – Sync sessionstart_timestamp (DateTimeField) – Start timestamp
last_activity_timestamp (DateTimeField) – Last activity timestamp
client_fsic (TextField) – Client fsic
server_fsic (TextField) – Server fsic
transfer_stage (CharField) – Transfer stage
transfer_stage_status (CharField) – Transfer stage status
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- active
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- buffer_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- bytes_received
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- bytes_sent
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- client_fsic
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- delete_buffers()[source]
Deletes Buffer and RecordMaxCounterBuffer model records by executing SQL directly against the database for better performance
- filter
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_last_activity_timestamp(*, field=<django.db.models.fields.DateTimeField: last_activity_timestamp>, is_next=True, **kwargs)
- get_next_by_start_timestamp(*, field=<django.db.models.fields.DateTimeField: start_timestamp>, is_next=True, **kwargs)
- get_previous_by_last_activity_timestamp(*, field=<django.db.models.fields.DateTimeField: last_activity_timestamp>, is_next=False, **kwargs)
- get_previous_by_start_timestamp(*, field=<django.db.models.fields.DateTimeField: start_timestamp>, is_next=False, **kwargs)
- get_transfer_stage_display(*, field=<django.db.models.fields.CharField: transfer_stage>)
- get_transfer_stage_status_display(*, field=<django.db.models.fields.CharField: transfer_stage_status>)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_activity_timestamp
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- property pull
Getter for not push condition, which adds complexity in conditional statements
- push
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- recordmaxcounterbuffer_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- records_total
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- records_transferred
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- server_fsic
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- start_timestamp
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- sync_session
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- sync_session_id
- transfer_stage
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- transfer_stage_status
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class morango.models.UUIDField(*args, **kwargs)[source]
Bases:
CharFieldAdaptation of Django’s UUIDField, but with 32-char hex representation as Python representation rather than a UUID instance.
- deconstruct()[source]
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- class morango.models.UUIDModelMixin(*args, **kwargs)[source]
Bases:
ModelMixin for Django models that makes the primary key “id” into a UUID, which is calculated as a function of jointly unique parameters on the model, to ensure consistency across instances.
- Parameters:
id (UUIDField) – Id
- calculate_uuid()[source]
Should return a 32-digit hex string for a UUID that is calculated as a function of a set of fields from the model.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- uuid_input_fields = None
Sync sessions
- class morango.sync.session.SessionWrapper[source]
Bases:
SessionWrapper around requests.sessions.Session in order to implement logging around all request errors.
- bytes_received = 0
- bytes_sent = 0
- prepare_request(request)[source]
Override request preparer so we can get the prepared content length, for tracking transfer sizes
- Return type:
requests.PreparedRequest
- request(method, url, **kwargs)[source]
Constructs a
Request, prepares it and sends it. ReturnsResponseobject.- Parameters:
method – method for the new
Requestobject.url – URL for the new
Requestobject.params – (optional) Dictionary or bytes to be sent in the query string for the
Request.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.json – (optional) json to send in the body of the
Request.headers – (optional) Dictionary of HTTP Headers to send with the
Request.cookies – (optional) Dict or CookieJar object to send with the
Request.files – (optional) Dictionary of
'filename': file-like-objectsfor multipart encoding upload.auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
timeout (float or tuple) – (optional) How many seconds to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
allow_redirects (bool) – (optional) Set to True by default.
proxies – (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
hooks – (optional) Dictionary mapping hook name to one event or list of events, event must be callable.
stream – (optional) whether to immediately download the response content. Defaults to
False.verify – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to
True. When set toFalse, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify toFalsemay be useful during local development or testing.cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
- Return type:
requests.Response
The main module to be used for initiating the synchronization of data between morango instances.
- class morango.sync.syncsession.Connection[source]
Bases:
objectAbstraction around a connection with a syncing peer (network or disk), supporting interactions with that peer. This may be used by a SyncClient, but also supports other operations (e.g. querying certificates) outside the context of syncing.
This class should be subclassed for particular transport mechanisms, and the necessary methods overridden.
- class morango.sync.syncsession.NetworkSyncConnection(base_url='', compresslevel=9, retries=7, backoff_factor=0.3, chunk_size=500)[source]
Bases:
Connection- base_url
- property bytes_received
- property bytes_sent
- capabilities
- certificate_signing_request(parent_cert, scope_definition_id, scope_params, userargs=None, password=None)[source]
- chunk_size
- compresslevel
- create_sync_session(client_cert, server_cert, chunk_size=None)[source]
Starts a sync session by creating it on the server side and returning a client to use for initiating transfer operations
- Parameters:
client_cert (Certificate) – The local certificate to use, already registered with the server
server_cert (Certificate) – The server’s certificate that relates to the same profile as local
chunk_size (int) – An optional parameter specifying the size for each transferred chunk
- Returns:
A SyncSessionClient instance
- Return type:
- default_chunk_size = 500
- resume_sync_session(sync_session_id, chunk_size=None, ignore_existing_process=False)[source]
Resumes an existing sync session given an ID
- Parameters:
sync_session_id – The UUID of the SyncSession to resume
chunk_size (int) – An optional parameter specifying the size for each transferred chunk
- :param ignore_existing_process:An optional parameter specifying whether to ignore an
existing active process ID
- Returns:
A SyncSessionClient instance
- Return type:
- server_info
- session
- class morango.sync.syncsession.PullClient(*args, **kwargs)[source]
Bases:
TransferClientSync class to pull from server
- context
- controller
- signals
- sync_connection
- sync_session
- class morango.sync.syncsession.PushClient(*args, **kwargs)[source]
Bases:
TransferClientSync client for pushing to a server
- context
- controller
- signals
- sync_connection
- sync_session
- class morango.sync.syncsession.SyncClientSignals(**kwargs_defaults)[source]
Bases:
SyncSignalClass for holding all signal types, attached to SyncClient as attribute. All groups are sent the TransferSession object via the transfer_session keyword argument.
- dequeuing = <morango.sync.utils.SyncSignalGroup object>
Dequeuing signal group for locally or remotely dequeuing data after transfer.
- queuing = <morango.sync.utils.SyncSignalGroup object>
Queuing signal group for locally or remotely queuing data before transfer.
- session = <morango.sync.utils.SyncSignalGroup object>
Signal group firing for each push and pull TransferSession.
- transferring = <morango.sync.utils.SyncSignalGroup object>
Transferring signal group for tracking progress of push/pull on TransferSession.
- class morango.sync.syncsession.SyncSessionClient(sync_connection, sync_session, controller=None)[source]
Bases:
object- close_sync_session()[source]
Deprecated - Please use
NetworkSyncConnection.close_sync_sessionandNetworkSyncConnection.close
- controller
- initiate_pull(sync_filter)[source]
Deprecated - Please use
get_pull_clientand use the client :param sync_filter: Filter
- signals
- sync_connection
- sync_session
- class morango.sync.syncsession.TransferClient(sync_connection, sync_session, controller)[source]
Bases:
objectBase class for handling common operations for initiating syncing and other related operations.
- context
- controller
- property current_transfer_session
- proceed_to_and_wait_for(stage, error_msg=None, callback=None)[source]
Raises an exception if an ERROR result is received from calling proceed_to_and_wait_for :param stage: The stage to proceed to :param error_msg: An error message str to use as the exception message if it errors :param callback: A callback to pass along to the controller
- signals
- sync_connection
- sync_session
Viewsets
- class morango.api.viewsets.BufferViewSet(**kwargs)[source]
Bases:
ListModelMixin,GenericViewSet- get_queryset()[source]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- pagination_class
alias of
LimitOffsetPagination
- parser_classes = (<class 'morango.api.parsers.GzipParser'>, <class 'rest_framework.parsers.JSONParser'>)
- permission_classes = (<class 'morango.api.permissions.BufferPermissions'>,)
- serializer_class
alias of
BufferSerializer
- class morango.api.viewsets.CertificateChainViewSet(**kwargs)[source]
Bases:
ViewSet- permissions = (<class 'morango.api.permissions.CertificatePushPermissions'>,)
- class morango.api.viewsets.CertificateViewSet(**kwargs)[source]
Bases:
CreateModelMixin,RetrieveModelMixin,ListModelMixin,GenericViewSet- authentication_classes = (<class 'morango.api.permissions.BasicMultiArgumentAuthentication'>,)
- get_queryset()[source]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- permission_classes = (<class 'morango.api.permissions.CertificatePermissions'>,)
- serializer_class
alias of
CertificateSerializer
- class morango.api.viewsets.NonceViewSet(**kwargs)[source]
Bases:
CreateModelMixin,GenericViewSet- serializer_class
alias of
NonceSerializer
- class morango.api.viewsets.PublicKeyViewSet(**kwargs)[source]
Bases:
ReadOnlyModelViewSet- get_queryset()[source]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- permission_classes = (<class 'morango.api.permissions.CertificatePushPermissions'>,)
- serializer_class
alias of
SharedKeySerializer
- class morango.api.viewsets.SyncSessionViewSet(**kwargs)[source]
Bases:
DestroyModelMixin,RetrieveModelMixin,GenericViewSet- get_queryset()[source]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- serializer_class
alias of
SyncSessionSerializer
- class morango.api.viewsets.TransferSessionViewSet(**kwargs)[source]
Bases:
RetrieveModelMixin,UpdateModelMixin,DestroyModelMixin,GenericViewSet- get_queryset()[source]
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- serializer_class
alias of
TransferSessionSerializer
Permissions
- class morango.api.permissions.BasicMultiArgumentAuthentication[source]
Bases:
BasicAuthenticationHTTP Basic authentication against username (plus any other optional arguments) and password.