Ejemplo n.º 1
0
def capture_journal(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    """
    formatter = journald_json_formatter(output_file)
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'journalctl',
            b'--lines', b'0',
            b'--output', b'export',
            b'--follow',
            # Only bother with units we care about:
            b'-u', b'docker',
            b'-u', b'flocker-control',
            b'-u', b'flocker-dataset-agent',
            b'-u', b'flocker-container-agent',
            b'-u', b'flocker-docker-plugin',
        ],
        handle_stdout=formatter,
    )
    ran.addErrback(write_failure, logger=None)
    # Deliver a final empty line to process the last message
    ran.addCallback(lambda ignored: formatter(b""))
Ejemplo n.º 2
0
def capture_journal(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    :return deferred: that will run the journalctl command
    """
    formatter = journald_json_formatter(output_file)
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'journalctl',
            b'--lines', b'0',
            b'--output', b'export',
            b'--follow',
            # Only bother with units we care about:
            b'-u', b'docker',
            b'-u', b'flocker-control',
            b'-u', b'flocker-dataset-agent',
            b'-u', b'flocker-container-agent',
            b'-u', b'flocker-docker-plugin',
        ],
        handle_stdout=formatter,
    )
    ran.addErrback(write_failure, logger=None)
    # Deliver a final empty line to process the last message
    ran.addCallback(lambda ignored: formatter(b""))
    return ran
Ejemplo n.º 3
0
def capture_journal(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    """
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'journalctl',
            b'--lines', b'0',
            b'--follow',
            # Only bother with units we care about:
            b'-u', b'docker',
            b'-u', b'flocker-control',
            b'-u', b'flocker-dataset-agent',
            b'-u', b'flocker-container-agent',
            b'-u', b'flocker-docker-plugin',
        ],
        handle_stdout=lambda line: output_file.write(line + b'\n')
    )
    ran.addErrback(write_failure, logger=None)
Ejemplo n.º 4
0
def capture_upstart(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    :return deferred: that will run the tail command
    """
    # note that we are using tail -F to keep retrying and not to exit when we
    # reach the end of the file, as we expect the logs to keep being generated
    formatter = TailFormatter(output_file, host)
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'tail',
            b'-F',
            b'/var/log/flocker/flocker-control.log',
            b'/var/log/flocker/flocker-dataset-agent.log',
            b'/var/log/flocker/flocker-container-agent.log',
            b'/var/log/flocker/flocker-docker-plugin.log',
            b'/var/log/upstart/docker.log',
        ],
        handle_stdout=formatter.handle_output_line,
    )
    ran.addErrback(write_failure, logger=None)
    # Deliver a final empty line to process the last message
    ran.addCallback(lambda ignored: formatter.handle_output_line(b""))
    return ran
Ejemplo n.º 5
0
def capture_upstart(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    :return deferred: that will run the tail command
    """
    # note that we are using tail -F to keep retrying and not to exit when we
    # reach the end of the file, as we expect the logs to keep being generated
    formatter = TailFormatter(output_file, host)
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'tail',
            b'-F',
            b'/var/log/flocker/flocker-control.log',
            b'/var/log/flocker/flocker-dataset-agent.log',
            b'/var/log/flocker/flocker-container-agent.log',
            b'/var/log/flocker/flocker-docker-plugin.log',
            b'/var/log/upstart/docker.log',
        ],
        handle_stdout=formatter.handle_output_line,
    )
    ran.addErrback(write_failure, logger=None)
    # Deliver a final empty line to process the last message
    ran.addCallback(lambda ignored: formatter.handle_output_line(b""))
    return ran
Ejemplo n.º 6
0
def capture_journal(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    """
    ran = run_ssh(
        reactor=reactor,
        host=host,
        username='******',
        command=[
            b'journalctl',
            b'--lines',
            b'0',
            b'--follow',
            # Only bother with units we care about:
            b'-u',
            b'docker',
            b'-u',
            b'flocker-control',
            b'-u',
            b'flocker-dataset-agent',
            b'-u',
            b'flocker-container-agent',
        ],
        handle_stdout=lambda line: output_file.write(line + b'\n'))
    ran.addErrback(write_failure, logger=None)
Ejemplo n.º 7
0
def remote_command(client_ip, command):
    """
    Run ``command`` on ``client_ip``.

    :returns: A ``Deferred`` when the command has completed or failed.
    """
    process_output = []
    d = run_ssh(reactor,
                'ubuntu',
                client_ip,
                command,
                handle_stdout=process_output.append)
    d.addCallback(lambda process_result: (process_result, process_output))
    return d
Ejemplo n.º 8
0
    def run(self, node, command_args, handle_stdout):
        """
        Run a command using SSH.

        :param Node node: Node to run command on.
        :param [str] command_args: List of command line arguments.
        :param callable handle_stdout: Function to handle each line of output.
        :return: Deferred, firing when complete.
        """
        d = run_ssh(
            self.reactor,
            self.user,
            self.cluster.public_address(node.public_address).exploded,
            command_args,
            handle_stdout=handle_stdout,
        )
        return d
Ejemplo n.º 9
0
    def run(self, node, command_args, handle_stdout):
        """
        Run a command using SSH.

        :param Node node: Node to run command on.
        :param [str] command_args: List of command line arguments.
        :param callable handle_stdout: Function to handle each line of output.
        :return: Deferred, firing when complete.
        """
        d = run_ssh(
            self.reactor,
            self.user,
            self.cluster.public_address(node.public_address).exploded,
            command_args,
            handle_stdout=handle_stdout,
        )
        return d
Ejemplo n.º 10
0
def remote_command(client_ip, command):
    """
    Run ``command`` on ``client_ip``.

    :returns: A ``Deferred`` when the command has completed or failed.
    """
    process_output = []
    d = run_ssh(
        reactor,
        'ubuntu',
        client_ip,
        command,
        handle_stdout=process_output.append
    )
    d.addCallback(
        lambda process_result: (process_result, process_output)
    )
    return d
Ejemplo n.º 11
0
    def run(self, node, command_args, handle_stdout):
        """
        Run a command using SSH.

        :param Node node: Node to run command on.
        :param [str] command_args: List of command line arguments.
        :param callable handle_stdout: Function to handle each line of output.
        :return: Deferred, firing when complete.
        """
        hostname = node.public_address.exploded
        # Map hostname to public IP address. If not in mapping, use hostname.
        public_ip = self.node_mapping.get(hostname, hostname)
        d = run_ssh(
            self.reactor,
            self.user,
            public_ip,
            command_args,
            handle_stdout=handle_stdout,
        )
        return d
Ejemplo n.º 12
0
def capture_upstart(reactor, host, output_file):
    """
    SSH into given machine and capture relevant logs, writing them to
    output file.

    :param reactor: The reactor.
    :param bytes host: Machine to SSH into.
    :param file output_file: File to write to.
    :return deferred: that will run the tail command
    """
    # note that we are using tail -F to keep retrying and not to exit when we
    # reach the end of the file, as we expect the logs to keep being generated
    results = []
    for (directory, service) in [
            (b"flocker", b"flocker-control"),
            (b"flocker", b"flocker-dataset-agent"),
            (b"flocker", b"flocker-container-agent"),
            (b"flocker", b"flocker-docker-plugin"),
            (b"upstart", b"docker")]:
        path = FilePath(b'/var/log/').child(directory).child(service + b'.log')
        formatter = TailFormatter(output_file, host, service)
        ran = run_ssh(
            reactor=reactor,
            host=host,
            username='******',
            command=[
                b'tail',
                b'-F',
                path.path
            ],
            handle_stdout=formatter.handle_output_line,
        )
        ran.addErrback(write_failure, logger=None)
        # Deliver a final empty line to process the last message
        ran.addCallback(lambda ignored, formatter=formatter:
                        formatter.handle_output_line(b""))
        results.append(ran)
    return gather_deferreds(results)