Ejemplo n.º 1
0
def create_and_upload_archive(include_logs, include_configs, include_content, include_system_info,
                              debug=False):
    try:
        plain_text_output_path = create_archive(include_logs=include_logs,
                                                include_configs=include_configs,
                                                include_content=include_content,
                                                include_system_info=include_system_info)
        encrypted_output_path = encrypt_archive(archive_file_path=plain_text_output_path)
        upload_archive(archive_file_path=encrypted_output_path)
    except Exception:
        LOG.exception('Failed to upload tarball to StackStorm', exc_info=True)
        plain_text_output_path = None
        encrypted_output_path = None
    else:
        tarball_name = os.path.basename(encrypted_output_path)
        LOG.info('Debug tarball successfully uploaded to StackStorm (name=%s)' % (tarball_name))
        LOG.info('When communicating with support, please let them know the tarball name - %s' %
                 (tarball_name))
    finally:
        # Remove tarballs
        if plain_text_output_path:
            assert(plain_text_output_path.startswith('/tmp'))
            remove_file(file_path=plain_text_output_path)
        if encrypted_output_path:
            assert(encrypted_output_path.startswith('/tmp'))
            remove_file(file_path=encrypted_output_path)
Ejemplo n.º 2
0
def create_and_upload_archive(include_logs,
                              include_configs,
                              include_content,
                              include_system_info,
                              debug=False):
    try:
        plain_text_output_path = create_archive(
            include_logs=include_logs,
            include_configs=include_configs,
            include_content=include_content,
            include_system_info=include_system_info)
        encrypted_output_path = encrypt_archive(
            archive_file_path=plain_text_output_path)
        upload_archive(archive_file_path=encrypted_output_path)
    except Exception:
        LOG.exception('Failed to upload tarball to StackStorm', exc_info=True)
        plain_text_output_path = None
        encrypted_output_path = None
    else:
        LOG.info('Debug tarball successfully uploaded to StackStorm')
    finally:
        # Remove tarballs
        if plain_text_output_path:
            assert (plain_text_output_path.startswith('/tmp'))
            remove_file(file_path=plain_text_output_path)
        if encrypted_output_path:
            assert (encrypted_output_path.startswith('/tmp'))
            remove_file(file_path=encrypted_output_path)
Ejemplo n.º 3
0
def create_and_upload_archive(include_logs,
                              include_configs,
                              include_content,
                              include_system_info,
                              include_shell_commands=False,
                              user_info=None,
                              debug=False,
                              config_yaml=None):
    if config_yaml:
        s3_bucket_url = get_config_details('s3_bucket', option_name='url')
        gpg_key_fingerprint = get_config_details(
            'gpg', option_name='gpg_key_fingerprint')
        gpg_key = get_config_details('gpg', option_name='gpg_key')
        company_name = get_config_details('company_name', option_name='name')
    else:
        s3_bucket_url = S3_BUCKET_URL
        gpg_key_fingerprint = GPG_KEY_FINGERPRINT
        gpg_key = GPG_KEY
        company_name = COMPANY_NAME
    try:
        plain_text_output_path = create_archive(
            include_logs=include_logs,
            include_configs=include_configs,
            include_content=include_content,
            include_system_info=include_system_info,
            include_shell_commands=include_shell_commands,
            user_info=user_info,
            debug=debug,
            config_yaml=config_yaml)
        encrypted_output_path = encrypt_archive(
            archive_file_path=plain_text_output_path,
            key_fingerprint=gpg_key_fingerprint,
            key_gpg=gpg_key)
        upload_archive(archive_file_path=encrypted_output_path,
                       bucket_url=s3_bucket_url)
    except Exception:
        LOG.exception('Failed to upload tarball to %s' % company_name,
                      exc_info=True)
        plain_text_output_path = None
        encrypted_output_path = None
    else:
        tarball_name = os.path.basename(encrypted_output_path)
        LOG.info('Debug tarball successfully uploaded to %s (name=%s)' %
                 (company_name, tarball_name))
        LOG.info(
            'When communicating with support, please let them know the tarball name - %s'
            % tarball_name)

    finally:
        # Remove tarballs
        if plain_text_output_path:
            assert plain_text_output_path.startswith('/tmp')
            remove_file(file_path=plain_text_output_path)
        if encrypted_output_path:
            assert encrypted_output_path.startswith('/tmp')
            remove_file(file_path=encrypted_output_path)
Ejemplo n.º 4
0
    def run(self, encrypt=False, upload=False, existing_file=None):
        """
        Run the specified steps.

        :param encrypt: If true, encrypt the archive file.
        :param encrypt: ``bool``
        :param upload: If true, upload the resulting file.
        :param upload: ``bool``
        :param existing_file: Path to an existing archive file. If not specified a new
        archive will be created.
        :param existing_file: ``str``
        """
        temp_files = []

        try:
            if existing_file:
                working_file = existing_file
            else:
                # Create a new archive if an existing file hasn't been provided
                working_file = self.create_archive()
                if not encrypt and not upload:
                    LOG.info('Debug tarball successfully '
                             'generated and can be reviewed at: %s' %
                             working_file)
                else:
                    temp_files.append(working_file)

            if encrypt:
                working_file = self.encrypt_archive(
                    archive_file_path=working_file)
                if not upload:
                    LOG.info(
                        'Encrypted debug tarball successfully generated at: %s'
                        % working_file)
                else:
                    temp_files.append(working_file)

            if upload:
                self.upload_archive(archive_file_path=working_file)
                tarball_name = os.path.basename(working_file)
                LOG.info(
                    'Debug tarball successfully uploaded to %s (name=%s)' %
                    (self.company_name, tarball_name))
                LOG.info(
                    'When communicating with support, please let them know the '
                    'tarball name - %s' % tarball_name)
        finally:
            # Remove temp files
            for temp_file in temp_files:
                assert temp_file.startswith('/tmp')
                remove_file(file_path=temp_file)
Ejemplo n.º 5
0
    def run(self, encrypt=False, upload=False, existing_file=None):
        """
        Run the specified steps.

        :param encrypt: If true, encrypt the archive file.
        :param encrypt: ``bool``
        :param upload: If true, upload the resulting file.
        :param upload: ``bool``
        :param existing_file: Path to an existing archive file. If not specified a new
        archive will be created.
        :param existing_file: ``str``
        """
        temp_files = []

        try:
            if existing_file:
                working_file = existing_file
            else:
                # Create a new archive if an existing file hasn't been provided
                working_file = self.create_archive()
                if not encrypt and not upload:
                    LOG.info('Debug tarball successfully '
                             'generated and can be reviewed at: %s' % working_file)
                else:
                    temp_files.append(working_file)

            if encrypt:
                working_file = self.encrypt_archive(archive_file_path=working_file)
                if not upload:
                    LOG.info('Encrypted debug tarball successfully generated at: %s' %
                             working_file)
                else:
                    temp_files.append(working_file)

            if upload:
                self.upload_archive(archive_file_path=working_file)
                tarball_name = os.path.basename(working_file)
                LOG.info('Debug tarball successfully uploaded to %s (name=%s)' %
                         (self.company_name, tarball_name))
                LOG.info('When communicating with support, please let them know the '
                         'tarball name - %s' % tarball_name)
        finally:
            # Remove temp files
            for temp_file in temp_files:
                assert temp_file.startswith('/tmp')
                remove_file(file_path=temp_file)
Ejemplo n.º 6
0
def create_and_upload_archive(include_logs, include_configs, include_content,
                              include_system_info, include_shell_commands=False,
                              user_info=None, debug=False, config_yaml=None):
    if config_yaml:
        s3_bucket_url = get_config_details('s3_bucket', option_name='url')
        gpg_key_fingerprint = get_config_details('gpg', option_name='gpg_key_fingerprint')
        gpg_key = get_config_details('gpg', option_name='gpg_key')
        company_name = get_config_details('company_name', option_name='name')
    else:
        s3_bucket_url = S3_BUCKET_URL
        gpg_key_fingerprint = GPG_KEY_FINGERPRINT
        gpg_key = GPG_KEY
        company_name = COMPANY_NAME
    try:
        plain_text_output_path = create_archive(include_logs=include_logs,
                                                include_configs=include_configs,
                                                include_content=include_content,
                                                include_system_info=include_system_info,
                                                include_shell_commands=include_shell_commands,
                                                user_info=user_info,
                                                debug=debug,
                                                config_yaml=config_yaml)
        encrypted_output_path = encrypt_archive(archive_file_path=plain_text_output_path,
                                                key_fingerprint=gpg_key_fingerprint,
                                                key_gpg=gpg_key)
        upload_archive(archive_file_path=encrypted_output_path, bucket_url=s3_bucket_url)
    except Exception:
        LOG.exception('Failed to upload tarball to %s' % company_name, exc_info=True)
        plain_text_output_path = None
        encrypted_output_path = None
    else:
        tarball_name = os.path.basename(encrypted_output_path)
        LOG.info('Debug tarball successfully uploaded to %s (name=%s)' %
                 (company_name, tarball_name))
        LOG.info('When communicating with support, please let them know the tarball name - %s' %
                 tarball_name)

    finally:
        # Remove tarballs
        if plain_text_output_path:
            assert plain_text_output_path.startswith('/tmp')
            remove_file(file_path=plain_text_output_path)
        if encrypted_output_path:
            assert encrypted_output_path.startswith('/tmp')
            remove_file(file_path=encrypted_output_path)