# 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 ctx():
#     return current_ctx.get_ctx()
# 
# @proxy
# def workflow_ctx():
#     return current_workflow_ctx.get_ctx()
# 
# class NotInContext(RuntimeError):
#     """Attempted accesing a context, but no context is available.
#     """
# 
# Path: cloudify/cluster.py
# class CloudifyClusterClient(CloudifyClient):
#     client_class = ClusterHTTPClient
# 
# def get_cluster_settings(filename=None):
#     filename = _get_cluster_settings_file(filename=filename)
#     if not filename:
#         return None
#     try:
#         with open(filename) as f:
#             return json.load(f)
#     except (IOError, ValueError):
#         return None
# 
# Path: cloudify/exceptions.py
# class HttpException(NonRecoverableError):
#     """
#     Wraps HTTP based exceptions that may be raised.
# 
#     :param url: The url the request was made to.
#     :param code: The response status code.
#     :param message: The underlying reason for the error.
# 
#     """
# 
#     def __init__(self, url, code, message, causes=None, **kwargs):
#         self.url = url
#         self.code = code
#         self.message = message
#         super(HttpException, self).__init__(str(self), causes=causes, **kwargs)
# 
#     def __str__(self):
#         return "{0} ({1}) : {2}".format(self.code, self.url, self.message)
# 
# class NonRecoverableError(Exception):
#     """
#     An error raised by plugins to denote that no retry should be attempted by
#     by the executing workflow engine.
#     """
#     def __init__(self, *args, **kwargs):
#         self.causes = kwargs.pop('causes', []) or []
#         super(NonRecoverableError, self).__init__(*args, **kwargs)


import os
import requests
import utils
from urlparse import urljoin
from cloudify_rest_client import CloudifyClient
from cloudify_rest_client.constants import VisibilityState
from cloudify import constants
from cloudify.state import ctx, workflow_ctx, NotInContext
from cloudify.cluster import CloudifyClusterClient, get_cluster_settings
from cloudify.exceptions import HttpException, NonRecoverableError

    @state.setter
    def state(self, value):
        self._state = value

    @property
    def dirty(self):
        return self._runtime_properties.dirty

    @property
    def host_id(self):
        return self._host_id

    @property
    def node_id(self):
        return self._node_id

    @property
    def relationships(self):
        return self._relationships


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:

# 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 ctx():
#     return current_ctx.get_ctx()
# 
# @proxy
# def workflow_ctx():
#     return current_workflow_ctx.get_ctx()
# 
# class NotInContext(RuntimeError):
#     """Attempted accesing a context, but no context is available.
#     """
# 
# Path: cloudify/cluster.py
# class CloudifyClusterClient(CloudifyClient):
#     client_class = ClusterHTTPClient
# 
# def get_cluster_settings(filename=None):
#     filename = _get_cluster_settings_file(filename=filename)
#     if not filename:
#         return None
#     try:
#         with open(filename) as f:
#             return json.load(f)
#     except (IOError, ValueError):
#         return None
# 
# Path: cloudify/exceptions.py
# class HttpException(NonRecoverableError):
#     """
#     Wraps HTTP based exceptions that may be raised.
# 
#     :param url: The url the request was made to.
#     :param code: The response status code.
#     :param message: The underlying reason for the error.
# 
#     """
# 
#     def __init__(self, url, code, message, causes=None, **kwargs):
#         self.url = url
#         self.code = code
#         self.message = message
#         super(HttpException, self).__init__(str(self), causes=causes, **kwargs)
# 
#     def __str__(self):
#         return "{0} ({1}) : {2}".format(self.code, self.url, self.message)
# 
# class NonRecoverableError(Exception):
#     """
#     An error raised by plugins to denote that no retry should be attempted by
#     by the executing workflow engine.
#     """
#     def __init__(self, *args, **kwargs):
#         self.causes = kwargs.pop('causes', []) or []
#         super(NonRecoverableError, self).__init__(*args, **kwargs)


# Path: cloudify/manager.py
import os
import requests
import utils
from urlparse import urljoin
from cloudify_rest_client import CloudifyClient
from cloudify_rest_client.constants import VisibilityState
from cloudify import constants
from cloudify.state import ctx, workflow_ctx, NotInContext
from cloudify.cluster import CloudifyClusterClient, get_cluster_settings
from cloudify.exceptions import HttpException, NonRecoverableError


    @state.setter
    def state(self, value):
        self._state = value

    @property
    def dirty(self):
        return self._runtime_properties.dirty

    @property
    def host_id(self):
        return self._host_id

    @property
    def node_id(self):
        return self._node_id

    @property
    def relationships(self):
        return self._relationships


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