# Path: cloudify_agent/api/exceptions.py
# class DaemonException(BaseException):
# class DaemonStartupTimeout(DaemonException):
# class DaemonShutdownTimeout(DaemonException):
# class DaemonStillRunningException(DaemonException):
# class DaemonError(BaseException):
# class DaemonConfigurationError(DaemonError):
# class DaemonPropertiesError(DaemonError):
# class DaemonMissingMandatoryPropertyError(DaemonPropertiesError):
# class DaemonNotConfiguredError(DaemonError):
# class DaemonNotFoundError(DaemonError):
# class DaemonAlreadyExistsError(DaemonError):
# class DaemonNotImplementedError(DaemonError):
#     def __init__(self, timeout, name):
#     def __str__(self):
#     def __init__(self, timeout, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, param):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, process_management):
#     def __str__(self):
# 
# Path: cloudify_agent/api/utils.py
# class _Internal(object):
#     CLOUDIFY_DAEMON_STORAGE_DIRECTORY_KEY = 'CLOUDIFY_DAEMON_STORAGE_DIRECTORY'
#     CLOUDIFY_DAEMON_USER_KEY = 'CLOUDIFY_DAEMON_USER'
#     def get_daemon_storage_dir(cls):
#     def get_daemon_user(cls):
#     def get_storage_directory(cls, username=None):
#     def generate_agent_name():
#     def generate_new_agent_name(old_agent_name):
#     def daemon_to_dict(daemon):
#     def get_broker_url(agent):
# def get_agent_registered(name,
#                          celery_client,
#                          timeout=workflows_tasks.INSPECT_TIMEOUT):
# def get_windows_home_dir(username):
# def get_home_dir(username=None):
# def render_template_to_file(template_path, file_path=None, **values):
# def resource_to_tempfile(resource_path, executable=False):
# def get_resource(resource_path):
# def get_absolute_resource_path(resource_path):
# def content_to_file(content, file_path=None, executable=False):
# def env_to_file(env_variables, destination_path=None, posix=True):
# def stringify_values(dictionary):
# def purge_none_values(dictionary):
# def json_load(file_path):
# def json_loads(content):
# def safe_create_dir(path):
# def get_rest_client(rest_host,
#                     rest_port,
#                     rest_token,
#                     rest_tenant,
#                     ssl_cert_path,
#                     bypass_maintenance_mode=False):
# def _parse_comma_separated(ctx, param, value):
# def get_manager_file_server_url(hostname, port, scheme=None):
# def get_agent_version():
# def get_windows_basedir():
# def get_linux_basedir():
# def get_agent_basedir(is_windows=False):


import os
import json
from cloudify.utils import setup_logger
from cloudify_agent.api import exceptions
from cloudify_agent.api import utils
        from cloudify_agent.api.pm.base import Daemon
    """
    Factory class for manipulating various daemon instances.

    """
    def __init__(self, username=None, storage=None, logger=None):

        """
        :param username: the username the daemons are registered under.
                         if no username if passed, the currently logged user
                         will be used. this setting is used for computing
                         the storage directory, hence, if `storage` is passed,
                         the username will be ignored.
        :param storage: the storage directory where daemons are stored.
                        if no directory is passed, it will computed using the
                        `utils.get_storage_directory` function.
        :param logger: a logger to be used to log various subsequent
                       operations.

        """

        ######################################################################
        # `username` and `storage` are arguments because the default home
        # directory may change depending on how the daemon process is
        # executed. For example if running in a Windows Service, the home
        # directory changes. This means that we must the ability to specify
        # exactly where the storage directory is, and not let the code
        # auto-detect it in any scenario.
        #####################################################################

        self.username = username

# Path: cloudify_agent/api/exceptions.py
# class DaemonException(BaseException):
# class DaemonStartupTimeout(DaemonException):
# class DaemonShutdownTimeout(DaemonException):
# class DaemonStillRunningException(DaemonException):
# class DaemonError(BaseException):
# class DaemonConfigurationError(DaemonError):
# class DaemonPropertiesError(DaemonError):
# class DaemonMissingMandatoryPropertyError(DaemonPropertiesError):
# class DaemonNotConfiguredError(DaemonError):
# class DaemonNotFoundError(DaemonError):
# class DaemonAlreadyExistsError(DaemonError):
# class DaemonNotImplementedError(DaemonError):
#     def __init__(self, timeout, name):
#     def __str__(self):
#     def __init__(self, timeout, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, param):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, name):
#     def __str__(self):
#     def __init__(self, process_management):
#     def __str__(self):
# 
# Path: cloudify_agent/api/utils.py
# class _Internal(object):
#     CLOUDIFY_DAEMON_STORAGE_DIRECTORY_KEY = 'CLOUDIFY_DAEMON_STORAGE_DIRECTORY'
#     CLOUDIFY_DAEMON_USER_KEY = 'CLOUDIFY_DAEMON_USER'
#     def get_daemon_storage_dir(cls):
#     def get_daemon_user(cls):
#     def get_storage_directory(cls, username=None):
#     def generate_agent_name():
#     def generate_new_agent_name(old_agent_name):
#     def daemon_to_dict(daemon):
#     def get_broker_url(agent):
# def get_agent_registered(name,
#                          celery_client,
#                          timeout=workflows_tasks.INSPECT_TIMEOUT):
# def get_windows_home_dir(username):
# def get_home_dir(username=None):
# def render_template_to_file(template_path, file_path=None, **values):
# def resource_to_tempfile(resource_path, executable=False):
# def get_resource(resource_path):
# def get_absolute_resource_path(resource_path):
# def content_to_file(content, file_path=None, executable=False):
# def env_to_file(env_variables, destination_path=None, posix=True):
# def stringify_values(dictionary):
# def purge_none_values(dictionary):
# def json_load(file_path):
# def json_loads(content):
# def safe_create_dir(path):
# def get_rest_client(rest_host,
#                     rest_port,
#                     rest_token,
#                     rest_tenant,
#                     ssl_cert_path,
#                     bypass_maintenance_mode=False):
# def _parse_comma_separated(ctx, param, value):
# def get_manager_file_server_url(hostname, port, scheme=None):
# def get_agent_version():
# def get_windows_basedir():
# def get_linux_basedir():
# def get_agent_basedir(is_windows=False):


# Path: cloudify_agent/api/factory.py
import os
import json
from cloudify.utils import setup_logger
from cloudify_agent.api import exceptions
from cloudify_agent.api import utils
        from cloudify_agent.api.pm.base import Daemon

    """
    Factory class for manipulating various daemon instances.

    """
    def __init__(self, username=None, storage=None, logger=None):

        """
        :param username: the username the daemons are registered under.
                         if no username if passed, the currently logged user
                         will be used. this setting is used for computing
                         the storage directory, hence, if `storage` is passed,
                         the username will be ignored.
        :param storage: the storage directory where daemons are stored.
                        if no directory is passed, it will computed using the
                        `utils.get_storage_directory` function.
        :param logger: a logger to be used to log various subsequent
                       operations.

        """

        ######################################################################
        # `username` and `storage` are arguments because the default home
        # directory may change depending on how the daemon process is
        # executed. For example if running in a Windows Service, the home
        # directory changes. This means that we must the ability to specify
        # exactly where the storage directory is, and not let the code
        # auto-detect it in any scenario.
        #####################################################################

        self.username = username

        self.storage = storage or utils.internal.get_storage_directory(