API

Models

class morango.models.Buffer(*args, **kwargs)[source]

Bases: AbstractStore

Buffer is 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

  • transfer_session_id (ForeignKey to ~) – Transfer session

  • model_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>
rmcb_list()[source]
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.parent is a ForwardManyToOneDescriptor instance.

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 ~) – Parent

  • profile (CharField) – Profile

  • scope_definition_id (ForeignKey to ~) – Scope definition

  • scope_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.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

check_certificate()[source]
classmethod deserialize(serialized, signature)[source]
classmethod generate_root_certificate(scope_def_id, **extra_scope_params)[source]
get_scope()[source]
has_private_key()[source]
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.parent is a ForwardManyToOneDescriptor instance.

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.

classmethod save_certificate_chain(cert_chain, expected_last_id=None)[source]
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.parent is a ForwardManyToOneDescriptor instance.

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.

serialize()[source]
serialized

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

sign(value)[source]
sign_certificate(cert_to_sign)[source]
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.children is a ReverseManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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')
verify(value, signature)[source]
class morango.models.DatabaseIDModel(*args, **kwargs)[source]

Bases: UUIDModelMixin

Model 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)
classmethod get_or_create_current_database_id()[source]
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.children is a ReverseManyToOneDescriptor instance.

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: AbstractCounter

DatabaseMaxCounter is 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]
classmethod get_instance_counters_for_partitions(partitions, is_producer=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.

classmethod update_fsics(fsics, sync_filter, v2_format=False)[source]
class morango.models.DeletedModels(*args, **kwargs)[source]

Bases: Model

DeletedModels helps 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(template, params={})[source]

Bases: object

contains_partition(partition)[source]
is_subset_of(other)[source]
class morango.models.HardDeletedModels(*args, **kwargs)[source]

Bases: Model

HardDeletedModels helps 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: Model

InstanceIDModel is 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 ~) – Database

  • counter (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.parent is a ForwardManyToOneDescriptor instance.

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_current_instance_and_increment_counter()[source]
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).

get_proquint()[source]
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: UUIDModelMixin

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

classmethod use_nonce(nonce_value)[source]
uuid_input_fields = 'RANDOM'
class morango.models.PrivateKeyField(*args, **kwargs)[source]

Bases: RSAKeyBaseField

from_db_value(value, expression, connection)[source]
get_prep_value(value)[source]

Perform preliminary non-db specific value checks and conversions.

to_python(value)[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

class morango.models.PublicKeyField(*args, **kwargs)[source]

Bases: RSAKeyBaseField

from_db_value(value, expression, connection)[source]
get_prep_value(value)[source]

Perform preliminary non-db specific value checks and conversions.

to_python(value)[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

class morango.models.RecordMaxCounter(*args, **kwargs)[source]

Bases: AbstractCounter

RecordMaxCounter keeps 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.parent is a ForwardManyToOneDescriptor instance.

store_model_id
class morango.models.RecordMaxCounterBuffer(*args, **kwargs)[source]

Bases: AbstractCounter

RecordMaxCounterBuffer is where combinations of instance ID and counters (from RecordMaxCounter) are stored temporarily, until they are sent or received by another morango instance.

Parameters:
  • id (AutoField) – Id

  • instance_id (UUIDField) – Instance id

  • counter (IntegerField) – Counter

  • transfer_session_id (ForeignKey to ~) – Transfer session

  • model_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.parent is a ForwardManyToOneDescriptor instance.

transfer_session_id
class morango.models.Scope(definition, params)[source]

Bases: object

is_subset_of(other)[source]
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.children is a ReverseManyToOneDescriptor instance.

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.

get_description(params)[source]
get_scope(params)[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>
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.

classmethod retrieve_by_id(scope_def_id)[source]
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.

class morango.models.SharedKey(*args, **kwargs)[source]

Bases: Model

The public key is publically available via the api/morango/v1/publickey endpoint. Applications who would like to allow certificates to be pushed to the server must also enable ALLOW_CERTIFICATE_PUSHING. Clients generate a Certificate object and set the public_key field 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

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.

classmethod get_or_create_shared_key(force_new=False)[source]

Create a shared public/private key pair for certificate pushing, if the settings allow.

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>
private_key

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.

class morango.models.Store(*args, **kwargs)[source]

Bases: AbstractStore

Store is 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

  • id (UUIDField) – Id

  • dirty_bit (BooleanField) – Dirty bit

  • deserialization_error (TextField) – Deserialization error

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

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.children is a ReverseManyToOneDescriptor instance.

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: Model

SyncSession holds 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 certificate

  • server_certificate_id (ForeignKey to ~) – Server certificate

  • profile (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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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: UUIDModelMixin

SyncableModel is 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}'
class Meta[source]

Bases: object

abstract = False
cached_clean_fields(fk_lookup_cache)[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 – A dictionary to use as a cache to prevent querying the database if a FK exists in the cache, having already been validated

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.

static compute_namespaced_id(partition_value, source_id_value, model_name)[source]
deferred_clean_fields()[source]

Calls .clean_fields() but excludes all foreign key fields and instead returns them as a dictionary for deferred batch processing

Returns:

A dictionary containing lists of `ForeignKeyReference`s keyed by the name of the model being referenced by the FK

delete(using=None, keep_parents=False, hard_delete=False, *args, **kwargs)[source]
classmethod deserialize(dict_model)[source]

Returns an unsaved class object based on the valid properties passed in.

classmethod merge_conflict(current, push)[source]
morango_fields_not_to_serialize = ()
morango_model_dependencies = ()
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 SyncableModel subclass, except for those specifically blacklisted, are returned in a dict.

class morango.models.SyncableModelManager(*args, **kwargs)[source]

Bases: ManagerFromSyncableModelQuerySet

class morango.models.SyncableModelQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

classmethod as_manager()[source]
update(update_dirty_bit_to=True, **kwargs)[source]

Update all elements in the current QuerySet, setting all the given fields to the appropriate values.

class morango.models.TransferSession(*args, **kwargs)[source]

Bases: Model

TransferSession holds 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 session

  • start_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.children is a ReverseManyToOneDescriptor instance.

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_filter()[source]
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_touched_record_ids_for_model(model)[source]
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.children is a ReverseManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.

update_state(stage=None, stage_status=None)[source]
class morango.models.UUIDField(*args, **kwargs)[source]

Bases: CharField

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

from_db_value(value, expression, connection)[source]
get_db_prep_value(value, connection, prepared=False)[source]

Return field’s value prepared for interacting with the database backend.

Used by the default implementations of get_db_prep_save().

get_default()[source]

Returns the default value for this field.

get_internal_type()[source]
prepare_value(value)[source]
to_python(value)[source]

Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can’t be converted. Return the converted value. Subclasses should override this.

class morango.models.UUIDModelMixin(*args, **kwargs)[source]

Bases: Model

Mixin 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

class Meta[source]

Bases: object

abstract = False
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: Session

Wrapper 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. Returns Response object.

Parameters:
  • method – method for the new Request object.

  • url – URL for the new Request object.

  • 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-objects for multipart encoding upload.

  • auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.

  • timeout (float or tuple) – (optional) How long 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.

  • 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 to False, 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 to False may 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

reset_transfer_bytes()[source]

Resets the bytes_sent and bytes_received values to zero

The main module to be used for initiating the synchronization of data between morango instances.

class morango.sync.syncsession.Connection[source]

Bases: object

Abstraction 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
close()[source]
close_sync_session(sync_session)[source]
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:

SyncSessionClient

default_chunk_size = 500
get_remote_certificates(primary_partition, scope_def_id=None)[source]
push_signed_client_certificate_chain(local_parent_cert, scope_definition_id, scope_params)[source]
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:

SyncSessionClient

server_info
session
urlresolve(endpoint, lookup=None)[source]
class morango.sync.syncsession.PullClient(*args, **kwargs)[source]

Bases: TransferClient

Sync class to pull from server

context
controller
signals
sync_connection
sync_session
class morango.sync.syncsession.PushClient(*args, **kwargs)[source]

Bases: TransferClient

Sync client for pushing to a server

context
controller
signals
sync_connection
sync_session
class morango.sync.syncsession.SyncClientSignals(**kwargs_defaults)[source]

Bases: SyncSignal

Class 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_session and NetworkSyncConnection.close

controller
get_pull_client()[source]

returns PullClient

get_push_client()[source]

returns PushClient

initiate_pull(sync_filter)[source]

Deprecated - Please use get_pull_client and use the client :param sync_filter: Filter

initiate_push(sync_filter)[source]

Deprecated - Please use get_push_client and use the client

signals
sync_connection
sync_session
class morango.sync.syncsession.TransferClient(sync_connection, sync_session, controller)[source]

Bases: object

Base class for handling common operations for initiating syncing and other related operations.

context
controller
property current_transfer_session
finalize()[source]
initialize(sync_filter)[source]
Parameters:

sync_filter – Filter

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

run()[source]

Execute the transferring portion of the sync

signals
sync_connection
sync_session
morango.sync.syncsession.compress_string(s, compresslevel=9)[source]

Viewsets

class morango.api.viewsets.BufferViewSet(**kwargs)[source]

Bases: ListModelMixin, GenericViewSet

create(request)[source]
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

create(request)[source]
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'>,)
create(request)[source]
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.MorangoInfoViewSet(**kwargs)[source]

Bases: ViewSet

retrieve(request, pk=None)[source]
class morango.api.viewsets.NonceViewSet(**kwargs)[source]

Bases: CreateModelMixin, GenericViewSet

create(request)[source]
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

create(request)[source]
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)

perform_destroy(syncsession)[source]
serializer_class

alias of SyncSessionSerializer

class morango.api.viewsets.TransferSessionViewSet(**kwargs)[source]

Bases: RetrieveModelMixin, UpdateModelMixin, DestroyModelMixin, GenericViewSet

async_allowed()[source]
Returns:

A boolean if async ops are allowed by client and self

create(request)[source]
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)

perform_destroy(transfer_session)[source]
serializer_class

alias of TransferSessionSerializer

update(request, *args, **kwargs)[source]
morango.api.viewsets.controller_signal_logger(context=None)[source]
morango.api.viewsets.get_ip(request)[source]

Permissions

class morango.api.permissions.BasicMultiArgumentAuthentication[source]

Bases: BasicAuthentication

HTTP Basic authentication against username (plus any other optional arguments) and password.

authenticate_credentials(userargs, password, request=None)[source]

Authenticate the userargs and password against Django auth backends. The “userargs” string may be just the username, or a querystring-encoded set of params.

class morango.api.permissions.BufferPermissions[source]

Bases: BasePermission

has_permission(request, view)[source]

Return True if permission is granted, False otherwise.

class morango.api.permissions.CertificatePermissions[source]

Bases: BasePermission

has_permission(request, view)[source]

Return True if permission is granted, False otherwise.

class morango.api.permissions.CertificatePushPermissions[source]

Bases: BasePermission

has_permission(request, view)[source]

Return True if permission is granted, False otherwise.

message = 'Server does not allow certificate pushing.'