# Path: cloudify/cluster.py
# def _get_cluster_settings_file(filename=None):
# def get_cluster_settings(filename=None):
# def set_cluster_settings(settings, filename=None):
# def get_cluster_nodes(filename=None):
# def set_cluster_nodes(nodes, filename=None):
# def get_cluster_active(filename=None):
# def set_cluster_active(node, filename=None):
# def get_cluster_amqp_settings():
# def delete_cluster_settings(filename=None):
# def is_cluster_configured(filename=None):
# def _parse_url(broker_url):
# def config_from_broker_urls(active, nodes):
#     def __init__(self, *args, **kwargs):
#     def do_request(self, *args, **kwargs):
#     def _use_node(self, node_ip):
# class ClusterHTTPClient(HTTPClient):
# class CloudifyClusterClient(CloudifyClient):
# 
# 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/state.py
# @proxy
# def workflow_ctx():
#     return current_workflow_ctx.get_ctx()
# 
# @proxy
# def ctx():
#     return current_ctx.get_ctx()
# 
# Path: cloudify/exceptions.py
# class CommandExecutionException(Exception):
# 
#     """
#     Indicates a command was executed, however some sort of error happened,
#     resulting in a non-zero return value of the process.
# 
#     :param command: The command executed
#     :param code: process exit code
#     :param error: process stderr output
#     :param output: process stdout output
#     """
# 
#     def __init__(self, command, error, output, code):
#         self.command = command
#         self.error = error
#         self.code = code
#         self.output = output
#         Exception.__init__(self, self.__str__())
# 
#     def __str__(self):
#         return "Command '{0}' executed with an error." \
#                "\ncode: {1}" \
#                "\nerror: {2}" \
#                "\noutput: {3}" \
#             .format(self.command, self.code,
#                     self.error or None,
#                     self.output or None)


from contextlib import contextmanager
from distutils.version import LooseVersion
from cloudify import cluster, constants
from cloudify.state import workflow_ctx, ctx
from cloudify.exceptions import CommandExecutionException
import logging
import os
import random
import shlex
import ssl
import string
import subprocess
import sys
import tempfile
import traceback
import StringIO
        logger.addHandler(handler)

    logger.setLevel(logger_level)
    if not propagate:
        logger.propagate = False
    return logger


def format_exception(e):
    """Human-readable representation of an exception, as a bytestring.

    The canonical way to print an exception, str(e), also made to handle
    unicode exception messages in python 2.
    Additionally, if the exception message is incompatible with utf-8,
    (which should only happen in extreme cases, such as NUL bytes),
    fallback to repr().
    """
    try:
        return str(e)
    except UnicodeEncodeError:
        try:
            return unicode(e).encode('utf-8')
        except UnicodeEncodeError:
            return repr(e)


def get_manager_file_server_url():
    """
    Returns the manager file server base url.
    """

# Path: cloudify/cluster.py
# def _get_cluster_settings_file(filename=None):
# def get_cluster_settings(filename=None):
# def set_cluster_settings(settings, filename=None):
# def get_cluster_nodes(filename=None):
# def set_cluster_nodes(nodes, filename=None):
# def get_cluster_active(filename=None):
# def set_cluster_active(node, filename=None):
# def get_cluster_amqp_settings():
# def delete_cluster_settings(filename=None):
# def is_cluster_configured(filename=None):
# def _parse_url(broker_url):
# def config_from_broker_urls(active, nodes):
#     def __init__(self, *args, **kwargs):
#     def do_request(self, *args, **kwargs):
#     def _use_node(self, node_ip):
# class ClusterHTTPClient(HTTPClient):
# class CloudifyClusterClient(CloudifyClient):
# 
# 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/state.py
# @proxy
# def workflow_ctx():
#     return current_workflow_ctx.get_ctx()
# 
# @proxy
# def ctx():
#     return current_ctx.get_ctx()
# 
# Path: cloudify/exceptions.py
# class CommandExecutionException(Exception):
# 
#     """
#     Indicates a command was executed, however some sort of error happened,
#     resulting in a non-zero return value of the process.
# 
#     :param command: The command executed
#     :param code: process exit code
#     :param error: process stderr output
#     :param output: process stdout output
#     """
# 
#     def __init__(self, command, error, output, code):
#         self.command = command
#         self.error = error
#         self.code = code
#         self.output = output
#         Exception.__init__(self, self.__str__())
# 
#     def __str__(self):
#         return "Command '{0}' executed with an error." \
#                "\ncode: {1}" \
#                "\nerror: {2}" \
#                "\noutput: {3}" \
#             .format(self.command, self.code,
#                     self.error or None,
#                     self.output or None)


# Path: cloudify/utils.py
from contextlib import contextmanager
from distutils.version import LooseVersion
from cloudify import cluster, constants
from cloudify.state import workflow_ctx, ctx
from cloudify.exceptions import CommandExecutionException
import logging
import os
import random
import shlex
import ssl
import string
import subprocess
import sys
import tempfile
import traceback
import StringIO

        logger.addHandler(handler)

    logger.setLevel(logger_level)
    if not propagate:
        logger.propagate = False
    return logger


def format_exception(e):
    """Human-readable representation of an exception, as a bytestring.

    The canonical way to print an exception, str(e), also made to handle
    unicode exception messages in python 2.
    Additionally, if the exception message is incompatible with utf-8,
    (which should only happen in extreme cases, such as NUL bytes),
    fallback to repr().
    """
    try:
        return str(e)
    except UnicodeEncodeError:
        try:
            return unicode(e).encode('utf-8')
        except UnicodeEncodeError:
            return repr(e)


def get_manager_file_server_url():
    """
    Returns the manager file server base url.
    """

    if cluster.is_cluster_configured():