pcf.core package

Submodules

pcf.core.aws_resource module

class pcf.core.aws_resource.AWSResource(particle_definition, resource_name, arn=None, session=None)

Bases: pcf.core.particle.Particle

The aws resource class inherits the particle class and adds the aws client. It takes as an input the resource_name (ie ec2) and the arn (if known)

_get_arn()

This gets the arn if it is not provided in the particle definition. This is implemented in each particle.

_get_client(session, **kwargs)
_get_resource(session, **kwargs)
apply(sync=True, cascade=False, validate_config=False, max_timeout=None, src_cascade=None, cache_ttl=15)

Triggers the state transition functions based on the state transition table.

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
  • validate_config (bool) – specify whether or not to call particle config validation function
  • max_timeout (int) – raise the max timeout exception after x(int) seconds reached, defaults to None
  • src_cascade ("parent","child", or "none") – direction of cascade logic
  • cache_ttl (int) – allows self.state_cache_ttl to be configured to any time interval
Returns:

State transition response

arn

Returns arn (str): The particle’s arn

client
get_identifier()
get_label()
get_region()
id_replace()

Looks through the particle definition for $lookup and replaces them with specified resource with given name

lookup

alias of pcf.util.aws.aws_lookup.AWSLookup

resource

Returns the aws resource object

set_region(session=None, region_name=None)

pcf.core.gcp_resource module

class pcf.core.gcp_resource.GCPResource(particle_definition, resource)

Bases: pcf.core.particle.Particle

The gcp resource class inherits the particle class and adds the gcp client. It takes as an input the resource library (ie datastore)

_get_client(**kwargs)

Returns a new resource client

Parameters:kwargs – See google docs for valid arguments (https://googlecloudplatform.github.io/google-cloud-python/latest/datastore/client.html)
Returns:Client
client

Client

Type:Returns

pcf.core.azure_resource module

class pcf.core.azure_resource.AzureResource(particle_definition)

Bases: pcf.core.particle.Particle

The azure resource class inherits the particle class and handles the clients for azure resources

compute_client

Uses client from cli so that users can use az login to get their credentials

Returns:Compute Client
network_client

Uses client from cli so that users can use az login to get their credentials

Returns:Network Client
resource_client

Uses client from cli so that users can use az login to get their credentials

Returns:Resource Client
storage_client

Uses client from cli so that users can use az login to get their credentials

Returns:Storage Client

pcf.core.particle module

class pcf.core.particle.MetaParticle

Bases: type

registry = {}
class pcf.core.particle.Particle(particle_definition)

Bases: object

_set_unique_keys()

Logic that sets keys from state definition using dot notation that are used to uniquely identify the instance of this particle

_start()

Logic that starts the particle. This is implemented for each individual particle

_stop()

Logic that stops the particle. This is implemented for each individual particle

_terminate()

Logic that terminates the particle. This is implemented for each individual particle

_update()

Logic that updates the particle. This is implemented for each individual particle

_validate_config()

Custom logic that that validates particle’s configurations

apply(sync=True, cascade=False, validate_config=False, max_timeout=None, src_cascade=None, cache_ttl=15)

Triggers the state transition functions based on the state transition table.

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
  • validate_config (bool) – specify whether or not to call particle config validation function
  • max_timeout (int) – raise the max timeout exception after x(int) seconds reached, defaults to None
  • src_cascade ("parent","child", or "none") – direction of cascade logic
  • cache_ttl (int) – allows self.state_cache_ttl to be configured to any time interval
Returns:

State transition response

apply_cascade(direction, desired_state=None, sync=True, src_cascade=None)
Parameters:
  • direction ("parent","child", or "none") – direction of cascade logic
  • desired_state – the desired state of the particle
  • sync (bool) – apply state transitions synchronously
  • src_cascade ("parent","child", or "none") – direction of cascade logic
flavor = None

Type of particle

get_and_replace_parent_variables()

Checks the particles desired state definition and checks to see if there are values that dependent on one of its parents. The format should look like $flavor:pcf_name$key_in_parent_current_state_definition. If there are values then this function looks for the corresponding parents and adds those values to this particles desired_state_definition.

get_attribute_value(attribute_key, state_definition_to_use='c>d', default=None)
get_current_state_definition()
Returns:current_state_definition
get_desired_state_definition()
Returns:desired_state_definition
get_pcf_id()

generates an pcf id using the flavor and the pcf name

Returns:pcf id
get_state()

Calls sync state and afterward returns the current state. Uses cached state if available.

Returns:state
get_state_transition_function(start_state, end_state)

Gets the corresponding transition function

Parameters:
  • start_state – starting state of the transition
  • end_state – ending state of the transition
is_state_definition_equivalent()

Determines if state definitions are equivalent

Returns:bool
is_state_equivalent(state1, state2)

Determines if states are equivalent.

Parameters:
  • state1
  • state2
Returns:

bool

links children and parents to each other

Parameters:pcf – pcf field

Adds child id to pcf children list and adds self to parent list

Parameters:
  • pcf – pcf field
  • child_pcf_id – child pcf id

Adds parent id to pcf parents list and adds self to children list

Parameters:
  • pcf – pcf field
  • parent_pcf_id – parent pcf id
measure()
register_state_transition(start_state, end_state, transition_function)

Registers the correct transition function

Parameters:
  • start_state – starting state of the transition
  • end_state – ending state of the transition
  • transition_function – associated transition function
set_desired_state(desired_state)

Sets the particle’s desired state

Arg:
desired_state (str): one of running,stopped,terminated.
start(sync=True, cascade=False)

Calls sync state then calls _start()

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
stop(sync=True, cascade=False)

Calls sync state then calls _stop()

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
sync_state()

Logic that determines what the current state of the particle is. This is implemented for each individual particle

terminate(sync=True, cascade=False)

Calls sync state then calls _terminate()

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
update(sync=True, cascade=False)

Calls sync state then calls _update()

Parameters:
  • sync (bool) – apply state transitions synchronously
  • cascade (bool) – apply state transitions to all family members
use_cached_state()

Returns true if the last cached time is greater than cache_ttl variable.

Returns:bool
validate_unique_id()

Throws an error if particle flavor or any unique identifiers are missing

wait()

pcf.core.particle_flavor_scanner module

exception pcf.core.particle_flavor_scanner.InvalidInputException(flavor)

Bases: Exception

exception pcf.core.particle_flavor_scanner.ParticleFlavorNotFoundError(flavor)

Bases: Exception

pcf.core.particle_flavor_scanner.get_particle_flavor(flavor: str)
pcf.core.particle_flavor_scanner.get_particle_flavor_registry()

pcf.core.pcf module

class pcf.core.pcf.PCF(pcf_definition_json)

Bases: object

add_particle(particle)
add_particles(particles)
apply(sync=True, cascade=False, validate_config=False, max_timeout=None, particles_dict=None)
get_particle(flavor, pcf_name)
get_particle_from_pcf_id(pcf_id)
get_particles(flavor=None)
load_particle_definition(particle_definition)
load_pcf_definition(pcf_definition_json)

pcf.core.pcf_exceptions module

exception pcf.core.pcf_exceptions.FlavorMissingException

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidCacheTTLException

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidConfigException(message='Particle config validation failed')

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidState(message='Attempted to set a state that is not valid')

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidTagsException(message='Tag validation failed')

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidUniqueKeysException(message='Particle unique keys validation failed')

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidUpdateParamException

Bases: Exception

exception pcf.core.pcf_exceptions.InvalidValueReplaceException(message='Invalid inputs for definition variable replace ($)')

Bases: Exception

exception pcf.core.pcf_exceptions.MaxTimeoutException(message='Max timeout reached while in apply()')

Bases: Exception

exception pcf.core.pcf_exceptions.MissingException(message='Attempted to use missing value')

Bases: Exception

exception pcf.core.pcf_exceptions.NoCallbackFunctionException

Bases: Exception

exception pcf.core.pcf_exceptions.NoCodeException

Bases: Exception

exception pcf.core.pcf_exceptions.NoResourceException

Bases: Exception

exception pcf.core.pcf_exceptions.ParentRequiredException

Bases: Exception

exception pcf.core.pcf_exceptions.ResourceLookupNotDefinedException(message='Resource lookup class not defined')

Bases: Exception

exception pcf.core.pcf_exceptions.TooManyResourceException

Bases: Exception

pcf.core.quasiparticle module

class pcf.core.quasiparticle.Quasiparticle(particle_definition)

Bases: pcf.core.particle.Particle

_fuse_particles()

This functions adds all particles to a pcf object (pcf_field). If a particle contains a multiplier field that number of particles are created with indexes appended to the particle’s unique identifier. If the quasiparticle has a parent, that parent is added to all particles in the quasiparticle. Finally link_particles is called on the pcf_field.

add_parents_to_particle(particle_definition)

Adds parents to particle_definition

Parameters:particle_definition
Returns:updated version
Return type:particle_definition
apply(sync=True, cascade=True, validate_config=False, rollback=False, max_timeout=None)

Calls apply all particles via pcf_field.apply()

Parameters:
  • sync (bool) – sync or async mode. Defaults to True
  • cascade (bool) – Defaults to True
  • validate_config (bool) – specify whether or not to call particle config validation function
  • rollback (bool) – If true then all particles will be terminated if there is an error during start. Defaults to False
  • max_timeout (int) – raise the max timeout exception after x(int) seconds reached, defaults to None
flavor = 'quasiparticle'
fuse()

To override fuse() functionality reimplement _fuse_particles()

Returns:_fuse_particles()
get_particle(flavor, pcf_name)

Returns a particle from the quasiparticle

Args:
flavor (str): pcf_name (str):
Returns:Particle
get_state()

If all the particles are in the same state then the quasiparticle returns that state. Otherwise will return State.pending

Returns:self.state
set_desired_state(desired_state)

Sets the desired state for all particles in the quasiparticle.

Parameters:desired_state (str) – one of running,stopped,terminated.
set_particle_state(flavor, desired_state, pcf_name=None)

Sets the state of a particular particle.

Parameters:
  • flavor (str) –
  • desired_state (State) –
  • pcf_name (str) – default is None
sync_state()

Logic that determines what the current state of the particle is. This is implemented for each individual particle

update_particle_definition(particle_definition, base_particle)

Updates a particle’s definition with a previous definition. Replaces any fields that are specified.

Parameters:
  • particle_definition (dict) – new particle defintion (can be empty)
  • base_particle (particle) – the particle that the new particle is inheriting from
Returns:

updated_particle_definition

Module contents

class pcf.core.State

Bases: enum.Enum

An enumeration.

pending = 4
running = 1
stopped = 2
terminated = 3