def create_archive(self): """ Create an archive with debugging information. :return: Path to the generated archive. :rtype: ``str`` """ try: # 1. Create temporary directory with the final directory structure where we will move # files which will be processed and included in the tarball self._temp_dir_path = self.create_temp_directories() # Prepend temp_dir_path to OUTPUT_PATHS output_paths = {} for key, path in six.iteritems(OUTPUT_PATHS): output_paths[key] = os.path.join(self._temp_dir_path, path) # 2. Moves all the files to the temporary directory LOG.info('Collecting files...') if self.include_logs: self.collect_logs(output_paths['logs']) if self.include_configs: self.collect_config_files(output_paths['configs']) if self.include_content: self.collect_pack_content(output_paths['content']) if self.include_system_info: self.add_system_information(output_paths['system_info']) if self.user_info: self.add_user_info(output_paths['user_info']) if self.include_shell_commands: self.add_shell_command_output(output_paths['commands']) # 3. Create a tarball return self.create_tarball(self._temp_dir_path) except Exception as e: LOG.exception('Failed to generate tarball', exc_info=True) raise e finally: # Ensure temp files are removed regardless of success or failure assert self._temp_dir_path.startswith('/tmp') remove_dir(self._temp_dir_path)