# Path: cloudify/constants.py
# 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'
# 
# Path: cloudify/amqp_client_utils.py
# 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()
# 
# Path: cloudify/event.py
# HIGH_VERBOSE = 3
# MEDIUM_VERBOSE = 2
# LOW_VERBOSE = 1
# NO_VERBOSE = 0
# class Event(object):
#     def __init__(self, event, verbosity_level=None):
#     def __str__(self):
#     def has_output(self):
#     def operation_info(self):
#     def text(self):
#     def log_level(self):
#     def timestamp(self):
#     def printable_timestamp(self):
#     def event_type_indicator(self):
#     def operation(self):
#     def node_id(self):
#     def source_id(self):
#     def target_id(self):
#     def deployment_id(self):
#     def event_type(self):
#     def is_log_message(self):
# 
# Path: cloudify/exceptions.py
# class ClosedAMQPClientException(Exception):
#     """Raised when attempting to use a closed AMQP client"""
#     pass


import sys
import logging
import json
import datetime
from functools import wraps
from cloudify import constants
from cloudify import amqp_client_utils
from cloudify import event as _event
from cloudify.exceptions import ClosedAMQPClientException
    from cloudify.context import CloudifyContext


def stdout_event_out(event):
    populate_base_item(event, 'cloudify_event')
    output = create_event_message_prefix(event)
    if output:
        sys.stdout.write('{0}\n'.format(output))
        sys.stdout.flush()


def stdout_log_out(log):
    populate_base_item(log, 'cloudify_log')
    output = create_event_message_prefix(log)
    if output:
        sys.stdout.write('{0}\n'.format(output))
        sys.stdout.flush()


def create_event_message_prefix(event):
    event_obj = EVENT_CLASS(event, verbosity_level=EVENT_VERBOSITY_LEVEL)
    if not event_obj.has_output:
        return None
    return str(event_obj)


def with_amqp_client(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        """Calls the wrapped func with an AMQP client instance."""
        # call the wrapped func with the amqp client

# Path: cloudify/constants.py
# 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'
# 
# Path: cloudify/amqp_client_utils.py
# 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()
# 
# Path: cloudify/event.py
# HIGH_VERBOSE = 3
# MEDIUM_VERBOSE = 2
# LOW_VERBOSE = 1
# NO_VERBOSE = 0
# class Event(object):
#     def __init__(self, event, verbosity_level=None):
#     def __str__(self):
#     def has_output(self):
#     def operation_info(self):
#     def text(self):
#     def log_level(self):
#     def timestamp(self):
#     def printable_timestamp(self):
#     def event_type_indicator(self):
#     def operation(self):
#     def node_id(self):
#     def source_id(self):
#     def target_id(self):
#     def deployment_id(self):
#     def event_type(self):
#     def is_log_message(self):
# 
# Path: cloudify/exceptions.py
# class ClosedAMQPClientException(Exception):
#     """Raised when attempting to use a closed AMQP client"""
#     pass


# Path: cloudify/logs.py
import sys
import logging
import json
import datetime
from functools import wraps
from cloudify import constants
from cloudify import amqp_client_utils
from cloudify import event as _event
from cloudify.exceptions import ClosedAMQPClientException
    from cloudify.context import CloudifyContext



def stdout_event_out(event):
    populate_base_item(event, 'cloudify_event')
    output = create_event_message_prefix(event)
    if output:
        sys.stdout.write('{0}\n'.format(output))
        sys.stdout.flush()


def stdout_log_out(log):
    populate_base_item(log, 'cloudify_log')
    output = create_event_message_prefix(log)
    if output:
        sys.stdout.write('{0}\n'.format(output))
        sys.stdout.flush()


def create_event_message_prefix(event):
    event_obj = EVENT_CLASS(event, verbosity_level=EVENT_VERBOSITY_LEVEL)
    if not event_obj.has_output:
        return None
    return str(event_obj)


def with_amqp_client(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        """Calls the wrapped func with an AMQP client instance."""
        # call the wrapped func with the amqp client

        with amqp_client_utils.get_event_amqp_client() as client: