4:28 ˆÉÈ ƒy§Ç¿Ê!# Copyright (C) 2017 Canonical Ltd. # # This file is part of cloud-init. See LICENSE file for license information. """Cloud-init apport interface""" import json import logging import os from typing import Dict from cloudinit.cmd.devel.logs import ( INSTALLER_APPORT_FILES, INSTALLER_APPORT_SENSITIVE_FILES, ) from cloudinit.cmd.status import is_cloud_init_enabled try: from apport.hookutils import ( attach_file, attach_file_if_exists, attach_root_command_outputs, root_command_output, ) has_apport = True except ImportError: has_apport = False KNOWN_CLOUD_NAMES = [ "AliYun", "AltCloud", "Akamai", "Amazon - Ec2", "Azure", "Bigstep", "Brightbox", "CloudCIX", "CloudSigma", "CloudStack", "DigitalOcean", "E24Cloud", "GCE - Google Compute Engine", "Huawei Cloud", "Exoscale", "Hetzner Cloud", "NWCS", "IBM - (aka SoftLayer or BlueMix)", "LXD", "MAAS", "NoCloud", "OpenNebula", "OpenStack", "Oracle", "OVF", "RbxCloud - (HyperOne, Rootbox, Rubikon)", "OpenTelekomCloud", "SAP Converged Cloud", "Scaleway", "SmartOS", "UpCloud", "VMware", "Vultr", "ZStack", "Outscale", "WSL", "Other", ] def attach_cloud_init_logs(report, ui=None, include_sensitive=False): """Attach cloud-init logs and tarfile from 'cloud-init collect-logs'.""" attach_root_command_outputs( # pyright: ignore report, { "cloud-init-log-warnings": ( 'egrep -i "warn|error" /var/log/cloud-init.log' ), }, ) command = [ "cloud-init", "collect-logs", "-t", "/tmp/cloud-init-logs.tgz", ] if not include_sensitive: command.append("--redact") root_command_output(command) attach_file(report, "/tmp/cloud-init-logs.tgz", "logs.tgz") def attach_hwinfo(report, ui=None): """Optionally attach hardware info from lshw.""" prompt = ( "Your device details (lshw) may be useful to developers when" " addressing this bug, but gathering it requires admin privileges." " Would you like to include this info?" ) if ui and ui.yesno(prompt): attach_root_command_outputs(report, {"lshw.txt": "lshw"}) def attach_installer_files(report, ui=None, include_sensitive=False): """Attach any subiquity installer logs config. To support decoupling apport integration from installer config/logs, we eventually want to either source this function or APPORT_FILES attribute from subiquity and/or ubuntu-desktop-installer package-hooks python modules. """ for apport_file in INSTALLER_APPORT_FILES: realpath = os.path.realpath(apport_file.path) attach_file_if_exists(report, realpath, apport_file.label) if include_sensitive: for apport_file in INSTALLER_APPORT_SENSITIVE_FILES: realpath = os.path.realpath(apport_file.path) attach_file_if_exists(report, realpath, apport_file.label) def attach_ubuntu_pro_info(report, ui=None): """Attach ubuntu pro logs and tag if keys present in user-data.""" realpath = os.path.realpath("/var/log/ubuntu-advantage.log") attach_file_if_exists(report, realpath) # pyright: ignore if os.path.exists(realpath): report.setdefault("Tags", "") if report["Tags"]: report["Tags"] += " " report["Tags"] += "ubuntu-pro" def can_attach_sensitive(report, ui=None) -> bool: """Optionally provide user-data if desired.""" if not ui: return False prompt = ( "Your user data, cloud-config, network config, or autoinstall " "files can optionally be provided and could be useful to " "developers when addressing this bug. However, this data should " "not be included if it contains any sensitive data such as " "passwords and secrets. Gathering it requires admin privileges. " "Would you like to include