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[source]

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[source]

Returns the minimum number of workers for agent hosts.

max_workers[source]

Returns the maximum number of workers for agent hosts.

user[source]

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

remote_execution_port[source]

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

agent_key_path[source]

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

BootstrapContext.cloudify_agent[source]

Returns Cloudify agent related bootstrap context data

Return type:CloudifyAgent
BootstrapContext.policy_engine[source]

Returns Cloudify policy engine related bootstrap context data

Return type:PolicyEngine
BootstrapContext.resources_prefix[source]

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[source]

The blueprint id the plugin invocation belongs to.

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

Bases: cloudify.context.EntityContext

id[source]

The deployment id the plugin invocation belongs to.

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

Bases: cloudify.context.EntityContext

id[source]

The node’s id

name[source]

The node’s name

properties[source]

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[source]

The node instance id.

runtime_properties[source]

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[source]

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[source]

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[source]

Returns a holder for target node and target instance

Return type:RelationshipSubjectContext
type[source]

The relationship type

type_hierarchy[source]

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[source]

The node instance the operation is executed for.

This property is only relevant for NODE_INSTANCE context operations.

node[source]

The node the operation is executed for.

This property is only relevant for NODE_INSTANCE context operations.

source[source]

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

This property is only relevant for relationship operations.

target[source]

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

This property is only relevant for relationship operations.

type[source]

The type of this context.

Available values:

  • DEPLOYMENT
  • NODE_INSTANCE
  • RELATIONSHIP_INSTANCE
execution_id[source]

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

workflow_id[source]

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

install, uninstall etc...
task_id[source]

The plugin’s task invocation unique id.

task_name[source]

The full task name of the invoked task.

task_target[source]

The task target (RabbitMQ queue name).

plugin[source]

The plugin name of the invoked task.

operation[source]

The node operation name which is mapped to this task invocation. For example: cloudify.interfaces.lifecycle.start

capabilities[source]

Maps from instance relationship target ids to their respective runtime properties

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

logger[source]

A Cloudify context aware logger.

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

bootstrap_context[source]

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[source]

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.