Models package

Managers

class models.manager.base_manager.BaseManager(client)

Bases: object

Base repository class for objects.

KEY = 'cobalt'

Directory name in ETCD.

_load_from_etcd(data)

Utility method to expand result objects.

Parameters:data ([etcd.result] | etcd.result) – The iterable or a single result object not expanded
Returns:Return type matches given input (if it is a list->list), and all result objects are expanded
Return type:etcd.result
all()

Get all objects maintained by this repository.

Returns:0 etcd.Result: The directory object NOT expanded 1 [etcd.Result] List of The objects with expanded values
Return type:tuple
all_keys()

Get all object keys maintained by this repository.

Returns:A list of key strings
Return type:[str]
by_id(entry_id)

Get the object referenced by id.

Parameters:entry_id (str) – The id to fetch prefixed with the object dir
Returns:The expanded result if key exists, or None if key not found
Return type:etcd.Result
create(data, suffix='')

Create a new object inside the data store.

Parameters:
  • data (dict) – Dictionary containing values you want to store
  • suffix (str) – If given then it will be used as a key while storing
Returns:

THe created object expanded

Return type:

etcd.Result

delete(entity)

Delete an object from the data store.

Parameters:entity (etcd.Result) – The object one wants to be deleted, expanded or not
Returns:The state of the operation
Return type:bool
get_id_from_key(key)

Utility method for getting the id from an internal key.

Parameters:key (str) – THe objects key
Returns:The respective id
Return type:str
update(entity)

Update an existing object from the data store.

Parameters:entity (etcd.Result) – An expanded result object that needs to be serialized
Returns:The resulting object expanded, or None if Etcd failed
Return type:etcd.Result
watch(index=None, timeout=0)

Watch the directory of the repository for changes indefinably starting from an index.

Parameters:
  • index (int) – The index to start watching from
  • timeout (int) – The timeout after which we give up
Returns:

Result expanded or None if timeout occurred

Return type:

etcd.Result

class models.manager.VolumeManager(client)

Bases: models.manager.base_manager.BaseManager

Volume repository class.

KEY = 'cobalt/volumes'

Directory name in ETCD

by_node(node)

Returns all volumes that have the node provided.

Parameters:node (str) – The node you are interested in
Returns:A list of expanded results
Return type:[etcd.Result]
by_states(states=None)

Returns all volumes that have the state provided.

Parameters:states ([str]) – A list of interested states
Returns:A list of expanded results
Return type:[etcd.Result]
create(data, *_)

Similar to what the base manager does only that it adds the updated timestamp.

static filter_states(volumes, states)

Utility method for filtering a list of volume results by state.

Parameters:
  • volumes ([etcd.Result]) – The objects that should get filtered
  • states ([str]) – A list of interested in states
Returns:

Returns only the matching objects

Return type:

[etcd.Result]

get_lock(volume_id, purpose='clone')

Utility method to get a Lock instance for a specific purpose and a related object id.

Parameters:
  • volume_id (str) – The id for which resource it should focus on
  • purpose (str) – The operation that needs locking
Returns:

The respective Lock object unarmed

Return type:

etcd.Lock

update(volume)

Similar to what the base manager does only that it updates a volumes updated timestamp.

class models.manager.MachineManager(client)

Bases: models.manager.base_manager.BaseManager

Machine repository class.

KEY = 'cobalt/machines'

Directory name in ETCD.

Schemas

class models.manager.VolumeSchema(extra=None, only=(), exclude=(), prefix='', strict=False, many=False, context=None, load_only=(), dump_only=(), partial=False)

Bases: marshmallow.schema.Schema

marshmallow schema for the entire object.

get_attribute(attr, obj, default)

Utility method for getting the id for the representation.

class models.manager.VolumeAttributeSchema(extra=None, only=(), exclude=(), prefix='', strict=False, many=False, context=None, load_only=(), dump_only=(), partial=False)

Bases: marshmallow.schema.Schema

Marshmallow schema for the requested subsection.

class models.manager.VolumeControlSchema(extra=None, only=(), exclude=(), prefix='', strict=False, many=False, context=None, load_only=(), dump_only=(), partial=False)

Bases: marshmallow.schema.Schema

Marshmallow schema for the control subsection.