Engine package

Engine

class engine.Engine(etcd, volume_manager, machine_manager, context)

Bases: utils.service.Service

Service responsible for the decision making inside the cobalt cluster.

static _create_executor(volume_manager, machine_manager, context)

Factory method for creating the Executor.

Parameters:
  • volume_manager (VolumeManager) – Data source for the volume model
  • machine_manager (MachineManager) – Data source for the machine model
  • context (dict) – Context for the Executor
Returns:

Return type:

Executor

static _create_leaser(lock, context)

Factory method for creating the Leaser responsible for leader election.

Parameters:
  • lock (etcd.Lock) – The lock on which to listen
  • context (dict) – Context for the leaser
Returns:

The Leaser object

Return type:

Lease

static _create_lock(etcd)

Factory method for creating the Engines leader lock.

Parameters:etcd (etcd.Client) – The client for the store to register the lock on
Returns:The lock object unarmed
Return type:etcd.Lock
_machine_heartbeat()

Main machine status change listener.

If between 2 runs of this method the number of machines changes or they are not the same machines, it resets the the Executor to force healing.

_quit

Returns – bool: Whether the service should quit or not

_run()

Main decision making loop.

It is responsible for making sure the Engine should process, reset the Executor and provide a Greenlet context switch after each operation.

start()

Start the Engine greenlets.

Returns:A list of Greenlets to be joined
Return type:[Greenlet]
stop()

A means of stopping the service gracefully.

Returns:Whether the code needed stopping or not
Return type:bool

Executor

class engine.Executor(volume_manager, machine_manager, context)

Bases: object

Class responsible for all decision making within the cluster.

_find_machine(volume)

Utility method to get an appropriate machine for a volume, based on required space and constraints.

Parameters:volume (etcd.Result) – The volume it should find place for
Returns:The matched machine with expanded value
Return type:etcd.Result
_next_state(volume)

Utility method for finding the next state of a volume based on transitions available.

Parameters:volume (etcd.Result) – And expanded volume representation
Returns:Next state
Return type:str
_process(volume)

Method for processing a volume.

It figures out the next state and tries to transition the object based on the state machine diagram

Parameters:volume (etcd.Result) – THe volume object to process
_process_cloning(volume)

Process cloning volume.

Apply the cloning transition.

Parameters:volume (etcd.Result) – An expanded version
_process_pending(volume)

Process pending volume.

Apply the pending transition.

Parameters:volume (etcd.Result) – An expanded version
_process_scheduling(volume)

Process scheduling volume.

Apply the scheduling transition or healing.

Parameters:volume (etcd.Result) – An expanded version
reset()

Reset the state of the Executor causing the next operation to pool and heal.

tick()

Method that causes the Executor to process one volume, either by watching or by polled state.

timeout()

Make the Executor sleep for the defined amount, configured inside context.

Lease

class engine.Lease(lock, context)

Bases: object

Engine Lease acquisition class.

It is responsible for watching the state of the Lock and refresh it so to maintain Leader status

acquire()

The acquisition loop that first acquires then refreshes it.

When the Leaser quits it will automatically release the leader status so others may take action

is_held

Helper property so to access the acquired state of the Lock easier.