# Path: cloudify_agent/installer/exceptions.py
# class AgentInstallerConfigurationError(exceptions.NonRecoverableError):
#     def __init__(self, msg):
# 
# 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 sys
import logging
from fabric import Connection
from paramiko import RSAKey, ECDSAKey, Ed25519Key, SSHException
from cloudify._compat import reraise, StringIO
from cloudify.utils import CommandExecutionResponse
from cloudify.utils import setup_logger
from cloudify.exceptions import CommandExecutionException
from cloudify.exceptions import CommandExecutionError
from cloudify_agent.installer import exceptions
from cloudify_agent.api import utils as api_utils
from cloudify_rest_client.utils import is_kerberos_env

        # logger
        self.logger = logger or setup_logger('fabric_runner')

        # silence paramiko
        logging.getLogger('paramiko.transport').setLevel(logging.WARNING)

        # connection details
        self.port = port or DEFAULT_REMOTE_EXECUTION_PORT
        self.password = password
        self.user = user
        self.host = host
        self.key = key
        self.tmpdir = tmpdir

        # fabric environment
        self.env = self._set_env()
        self.env.update(fabric_env or {})
        self._connection = None

        self._validate_ssh_config()
        if validate_connection:
            self.validate_connection()

    def _validate_ssh_config(self):
        if not self.host:
            raise exceptions.AgentInstallerConfigurationError('Missing host')
        if not self.user:
            raise exceptions.AgentInstallerConfigurationError('Missing user')
        if not is_kerberos_env() and not self.password and not self.key:

# Path: cloudify_agent/installer/exceptions.py
# class AgentInstallerConfigurationError(exceptions.NonRecoverableError):
#     def __init__(self, msg):
# 
# 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/installer/runners/fabric_runner.py
import os
import sys
import logging
from fabric import Connection
from paramiko import RSAKey, ECDSAKey, Ed25519Key, SSHException
from cloudify._compat import reraise, StringIO
from cloudify.utils import CommandExecutionResponse
from cloudify.utils import setup_logger
from cloudify.exceptions import CommandExecutionException
from cloudify.exceptions import CommandExecutionError
from cloudify_agent.installer import exceptions
from cloudify_agent.api import utils as api_utils
from cloudify_rest_client.utils import is_kerberos_env


        # logger
        self.logger = logger or setup_logger('fabric_runner')

        # silence paramiko
        logging.getLogger('paramiko.transport').setLevel(logging.WARNING)

        # connection details
        self.port = port or DEFAULT_REMOTE_EXECUTION_PORT
        self.password = password
        self.user = user
        self.host = host
        self.key = key
        self.tmpdir = tmpdir

        # fabric environment
        self.env = self._set_env()
        self.env.update(fabric_env or {})
        self._connection = None

        self._validate_ssh_config()
        if validate_connection:
            self.validate_connection()

    def _validate_ssh_config(self):
        if not self.host:
            raise exceptions.AgentInstallerConfigurationError('Missing host')
        if not self.user:
            raise exceptions.AgentInstallerConfigurationError('Missing user')
        if not is_kerberos_env() and not self.password and not self.key:

            raise exceptions.AgentInstallerConfigurationError(