コード例 #1
0
    def create(self):
        """
        Create the archive by first creating a uniquely named directory in the
        current working directory, adding the log files and debug information,
        creating a ``tar`` archive from the directory and finally removing the
        directory.
        """
        os.makedirs(self._archive_path)
        try:
            # Flocker version
            with self._open_logfile('flocker-version') as output:
                output.write(__version__.encode('utf-8') + b'\n')

            # Flocker logs.
            services = self._service_manager.flocker_services()
            for service_name, service_status in services:
                self._log_exporter.export_flocker(
                    service_name=service_name,
                    target_path=self._logfile_path(service_name)
                )

            # Syslog.
            self._log_exporter.export_all(self._logfile_path('syslog'))

            # Status of all services.
            with self._open_logfile('service-status') as output:
                services = self._service_manager.all_services()
                for service_name, service_status in services:
                    output.write(service_name + " " + service_status + "\n")

            # Docker version
            check_call(
                ['docker', 'version'],
                stdout=self._open_logfile('docker-version')
            )

            # Docker configuration
            check_call(
                ['docker', 'info'],
                stdout=self._open_logfile('docker-info')
            )

            # Kernel version
            self._open_logfile('uname').write(' '.join(os.uname()))

            # Distribution version
            self._open_logfile('os-release').write(
                open('/etc/os-release').read()
            )

            # Network configuration
            check_call(
                ['ip', 'addr'],
                stdout=self._open_logfile('ip-addr')
            )

            # Hostname
            self._open_logfile('hostname').write(gethostname() + '\n')

            # Partition information
            check_call(
                ['fdisk', '-l'],
                stdout=self._open_logfile('fdisk')
            )

            # Block Device and filesystem information
            check_call(
                ['lsblk', '--all'],
                stdout=self._open_logfile('lsblk')
            )

            # Hardware inventory
            self._open_logfile('lshw').write(list_hardware())

            # Create a single archive file
            archive_path = make_archive(
                base_name=self._archive_name,
                format='tar',
                root_dir=os.path.dirname(self._archive_path),
                base_dir=os.path.basename(self._archive_path),
            )
        finally:
            # Attempt to remove the source directory.
            rmtree(self._archive_path)
        return archive_path
コード例 #2
0
ファイル: testbrew.py プロジェクト: aminembarki/flocker
 def opt_version(self):
     """Print the program's version and exit."""
     sys.stdout.write(__version__.encode('utf-8') + b'\n')
     sys.exit(0)
コード例 #3
0
ファイル: testbrew.py プロジェクト: ienliven/flocker
 def opt_version(self):
     """Print the program's version and exit."""
     sys.stdout.write(__version__.encode('utf-8') + b'\n')
     sys.exit(0)
コード例 #4
0
    def create(self):
        os.makedirs(self._archive_path)
        args = sys.argv
        if not args[1:]:
            args.append("--all")
        for arg in args[1:]:
            if arg not in self._args:
                return ("Illegal argument,\n"
                        "--docker-log               Docker logs"
                        "\n--flocker-log            Flocker logs\n"
                        "--application-log          Reduxio-StorKit-Flocker logs\n"
                        "--sys-log                  system logs along with other system information\n"
                        "--all                      all logs including Flocker diagnosticlogs\n")

        try:
            if "--docker-log" in args or "--all" in args:
                # Docker Logs
                self._log_exporter.export_docker(service_name='docker', target_path=self._archive_path)

                # Docker version
                check_call(
                    ['docker', 'version'],
                    stdout=self._open_logfile('docker-version')
                )

                # Docker configuration
                check_call(
                    ['docker', 'info'],
                    stdout=self._open_logfile('docker-info')
                )

            if "--application-log" in args or "--all" in args:
                # Reduxio Flocker Driver Logs
                self.get_reduxio_logs()

            if "--flocker-log" in args or "--all" in args:
                # Flocker version
                with self._open_logfile('flocker-version') as output:
                    output.write(__version__.encode('utf-8') + b'\n')

                # Flocker logs.
                services = self._service_manager.flocker_services()
                for service_name, service_status in services:
                    self._log_exporter.export_flocker(
                        service_name=service_name,
                        target_path=self._logfile_path(service_name)
                    )

            if "--sys-log" in args or "--all" in args:
                # Syslog.
                self._log_exporter.export_all(self._logfile_path('syslog'))

                # Status of all services.
                with self._open_logfile('service-status') as output:
                    services = self._service_manager.all_services()
                    for service_name, service_status in services:
                        output.write(service_name + " " + service_status + "\n")

                # Kernel version
                self._open_logfile('uname').write(' '.join(os.uname()))

                # Distribution version
                self._open_logfile('os-release').write(
                    open('/etc/os-release').read()
                )

                # Network configuration
                check_call(
                    ['ip', 'addr'],
                    stdout=self._open_logfile('ip-addr')
                )

                # Hostname
                self._open_logfile('hostname').write(gethostname() + '\n')

                # Partition information
                check_call(
                    ['fdisk', '-l'],
                    stdout=self._open_logfile('fdisk')
                )

                # Block Device and filesystem information
                check_call(
                    ['lsblk', '--all'],
                    stdout=self._open_logfile('lsblk')
                )

                # Hardware inventory
                self._open_logfile('lshw').write(list_hardware())

            # Create a single archive file
            archive_path = make_archive(
                base_name=self._archive_name,
                format='tar',
                root_dir=os.path.dirname(self._archive_path),
                base_dir=os.path.basename(self._archive_path),
            )
        finally:
            # Attempt to remove the source directory.
            rmtree(self._archive_path)
        return archive_path