3 \me8+@sdZddlZddlZddlmZddlmZmZy ddlm Z m Z m Z m Z dZ Wnek rhdZ YnXdd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*g#Zd+Zd,Zed-d.d/Zd@d0d1ZdAd2d3ZdBd4d5ZdCd6d7ZdDd8d9ZdEd:d;Zdd?ZdS)FzCloud-init apport interfaceN)read_cfg_paths)INSTALLER_APPORT_FILES INSTALLER_APPORT_SENSITIVE_FILES) attach_fileattach_file_if_existsattach_root_command_outputsroot_command_outputTFZAliYunZAltCloudZAkamaiz Amazon - Ec2ZAzureZBigstepZ BrightboxZ CloudSigmaZ CloudStackZ DigitalOceanZE24CloudzGCE - Google Compute Enginez Huawei CloudZExoscalez Hetzner CloudZNWCSz IBM - (aka SoftLayer or BlueMix)ZLXDZMAASZNoCloudZ OpenNebulaZ OpenStackZOracleZOVFz'RbxCloud - (HyperOne, Rootbox, Rubikon)ZOpenTelekomCloudzSAP Converged CloudZScalewayZSmartOSZUpCloudZVMwareZVultrZZStackZOutscaleZOtherz/var/log/cloud-init.logz/var/log/cloud-init-output.log)returncCst}|jdS)NZ userdata_raw)rZ get_ipath_cur)pathsr /usr/lib/python3.6/apport.py_get_user_data_fileHsr cCs0t|dddtddddgt|ddd S) zBAttach cloud-init logs and tarfile from 'cloud-init collect-logs'.z-egrep -i "warn|error" /var/log/cloud-init.logz"cat /var/log/cloud-init-output.log)zcloud-init-log-warningszcloud-init-output.log.txtz cloud-initz collect-logsz-tz/tmp/cloud-init-logs.tgzzlogs.tgzN)rrr)reportuir r r attach_cloud_init_logsMs rcCs$d}|r |j|r t|ddidS)z*Optionally attach hardware info from lshw.zYour 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?zlshw.txtZlshwN)yesnor)rrpromptr r r attach_hwinfo^srcCs|rt}y(t|jd}tj|}dSQRXWnttjjtfk rPYnXd}|j |}|dkrlt |rd}|j |t }|rt |d|d<nd|d<dS)aPrompt for cloud details if instance-data unavailable. When we have valid _get_instance_data, apport/generic-hooks/cloud_init.py provides CloudName, CloudID, CloudPlatform and CloudSubPlatform. Apport/generic-hooks are delivered by cloud-init's downstream branches ubuntu/(devel|kinetic|jammy|focal|bionic) so they will not be represented in upstream main. In absence of viable instance-data.json format, prompt for the cloud below. instance_dataNz/Is this machine running in a cloud environment?zOPlease select the cloud vendor or environment in which this instance is runningrZ CloudNameNone) ropenZ get_runpathjsonloadIOErrordecoderZJSONDecodeErrorAssertionErrorr StopIterationZchoiceKNOWN_CLOUD_NAMES)rrr filerrresponser r r attach_cloud_infois$    r cCs.x(tD] }tjj|j}t|||jqWdS)a 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. N)rospathrealpathrlabel)rr apport_filer#r r r attach_installer_filess r&cCsZtjjd}t||tjj|rV|jdd|drF|dd7<|dd7<dS)zsn    (