EVENT_CLASS = _event.Event
EVENT_VERBOSITY_LEVEL = _event.NO_VERBOSE
def message_context_from_cloudify_context(ctx):
def message_context_from_workflow_context(ctx):
def message_context_from_sys_wide_wf_context(ctx):
def message_context_from_workflow_node_instance_context(ctx):
    def __init__(self, ctx, out_func, message_context_builder):
    def flush(self):
    def emit(self, record):
    def __init__(self, ctx, out_func=None):
    def __init__(self, ctx, out_func=None):
    def __init__(self, ctx, out_func=None):
    def __init__(self, ctx, out_func=None):
def init_cloudify_logger(handler, logger_name,
                         logging_level=logging.DEBUG):
def send_workflow_event(ctx, event_type,
                        message=None,
                        args=None,
                        additional_context=None,
                        out_func=None):
def send_sys_wide_wf_event(ctx, event_type, message=None, args=None,
                           additional_context=None, out_func=None):
def send_workflow_node_event(ctx, event_type,
                             message=None,
                             args=None,
                             additional_context=None,
                             out_func=None):
def send_plugin_event(ctx,
                      message=None,
                      args=None,
                      additional_context=None,
                      out_func=None):
def send_task_event(cloudify_context,
                    event_type,
                    message=None,
                    args=None,
                    additional_context=None,
                    out_func=None):
def _send_event(ctx, context_type, event_type,
                message, args, additional_context,
                out_func):
def populate_base_item(item, message_type):
def amqp_event_out(event):
def amqp_log_out(log):
def stdout_event_out(event):
def stdout_log_out(log):
def create_event_message_prefix(event):
def with_amqp_client(func):
    def wrapper(*args, **kwargs):
def _publish_message(client, message, message_type, logger):
    def __init__(self, context, socket, fallback_logger):
    def emit(self, record):
class CloudifyBaseLoggingHandler(logging.Handler):
class CloudifyPluginLoggingHandler(CloudifyBaseLoggingHandler):
class CloudifyWorkflowLoggingHandler(CloudifyBaseLoggingHandler):
class SystemWideWorkflowLoggingHandler(CloudifyBaseLoggingHandler):
class CloudifyWorkflowNodeLoggingHandler(CloudifyBaseLoggingHandler):
class ZMQLoggingHandler(logging.Handler): class NonRecoverableError(Exception):
class RecoverableError(Exception):
class OperationRetry(RecoverableError):
class HttpException(NonRecoverableError):
class CommandExecutionError(RuntimeError):
class CommandExecutionException(Exception):
class TimeoutException(Exception):
class ProcessExecutionError(RuntimeError):
class ClosedAMQPClientException(Exception):
    def __init__(self, *args, **kwargs):
    def __init__(self, message='', retry_after=None, causes=None, **kwargs):
    def __init__(self, url, code, message, causes=None, **kwargs):
    def __str__(self):
    def __init__(self, command, error=None):
    def __str__(self):
    def __init__(self, command, error, output, code):
    def __str__(self):
    def __init__(self, message, error_type=None, traceback=None, causes=None,
                 **kwargs):
    def __str__(self): class NotInContext(RuntimeError):
class CtxParameters(dict):
class CurrentContext(threading.local):
    def __init__(self, parameters):
    def __getattr__(self, attr):
    def set(self, ctx, parameters=None):
    def get_ctx(self):
    def get_parameters(self):
    def _get(self, attribute):
    def clear(self):
    def push(self, ctx, parameters=None):
def ctx():
def ctx_parameters():
def workflow_ctx():
def workflow_parameters(): class ContextCapabilities(object):
class CommonContext(object):
class BootstrapContext(object):
    class PolicyEngine(object):
    class CloudifyAgent(object):
class EntityContext(object):
class BlueprintContext(EntityContext):
class DeploymentContext(EntityContext):
class NodeContext(EntityContext):
class NodeInstanceContext(EntityContext):
class RelationshipContext(EntityContext):
class RelationshipSubjectContext(object):
class CloudifyContext(CommonContext):
class OperationContext(object):
class CloudifyAgentContext(object):
class PluginContext(str):
class ImmutableProperties(dict):
    def __init__(self, endpoint, instance):
    def _find_item(self, key):
    def __getitem__(self, key):
    def __contains__(self, key):
    def get_all(self):
    def __str__(self):
    def _capabilities(self):
    def __init__(self, ctx=None):
        def __init__(self, policy_engine):
        def start_timeout(self):
        def __init__(self, cloudify_agent):
        def min_workers(self):
        def max_workers(self):
        def user(self):
        def remote_execution_port(self):
        def agent_key_path(self):
        def broker_ip(self):
        def broker_user(self):
        def broker_pass(self):
        def broker_vhost(self):
        def broker_ssl_enabled(self):
        def cluster(self):
        def networks(self):
    def __init__(self, bootstrap_context):
    def cloudify_agent(self):
    def policy_engine(self):
    def resources_prefix(self):
    def broker_config(self, *args, **kwargs):
    def __init__(self, context, **_):
    def id(self):
    def id(self):
    def __init__(self, *args, **kwargs):
    def _get_node_if_needed(self):
    def id(self):
    def name(self):
    def properties(self):
    def type(self):
    def type_hierarchy(self):
    def __init__(self, *args, **kwargs):
    def _get_node_instance(self):
    def _get_node_instance_if_needed(self):
    def id(self):
    def runtime_properties(self):
    def runtime_properties(self, new_properties):
    def update(self, on_conflict=None):
    def refresh(self, force=False):
    def _get_node_instance_ip_if_needed(self):
    def host_ip(self):
    def relationships(self):
    def __init__(self, relationship_context, endpoint, node):
    def target(self):
    def type(self):
    def type_hierarchy(self):
    def __init__(self, context, endpoint, modifiable):
    def __init__(self, ctx=None):
    def _verify_in_node_context(self):
    def _verify_in_relationship_context(self):
    def _verify_in_node_or_relationship_context(self):
    def instance(self):
    def node(self):
    def source(self):
    def target(self):
    def type(self):
    def execution_id(self):
    def workflow_id(self):
    def rest_token(self):
    def tenant_name(self):
    def tenant(self):
    def task_id(self):
    def task_name(self):
    def task_target(self):
    def task_queue(self):
    def plugin(self):
    def operation(self):
    def agent(self):
    def capabilities(self):
    def logger(self):
    def bootstrap_context(self):
    def send_event(self, event):
    def provider_context(self):
    def get_resource(self,
                     resource_path):
    def get_resource_and_render(self,
                                resource_path,
                                template_variables=None):
    def download_resource(self,
                          resource_path,
                          target_path=None):
    def download_resource_and_render(self,
                                     resource_path,
                                     target_path=None,
                                     template_variables=None):
    def _init_cloudify_logger(self):
    def _add_context_to_template_variables(self, template_variables):
    def __init__(self, operation_context):
    def name(self):
    def retry_number(self):
    def max_retries(self):
    def retry(self, message=None, retry_after=None):
    def __init__(self, context):
    def script_path(self):
    def script_path(self, value):
    def clean_script(self):
    def _validate_agent_env():
    def init_script(self, agent_config=None):
    def install_script_download_link(self, agent_config=None, clean=True):
    def __init__(self, other=''):
    def name(self):
    def package_name(self):
    def package_version(self):
    def prefix(self):
    def workdir(self):
    def _raise():
    def __setitem__(self, key, value):
    def __delitem__(self, key):
    def update(self, E=None, **F):
    def clear(self):
    def pop(self, k, d=None):
    def popitem(self): CFY_EXEC_TEMPDIR_ENVVAR = 'CFY_EXEC_TEMP'
class ManagerVersion(object):
class LocalCommandRunner(object):
class CommandExecutionResponse(object):
class Internal(object):
    def __init__(self, raw_version):
    def greater_than(self, other):
    def equals(self, other):
    def __str__(self):
    def __eq__(self, other):
    def __gt__(self, other):
    def __lt__(self, other):
    def __ge__(self, other):
    def __le__(self, other):
    def __ne__(self, other):
def setup_logger(logger_name,
                 logger_level=logging.INFO,
                 handlers=None,
                 remove_existing_handlers=True,
                 logger_format=None,
                 propagate=True):
def format_exception(e):
def get_manager_file_server_url():
def get_manager_file_server_root():
def get_manager_rest_service_host():
def get_broker_ssl_cert_path():
def get_manager_rest_service_port():
def get_local_rest_certificate():
def _get_current_context():
def get_rest_token():
def get_tenant():
def get_tenant_name():
def get_is_bypass_maintenance():
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
def get_exec_tempdir():
def create_temp_folder():
def exception_to_error_cause(exception, tb):
    def __init__(self, logger=None, host='localhost'):
    def run(self, command,
            exit_on_failure=True,
            stdout_pipe=True,
            stderr_pipe=True,
            cwd=None,
            execution_env=None):
    def __init__(self, command, std_out, std_err, return_code):
def _shlex_split(command):
    def get_install_method(properties):
    def get_broker_ssl_options(ssl_enabled, cert_path):
    def get_broker_credentials(cloudify_agent):
    def _get_package_version(plugins_dir, package_name):
    def plugin_prefix(package_name=None, package_version=None,
                      deployment_id=None, plugin_name=None, tenant_name=None,
                      sys_prefix_fallback=True):
    def _change_tenant(ctx, tenant): class AMQPWrappedThread(Thread):
class _GlobalAMQPClient(object):
    def __init__(self, target, *args, **kwargs):
        def wrapped_target(*inner_args, **inner_kwargs):
    def __init__(self, *client_args, **client_kwargs):
    def register_caller(self):
    def unregister_caller(self):
    def __enter__(self):
    def __exit__(self, exc, val, tb):
    def publish_message(self, message, message_type):
    def close(self):
    def _make_client(self):
    def _connect(self):
    def _disconnect(self):
    def _handle_publish_message(self):
def init_amqp_client():
def get_amqp_client():
def get_event_amqp_client():
def close_amqp_client():
_STOP = object() REST_HOST_KEY = 'REST_HOST'
REST_PORT_KEY = 'REST_PORT'
CELERY_WORK_DIR_KEY = 'CELERY_WORK_DIR'
MANAGER_FILE_SERVER_URL_KEY = 'MANAGER_FILE_SERVER_URL'
MANAGER_FILE_SERVER_ROOT_KEY = 'MANAGER_FILE_SERVER_ROOT'
FILE_SERVER_RESOURCES_FOLDER = 'resources'
FILE_SERVER_BLUEPRINTS_FOLDER = 'blueprints'
FILE_SERVER_DEPLOYMENTS_FOLDER = 'deployments'
FILE_SERVER_UPLOADED_BLUEPRINTS_FOLDER = 'uploaded-blueprints'
FILE_SERVER_SNAPSHOTS_FOLDER = 'snapshots'
FILE_SERVER_PLUGINS_FOLDER = 'plugins'
FILE_SERVER_GLOBAL_RESOURCES_FOLDER = 'global-resources'
FILE_SERVER_TENANT_RESOURCES_FOLDER = 'tenant-resources'
FILE_SERVER_AUTHENTICATORS_FOLDER = 'authenticators'
AGENT_INSTALL_METHOD_NONE = 'none'
AGENT_INSTALL_METHOD_REMOTE = 'remote'
AGENT_INSTALL_METHOD_INIT_SCRIPT = 'init_script'
AGENT_INSTALL_METHOD_PROVIDED = 'provided'
AGENT_INSTALL_METHOD_PLUGIN = 'plugin'
AGENT_INSTALL_METHODS = [
    AGENT_INSTALL_METHOD_NONE,
    AGENT_INSTALL_METHOD_REMOTE,
    AGENT_INSTALL_METHOD_INIT_SCRIPT,
    AGENT_INSTALL_METHOD_PROVIDED,
    AGENT_INSTALL_METHOD_PLUGIN
]
AGENT_INSTALL_METHODS_SCRIPTS = [
    AGENT_INSTALL_METHOD_INIT_SCRIPT,
    AGENT_INSTALL_METHOD_PROVIDED,
    AGENT_INSTALL_METHOD_PLUGIN
]
COMPUTE_NODE_TYPE = 'cloudify.nodes.Compute'
BROKER_PORT_NO_SSL = 5672
BROKER_PORT_SSL = 5671
CELERY_TASK_RESULT_EXPIRES = 600
CLOUDIFY_TOKEN_AUTHENTICATION_HEADER = 'Authentication-Token'
LOCAL_REST_CERT_FILE_KEY = 'LOCAL_REST_CERT_FILE'
SECURED_PROTOCOL = 'https'
BROKER_SSL_CERT_PATH = 'BROKER_SSL_CERT_PATH'
BYPASS_MAINTENANCE = 'BYPASS_MAINTENANCE'
LOGGING_CONFIG_FILE = '/etc/cloudify/logging.conf'
CLUSTER_SETTINGS_PATH_KEY = 'CLOUDIFY_CLUSTER_SETTINGS_PATH'
MGMTWORKER_QUEUE = 'cloudify.management'
DEPLOYMENT = 'deployment'
NODE_INSTANCE = 'node-instance'
RELATIONSHIP_INSTANCE = 'relationship-instance'
DEFAULT_NETWORK_NAME = 'default' class AMQPWrappedThread(Thread):
    """
    creates an amqp client before calling the target method.
    This thread is always set as a daemon.
    """

    def __init__(self, target, *args, **kwargs):

        def wrapped_target(*inner_args, **inner_kwargs):
            with global_amqp_client:
                self.target_method(*inner_args, **inner_kwargs)

        self.target_method = target
        super(AMQPWrappedThread, self).__init__(target=wrapped_target, *args,
                                                **kwargs)
        self.started_amqp_client = global_amqp_client.client_started
        self.daemon = True def update_execution_status(execution_id, status, error=None):
    """
    Update the execution status of the execution denoted by ``execution_id``.

    :returns: The updated status
    """
    client = get_rest_client()
    return client.executions.update(execution_id, status, error) def get_rest_client(tenant=None):
    """
    :param tenant: optional tenant name to connect as
    :returns: A REST client configured to connect to the manager in context
    :rtype: cloudify_rest_client.CloudifyClient
    """
    cluster_settings = get_cluster_settings()
    if cluster_settings:
        client_class = CloudifyClusterClient
    else:
        client_class = CloudifyClient

    if not tenant:
        tenant = utils.get_tenant_name()

    # Handle maintenance mode
    headers = {}
    if utils.get_is_bypass_maintenance():
        headers['X-BYPASS-MAINTENANCE'] = 'True'

    return client_class(
        headers=headers,
        host=utils.get_manager_rest_service_host(),
        port=utils.get_manager_rest_service_port(),
        tenant=tenant,
        token=utils.get_rest_token(),
        protocol=constants.SECURED_PROTOCOL,
        cert=utils.get_local_rest_certificate()
    ) DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE = 1
    POLL_INTERVAL = 0.5
class CloudifyWorkflowRelationshipInstance(object):
class CloudifyWorkflowRelationship(object):
class CloudifyWorkflowNodeInstance(object):
class CloudifyWorkflowNode(object):
class _WorkflowContextBase(object):
class WorkflowNodesAndInstancesContainer(object):
class CloudifyWorkflowContext(
    _WorkflowContextBase,
    WorkflowNodesAndInstancesContainer
):
class CloudifySystemWideWorkflowContext(_WorkflowContextBase):
    class _ManagedCloudifyWorkflowContext(CloudifyWorkflowContext):
class CloudifyWorkflowContextInternal(object):
class LocalTasksProcessing(object):
class CloudifyWorkflowContextHandler(object):
class _CeleryAppController(object):
class RemoteContextHandler(CloudifyWorkflowContextHandler):
class RemoteCloudifyWorkflowContextHandler(RemoteContextHandler):
class SystemWideWfRemoteContextHandler(RemoteContextHandler):
class LocalCloudifyWorkflowContextHandler(CloudifyWorkflowContextHandler):
class Modification(object):
class ModificationNodes(WorkflowNodesAndInstancesContainer):
class WorkflowDeploymentContext(context.DeploymentContext):
    def __init__(self, ctx, node_instance, nodes_and_instances,
                 relationship_instance):
    def target_id(self):
    def target_node_instance(self):
    def relationship(self):
    def execute_source_operation(self,
                                 operation,
                                 kwargs=None,
                                 allow_kwargs_override=False,
                                 send_task_events=DEFAULT_SEND_TASK_EVENTS):
    def execute_target_operation(self,
                                 operation,
                                 kwargs=None,
                                 allow_kwargs_override=False,
                                 send_task_events=DEFAULT_SEND_TASK_EVENTS):
    def __init__(self, ctx, node, nodes_and_instances, relationship):
    def target_id(self):
    def target_node(self):
    def source_operations(self):
    def target_operations(self):
    def is_derived_from(self, other_relationship):
    def __init__(self, ctx, node, node_instance, nodes_and_instances):
    def set_state(self, state):
    def get_state(self):
    def send_event(self, event, additional_context=None):
    def execute_operation(self,
                          operation,
                          kwargs=None,
                          allow_kwargs_override=False,
                          send_task_events=DEFAULT_SEND_TASK_EVENTS):
    def id(self):
    def node_id(self):
    def relationships(self):
    def node(self):
    def modification(self):
    def scaling_groups(self):
    def logger(self):
    def _init_cloudify_logger(self):
    def contained_instances(self):
    def _add_contained_node_instance(self, node_instance):
    def get_contained_subgraph(self):
    def __init__(self, ctx, node, nodes_and_instances):
    def id(self):
    def type(self):
    def type_hierarchy(self):
    def properties(self):
    def plugins_to_install(self):
    def plugins(self):
    def host_id(self):
    def host_node(self):
    def number_of_instances(self):
    def relationships(self):
    def operations(self):
    def instances(self):
    def get_relationship(self, target_id):
    def __init__(self, ctx, remote_ctx_handler_cls):
    def graph_mode(self):
    def bootstrap_context(self):
    def internal(self):
    def execution_id(self):
    def workflow_id(self):
    def rest_token(self):
    def tenant_name(self):
    def local(self):
    def dry_run(self):
    def logger(self):
    def tenant(self):
    def _init_cloudify_logger(self):
    def send_event(self, event, event_type='workflow_stage',
                   args=None,
                   additional_context=None):
    def _execute_operation(self,
                           operation,
                           node_instance,
                           operations,
                           related_node_instance=None,
                           kwargs=None,
                           allow_kwargs_override=False,
                           send_task_events=DEFAULT_SEND_TASK_EVENTS):
    def _merge_dicts(merged_from, merged_into, allow_override=False):
    def update_execution_status(self, new_status):
    def _build_cloudify_context(self,
                                task_id,
                                task_name,
                                node_context):
    def execute_task(self,
                     task_name,
                     local=True,
                     task_queue=None,
                     task_target=None,
                     kwargs=None,
                     node_context=None,
                     send_task_events=DEFAULT_SEND_TASK_EVENTS,
                     total_retries=None,
                     retry_interval=None):
    def local_task(self,
                   local_task,
                   node=None,
                   info=None,
                   kwargs=None,
                   task_id=None,
                   name=None,
                   send_task_events=DEFAULT_SEND_TASK_EVENTS,
                   override_task_config=False,
                   total_retries=None,
                   retry_interval=None):
    def remote_task(self,
                    kwargs,
                    cloudify_context,
                    task_id,
                    task_queue=None,
                    task_target=None,
                    send_task_events=DEFAULT_SEND_TASK_EVENTS,
                    total_retries=None,
                    retry_interval=None):
    def _process_task(self, task):
    def __init__(self, workflow_context, raw_nodes, raw_node_instances):
    def nodes(self):
    def node_instances(self):
    def get_node(self, node_id):
    def get_node_instance(self, node_instance_id):
    def __init__(self, ctx):
    def _build_cloudify_context(self, *args):
    def __init__(self, ctx):
        def __enter__(self):
        def __exit__(self, *args, **kwargs):
    def deployments_contexts(self):
                def lazily_loaded_ctx(dep_ctx):
                    def lazy_ctx():
    def __init__(self, workflow_context, handler):
    def get_task_configuration(self):
    def get_subgraph_task_configuration(self):
    def _get_bootstrap_context(self):
    def task_graph(self):
    def graph_mode(self):
    def graph_mode(self, graph_mode):
    def start_event_monitors(self):
    def _start_event_monitor(self, tenant=None):
    def stop_event_monitors(self):
    def send_task_event(self, state, task, event=None):
    def send_workflow_event(self, event_type, message=None, args=None):
    def start_local_tasks_processing(self):
    def stop_local_tasks_processing(self):
    def add_local_task(self, task):
    def __init__(self, workflow_ctx, thread_pool_size=1):
    def start(self):
    def stop(self):
    def add_task(self, task):
    def _process_local_task(self, workflow_ctx):
    def __init__(self, workflow_ctx):
    def get_context_logging_handler(self):
    def get_node_logging_handler(self, workflow_node_instance):
    def bootstrap_context(self):
    def get_send_task_event_func(self, task):
    def get_update_execution_status_task(self, new_status):
    def get_send_node_event_task(self, workflow_node_instance,
                                 event, additional_context=None):
    def get_send_workflow_event_task(self, event, event_type, args,
                                     additional_context=None):
    def get_task(self, workflow_task, queue=None, target=None):
    def operation_cloudify_context(self):
    def get_set_state_task(self,
                           workflow_node_instance,
                           state):
    def get_get_state_task(self, workflow_node_instance):
    def send_workflow_event(self, event_type, message=None, args=None,
                            additional_context=None):
    def download_deployment_resource(self,
                                     resource_path,
                                     target_path=None):
    def start_deployment_modification(self, nodes):
    def finish_deployment_modification(self, modification):
    def rollback_deployment_modification(self, modification):
    def scaling_groups(self):
    def __init__(self):
    def make_subtask(self, tenant, target, *args, **kwargs):
    def celery_app(self, tenant, target):
    def send_task(self, workflow_task, task):
    def _add_polling(self, app, workflow_task, result):
    def _poll(self):
    def _remove_finished_tasks(self, results):
    def _update_task_state(self, async_result, workflow_task):
    def _stop_idle_app(self, app):
    def __init__(self, *args, **kwargs):
    def bootstrap_context(self):
    def get_send_task_event_func(self, task):
    def get_update_execution_status_task(self, new_status):
        def update_execution_status_task():
    def get_send_workflow_event_task(self, event, event_type, args,
                                     additional_context=None):
        def send_event_task():
    def get_task(self, workflow_task, queue=None, target=None):
    def send_task(self, workflow_task, task):
    def operation_cloudify_context(self):
    def get_set_state_task(self,
                           workflow_node_instance,
                           state):
        def set_state_task():
    def get_get_state_task(self, workflow_node_instance):
        def get_state_task():
    def download_deployment_resource(self,
                                     blueprint_id,
                                     deployment_id,
                                     tenant_name,
                                     resource_path,
                                     target_path=None):
    def get_node_logging_handler(self, workflow_node_instance):
    def get_context_logging_handler(self):
    def download_deployment_resource(self,
                                     resource_path,
                                     target_path=None):
    def start_deployment_modification(self, nodes):
    def finish_deployment_modification(self, modification):
    def rollback_deployment_modification(self, modification):
    def send_workflow_event(self, event_type, message=None, args=None,
                            additional_context=None):
    def get_send_node_event_task(self, workflow_node_instance,
                                 event, additional_context=None):
        def send_event_task():
    def scaling_groups(self):
    def get_context_logging_handler(self):
    def send_workflow_event(self, event_type, message=None, args=None,
                            additional_context=None):
    def __init__(self, workflow_ctx, storage):
    def get_context_logging_handler(self):
    def get_node_logging_handler(self, workflow_node_instance):
    def bootstrap_context(self):
    def get_send_task_event_func(self, task):
    def get_update_execution_status_task(self, new_status):
    def get_send_node_event_task(self, workflow_node_instance,
                                 event, additional_context=None):
        def send_event_task():
    def get_send_workflow_event_task(self, event, event_type, args,
                                     additional_context=None):
        def send_event_task():
    def get_task(self, workflow_task, queue=None, target=None):
    def operation_cloudify_context(self):
    def get_set_state_task(self,
                           workflow_node_instance,
                           state):
        def set_state_task():
    def get_get_state_task(self, workflow_node_instance):
        def get_state_task():
    def send_workflow_event(self, event_type, message=None, args=None,
                            additional_context=None):
    def download_deployment_resource(self,
                                     resource_path,
                                     target_path=None):
    def scaling_groups(self):
    def __init__(self, workflow_ctx, modification):
    def added(self):
    def removed(self):
    def id(self):
    def finish(self):
    def rollback(self):
    def __init__(self, modification, raw_nodes, raw_node_instances):
    def __init__(self, cloudify_context, workflow_ctx):
    def start_modification(self, nodes):
    def scaling_groups(self):
def task_config(fn=None, **arguments):
        def wrapper(*args, **kwargs):
        def partial_wrapper(func): LOGGING_CONFIG_FILE = '/etc/cloudify/logging.conf'
import importlib
import copy
import json
import logging
import os
import shutil
import subprocess
import sys
import tempfile
import threading
import traceback
import StringIO
import Queue
            import zmq
from time import sleep
from cloudify_rest_client.executions import Execution
from cloudify_rest_client.constants import VisibilityState
from cloudify_rest_client.exceptions import InvalidExecutionUpdateStatus
from cloudify import logs
from cloudify import exceptions
from cloudify import state
from cloudify import context
from cloudify import utils
from cloudify import amqp_client_utils
from cloudify import constants
from cloudify.amqp_client_utils import AMQPWrappedThread
from cloudify.manager import update_execution_status, get_rest_client
from cloudify.workflows import workflow_context
from cloudify.workflows import api
from cloudify.constants import LOGGING_CONFIG_FILE
    from cloudify_agent import VIRTUALENV
    from cloudify_agent.app import app as _app
        # in case something really bad happened. in the general case, output
        # that users want to see in log files, should go through the different
        # loggers
        output = open(os.path.join(dispatch_dir, 'output'), 'w')
        try:
            with open(os.path.join(dispatch_dir, 'input.json'), 'w') as f:
                json.dump({
                    'cloudify_context': self.cloudify_context,
                    'args': self.args,
                    'kwargs': self.kwargs
                }, f)
            env = self._build_subprocess_env()
            command_args = [sys.executable, __file__, dispatch_dir]
            try:
                subprocess.check_call(command_args,
                                      env=env,
                                      bufsize=1,
                                      close_fds=os.name != 'nt',
                                      stdout=output,
                                      stderr=output)
            except subprocess.CalledProcessError:
                # this means something really bad happened because we generally
                # catch all exceptions in the subprocess and exit cleanly
                # regardless.
                output.close()
                with open(os.path.join(dispatch_dir, 'output')) as f:
                    read_output = f.read()
                raise exceptions.NonRecoverableError(
                    'Unhandled exception occurred in operation dispatch: '
                    '{0}'.format(read_output))
            with open(os.path.join(dispatch_dir, 'output.json')) as f:
                dispatch_output = json.load(f)
            if dispatch_output['type'] == 'result':
                return dispatch_output['payload']
            elif dispatch_output['type'] == 'error':
                error = dispatch_output['payload']

                tb = error['traceback']
                exception_type = error['exception_type']
                message = error['message']

                known_exception_type_kwargs = error[
                    'known_exception_type_kwargs']
                causes = known_exception_type_kwargs.pop('causes', [])
                causes.append({
                    'message': message,
                    'type': exception_type,
                    'traceback': tb
                })
                known_exception_type_kwargs['causes'] = causes

                known_exception_type = getattr(exceptions,
                                               error['known_exception_type'])
                known_exception_type_args = error['known_exception_type_args']

                if error['append_message']:
                    known_exception_type_args.append(message)
                else:
                    known_exception_type_args.insert(0, message)
                raise known_exception_type(*known_exception_type_args,
                                           **known_exception_type_kwargs)
            else:
                raise exceptions.NonRecoverableError(
                    'Unexpected output type: {0}'
                    .format(dispatch_output['type']))
        finally:
            output.close()
            shutil.rmtree(dispatch_dir, ignore_errors=True)

    def _build_subprocess_env(self):
        env = os.environ.copy()

        # marker for code that only gets executed when inside the dispatched
        # subprocess, see usage in the imports section of this module
        env[CLOUDIFY_DISPATCH] = 'true'

        # This is used to support environment variables configurations for
        # central deployment based operations. See workflow_context to
        # understand where this value gets set initially
        env.update(self.cloudify_context.get('execution_env') or {})

        # Update PATH environment variable to include bin dir of current
        # virtualenv, and of plugin that includes the operation (if exists)
        bin_dir = 'Scripts' if os.name == 'nt' else 'bin'
        prefixes = [VIRTUALENV]
        plugin_dir = self._extract_plugin_dir()
        if plugin_dir:
            prefixes.insert(0, plugin_dir)
        # Code that concats all bin dirs and is then prepended to the existing
        # PATH environment variable
        task_bin_dirs = [os.path.join(prefix, bin_dir) for prefix in prefixes]
        task_bin_dirs = os.pathsep.join(task_bin_dirs)
        env['PATH'] = '{0}{1}{2}'.format(task_bin_dirs,
                                         os.pathsep,
                                         env.get('PATH', ''))

        # Update PYTHONPATH environment variable to include libraries
        # that belong to plugin running the current operation.
        if plugin_dir:
            if os.name == 'nt':
                plugin_pythonpath_dirs = [os.path.join(
                    plugin_dir, 'Lib', 'site-packages')]
            else:
                # In linux, if plugin has compiled dependencies
                # and was complied for 64bit arch, two libraries should
                # be added: lib and lib64
                plugin_pythonpath_dirs = [os.path.join(
                    plugin_dir, 'lib{0}'.format(b),
                    # e.g. python2.7
                    'python{0}.{1}'.format(sys.version_info[0],
                                           sys.version_info[1]),
                    'site-packages') for b in ['', '64']]
            plugin_pythonpath_dirs = os.pathsep.join(plugin_pythonpath_dirs)
            # Plugin PYTHONPATH is prepended to current PYTHONPATH
            env['PYTHONPATH'] = '{0}{1}{2}'.format(
                plugin_pythonpath_dirs,
                os.pathsep,
                env.get('PYTHONPATH', ''))

        if self.cloudify_context.get('bypass_maintenance'):

            env[constants.BYPASS_MAINTENANCE] = 'True'