Пример #1
0
def _copy_resources_to_hosts(_hosts):
    ssh = SshHandler.get()
    try:
        ssh.test_hosts(_hosts)
    except Exception as e:
        raise e

    resources_dir = os.path.dirname(os.path.realpath(__file__))
    modules_dir = "{0}/modules".format(resources_dir)
    common_dir = "{0}/common".format(resources_dir)
    conf_file = "{0}/defaults.conf".format(__recipes_directory)

    if util.has_localhost(_hosts):
        _copy_resources_local()
        util.remove_localhost(_hosts)

    generate_conf_file(conf_file)

    """ Copy modules and conf to hosts """
    for host in _hosts:
        try:
            ssh.transfer_file(modules_dir, __recipes_directory, host)
            ssh.transfer_file(common_dir, __recipes_directory, host)
            ssh.transfer_file(conf_file, __recipes_directory, host)
        except Exception as e:
            raise e
Пример #2
0
def _run_recipe_in_hosts(recipe_file, recipes_dir, _hosts):
    hosts = set(_hosts)
    ssh = SshHandler.get()

    if util.has_localhost(hosts):
        _run_recipe_local(recipe_file)
        util.remove_localhost(hosts)

    for host in hosts:
        try:
            ssh.transfer_file(recipe_file, recipes_dir, host)
            ssh.run_recipe(recipe_file, host)
        except Exception as e:
            raise e
Пример #3
0
    def get_logs(self, _hosts):
        hosts = set(_hosts)
        basename = os.path.splitext(util.LOG_FILE)[0]
        connection = None

        util.remove_localhost(hosts)

        for host in hosts:
            new_name = "{0}-{1}.log".format(basename, host)
            try:
                connection = self.connect(self.ssh_user, self.ssh_private_key,
                                          host)
                sftp = connection.open_sftp()
                sftp.get(util.HOST_LOG_FILE, new_name)
            except:
                LOG.warning("clearstack: cannot get log file from {0}".format(
                    host))
            finally:
                if connection:
                    connection.close()
Пример #4
0
    def test_hosts(self, _hosts):
        hosts = set(_hosts)
        connection = None
        conf = Controller.get().CONF

        util.remove_localhost(hosts)

        if not conf['CONFIG_PRIVATE_SSH_KEY'] and hosts:
            raise Exception("CONFIG_PRIVATE_SSH_KEY: missing private key")

        for host in hosts:
            try:
                connection = self.connect(self.ssh_user, self.ssh_private_key,
                                          host)
                self.test_python_in_host(host, connection)
            except Exception as e:
                raise Exception("host {0}: {1}".format(host, str(e)))
            finally:
                if connection:
                    connection.close()
Пример #5
0
def validate_ssh_key(ssh_key):
    hosts = utils.get_all_hosts()
    util.remove_localhost(hosts)
    if len(hosts) != 0:
        validators.file(ssh_key)