a '¡Dg!ã@s$dZddlZddlZddlZddlmZddlmZmZddl m Z z ddl m Z m Z mZmZdZWneyzdZYn0gd ¢Zd#d d „Zd$d d „Zd%dd„Zd&dd„Zd'edœdd„Zdd„Zdd„Zeeefdœdd„Zeeefdœdd„ZeedœZeddœdd „Zddœd!d"„Z dS)(zCloud-init apport interfaceéN)ÚDict)ÚINSTALLER_APPORT_FILESÚ INSTALLER_APPORT_SENSITIVE_FILES)Úis_cloud_init_enabled)Ú attach_fileÚattach_file_if_existsÚattach_root_command_outputsÚroot_command_outputTF)%ZAliYunZAltCloudZAkamaiz Amazon - Ec2ZAzureZBigstepZ BrightboxZCloudCIXZ CloudSigmaZ CloudStackZ DigitalOceanZE24CloudzGCE - Google Compute Enginez Huawei CloudZExoscalez Hetzner CloudZNWCSz IBM - (aka SoftLayer or BlueMix)ZLXDZMAASZNoCloudZ OpenNebulaZ OpenStackZOracleZOVFz'RbxCloud - (HyperOne, Rootbox, Rubikon)ZOpenTelekomCloudzSAP Converged CloudZScalewayZSmartOSZUpCloudZVMwareZVultrZZStackZOutscaleZWSLZOthercCs<t|ddiƒgd¢}|s$| d¡t|ƒt|ddƒdS)zBAttach cloud-init logs and tarfile from 'cloud-init collect-logs'.zcloud-init-log-warningsz-egrep -i "warn|error" /var/log/cloud-init.log)z cloud-initz collect-logsz-tú/tmp/cloud-init-logs.tgzz--redactr zlogs.tgzN)rÚappendr r)ÚreportÚuiÚinclude_sensitiveZcommand©rú4/usr/lib/python3.9/site-packages/cloudinit/apport.pyÚattach_cloud_init_logsHsþþ rcCs$d}|r | |¡r t|ddiƒdS)z*Optionally attach hardware info from lshw.z¡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?zlshw.txtZlshwN)Úyesnor)r r ÚpromptrrrÚ attach_hwinfo^sÿrcCsTtD] }tj |j¡}t|||jƒq|rPtD] }tj |j¡}t|||jƒq.dS)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)rÚosÚpathÚrealpathrZlabelr)r r rZ apport_filerrrrÚattach_installer_filesisrcCsZtj d¡}t||ƒtj |¡rV| dd¡|drF|dd7<|dd7<dS)z|S) NZ meta_dataZimdsÚcomputeZImagePublisherZ ImageOfferZImageSKUZ ImageVersionZVMSize)Z publisherZofferZskuÚversionZvmSize©r"Úitems)Úds_datar*Zname_to_report_mapZ azure_dataZsrc_keyZreport_key_namerrrÚ_get_azure_data¿sûr/cs@| di¡ di¡ d¡}|s"iShd£‰‡fdd„| ¡DƒS)NZdynamiczinstance-identityÚdocument>ÚregionZimageIdZbillingProductsZ architectureZ instanceTypecsi|]\}}|ˆvr||“qSrr)Ú.0ÚkeyÚvalue©Z wanted_keysrrÚ Ýsz!_get_ec2_data..r,)r.r0rr5rÚ _get_ec2_dataÐsÿ ÿr7)ZazureZec2)ÚplatformrcCsJt |¡}|sdS||ƒ}| ¡D]"\}}|s0q"||| ¡| ¡<q"dS)z–Add datasoure specific information from the ds dictionary. ds_data contains the "ds" entry from data from /run/cloud/instance-data.json. N)ÚPLATFORM_SPECIFIC_INFOr"r-Ú capitalize)r r8r.Z platform_infoZretrieved_datar3r4rrrÚadd_datasource_specific_infoås r;cCsâzDtƒsWdStddƒ}t |¡}Wdƒn1s80YWn"tyft ¡ d¡YdS0| d¡}|s’t ¡ dt |  ¡ƒ¡dSddd d d d d œ  ¡D]\}}| |¡}|r¨|||<q¨t ||d| d¡ƒdS)zÆEntry point for Apport. This hook runs for every apport report Add a subset of non-sensitive cloud-init data from /run/cloud/instance-data.json that will be helpful for debugging. Nz"/run/cloud-init/instance-data.jsonÚrzKcloud-init run data not found on system. Unable to add cloud-specific data.Úv1z8instance-data.json lacks 'v1' metadata. Present keys: %sZCloudIDZ CloudNameZCloudArchitectureZ CloudPlatformZ CloudRegionZCloudSubPlatform)Zcloud_idZ cloud_nameÚmachiner8r1Z subplatformr8Zds) rÚopenÚjsonÚloadÚFileNotFoundErrorÚloggingZ getLoggerZwarningr"Úsortedr#r-r;)r Ú_ZfopenZ instance_datar=r3Z report_keyr4rrrÚgeneral_add_infoõs< , ÿ  þú  ÿrF)NF)N)NF)N)N)!Ú__doc__r@rCrÚtypingrZcloudinit.cmd.devel.logsrrZcloudinit.cmd.statusrZapport.hookutilsrrrr r'Ú ImportErrorZKNOWN_CLOUD_NAMESrrrrÚboolr!r&r)Ústrr/r7r9r;rFrrrrÚs0    )