Context

class cloudify.context.ContextCapabilities(endpoint, instance)[source]

Bases: object

Maps from instance relationship target ids to their respective runtime properties

get_all()[source]

Returns all capabilities as dict.

class cloudify.context.CommonContext(ctx=None)[source]

Bases: object

class cloudify.context.BootstrapContext(bootstrap_context)[source]

Bases: object

Holds bootstrap context that was posted to the rest service. (usually during the bootstrap process).

class PolicyEngine(policy_engine)[source]

Bases: object

Cloudify policy engine related configuration

start_timeout

Returns the number of seconds to wait for the policy engine to start

class BootstrapContext.CloudifyAgent(cloudify_agent)[source]

Bases: object

Cloudify agent related bootstrap context properties.

min_workers

Returns the minimum number of workers for agent hosts.

max_workers

Returns the maximum number of workers for agent hosts.

user

Returns the username used when SSH-ing during agent installation.

remote_execution_port

Returns the port used when SSH-ing during agent installation.

agent_key_path

Returns the path to the key file on the management machine used when SSH-ing during agent installation.

BootstrapContext.cloudify_agent

Returns Cloudify agent related bootstrap context data

Return type:CloudifyAgent
BootstrapContext.policy_engine

Returns Cloudify policy engine related bootstrap context data

Return type:PolicyEngine
BootstrapContext.resources_prefix

Returns the resources prefix that was configured during bootstrap. An empty string is returned if the resources prefix was not configured.

class cloudify.context.EntityContext(context, **_)[source]

Bases: object

class cloudify.context.BlueprintContext(context, **_)[source]

Bases: cloudify.context.EntityContext

id

The blueprint id the plugin invocation belongs to.

class cloudify.context.DeploymentContext(context, **_)[source]

Bases: cloudify.context.EntityContext

id

The deployment id the plugin invocation belongs to.

class cloudify.context.NodeContext(*args, **kwargs)[source]

Bases: cloudify.context.EntityContext

id

The node’s id

name

The node’s name

properties

The node properties as dict (read-only). These properties are the properties specified in the blueprint.

class cloudify.context.NodeInstanceContext(*args, **kwargs)[source]

Bases: cloudify.context.EntityContext

id

The node instance id.

runtime_properties

The node instance runtime properties as a dict (read-only).

Runtime properties are properties set during the node instance’s lifecycle. Retrieving runtime properties involves a call to Cloudify’s storage.

update()[source]

Stores new/updated runtime properties for the node instance in context in Cloudify’s storage.

This method should be invoked only if its necessary to immediately update Cloudify’s storage with changes. Otherwise, the method is automatically invoked as soon as the task execution is over.

host_ip

Returns the node instance host ip address.

This values is derived by reading the host_id from the relevant node instance and then reading its ip runtime property or its node_state ip property.

relationships

Returns a list of this instance relationships

Returns:list of RelationshipContext
Return type:list
class cloudify.context.RelationshipContext(relationship_context, endpoint, node)[source]

Bases: cloudify.context.EntityContext

Holds relationship instance data

target

Returns a holder for target node and target instance

Return type:RelationshipSubjectContext
type

The relationship type

type_hierarchy

The relationship type hierarchy

class cloudify.context.RelationshipSubjectContext(context, endpoint, modifiable)[source]

Bases: object

Holds reference to node and node instance.

Obtained in relationship operations by ctx.source and ctx.target, and by iterating instance relationships and for each relationship, reading relationship.target

class cloudify.context.CloudifyContext(ctx=None)[source]

Bases: cloudify.context.CommonContext

A context object passed to plugins tasks invocations. The context object is used in plugins when interacting with the Cloudify environment:

from cloudify import ctx

@operation
def my_start(**kwargs):
    # port is a property that was configured on the current instance's
    # node
    port = ctx.node.properties['port']
    start_server(port=port)
instance

The node instance the operation is executed for.

This property is only relevant for NODE_INSTANCE context operations.

node

The node the operation is executed for.

This property is only relevant for NODE_INSTANCE context operations.

source

Provides access to the relationship’s operation source node and node instance.

This property is only relevant for relationship operations.

target

Provides access to the relationship’s operation target node and node instance.

This property is only relevant for relationship operations.

type

The type of this context.

Available values:

  • DEPLOYMENT
  • NODE_INSTANCE
  • RELATIONSHIP_INSTANCE
execution_id

The workflow execution id the plugin invocation was requested from. This is a unique value which identifies a specific workflow execution.

workflow_id

The workflow id the plugin invocation was requested from. For example:

install, uninstall etc...
task_id

The plugin’s task invocation unique id.

task_name

The full task name of the invoked task.

task_target

The task target (RabbitMQ queue name).

plugin

The plugin name of the invoked task.

operation

The current operation context.

capabilities

Maps from instance relationship target ids to their respective runtime properties

NOTE: This feature is deprecated, use ‘instance.relationships’ instead.

logger

A Cloudify context aware logger.

Use this logger in order to index logged messages in ElasticSearch using logstash.

bootstrap_context

System context provided during the bootstrap process

Return type:BootstrapContext
send_event(event)[source]

Send an event to rabbitmq

Parameters:event – the event message
provider_context

Gets provider context which contains provider specific metadata.

get_resource(resource_path)[source]

Retrieves a resource bundled with the blueprint as a string.

Parameters:resource_path – the path to the resource. Note that this path is relative to the blueprint file which was uploaded.
download_resource(resource_path, target_path=None)[source]

Retrieves a resource bundled with the blueprint and saves it under a local file.

Parameters:
  • resource_path – the path to the resource. Note that this path is relative to the blueprint file which was uploaded.
  • target_path – optional local path (including filename) to store the resource at on the local file system. If missing, the location will be a tempfile with a generated name.
Returns:

The path to the resource on the local file system (identical to target_path parameter if used).

raises an cloudify.exceptions.HttpException

Raises:

cloudify.exceptions.HttpException on any kind of HTTP Error.

Raises:

IOError if the resource failed to be written to the local file system.

class cloudify.context.OperationContext(operation_context)[source]

Bases: object

name

The name of the operation.

retry_number

The retry number (relevant for retries and recoverable errors).

max_retries

The maximum number of retries the operation can have.

retry(message=None, retry_after=None)[source]

Specifies that this operation should be retried.

Usage:
return ctx.operation.retry(message=’...’, retry_after=1000)
:param message A text message containing information about the reason
for retrying the operation.
:param retry_after How many seconds should the workflow engine wait
before re-executing the operation.