x[h0!dZddlZddlZddlZddlmZddlmZmZddl m Z  ddl m Z m Z mZmZdZgd Zdd Zdd Zdd Zdd ZddefdZdZdZdeeeffdZdeeeffdZeedZdeddfdZddZ y#e$rdZYRwxYw)zCloud-init apport interfaceN)Dict)INSTALLER_APPORT_FILES INSTALLER_APPORT_SENSITIVE_FILES)is_cloud_init_enabled) attach_fileattach_file_if_existsattach_root_command_outputsroot_command_outputTF)&AliYunAltCloudAkamaiz Amazon - Ec2AzureBigstep BrightboxCloudCIX CloudSigma CloudStack DigitalOceanE24CloudzGCE - Google Compute Enginez Huawei CloudExoscalez Hetzner CloudNWCSz IBM - (aka SoftLayer or BlueMix)LXDMAASNoCloud OpenNebula OpenStackOracleOVFz'RbxCloud - (HyperOne, Rootbox, Rubikon)OpenTelekomCloudzSamsung Cloud PlatformzSAP Converged CloudScalewaySmartOSUpCloudVMwareVultrZStackOutscaleWSLOtherc~t|ddigd}|s|jdt|t|ddy)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)reportuiinclude_sensitivecommands 2/usr/lib/python3/dist-packages/cloudinit/apport.pyattach_cloud_init_logsr1IsE %? G z" 2J?cNd}|r!|j|rt|ddiyyy)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.txtlshwN)yesnor )r,r-prompts r0 attach_hwinfor7_s2 0  bhhv#FZ,@Arr2c6tD]B}tjj|j}t |||j D|rLt D]B}tjj|j}t |||j Dyy)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)rospathrealpathrlabelr)r,r-r. apport_filer;s r0attach_installer_filesr>js.C 77##K$4$45fh 0A0ABC; GKww'' (8(89H !&(K4E4E F Gr2ctjjd}t||tjj |r2|j dd|dr |dxxdz cc<|dxxdz cc<yy)z 6Nc !Nv,&  r2returncB|syd}|j|}|t|S)z(Optionally provide user-data if desired.FaQYour 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 this info?)r5 StopIteration)r,r-r6responses r0can_attach_sensitiverJs3  / xxH Or2cg}|jdr|jd|jdr|jdd|jvr|d}d|vr|jd|jdr|jd |rA|jd d |d r |d xxd z cc<|d xxd j |z cc<y y )z$Add any appropriate tags to the bug. CurtinErrorcurtin SubiquityLog subiquity JournalErrorszBreaking ordering cyclezsystemd-orderingUdiLogzubuntu-desktop-installerr@rArBN)getr+keysrDjoin)r,new_tagserrorss r0 add_bug_tagsrWsH zz- ! zz.! $&++-'( $ . OO. / zz(23&"% &> 6Nc !Nv#((8,, r2cts tdt||}t|||t ||t |||t ||t|y)a-This is an entry point to run cloud-init's package-specific hook Distros which want apport support will have a cloud-init package-hook at /usr/share/apport/package-hooks/cloud-init.py which defines an add_info function and returns the result of cloudinit.apport.add_info(report, ui). z;No apport imports discovered. Apport functionality disabledT) has_apport RuntimeErrorrJr1r7r>rErW)r,r-r.s r0add_infor[s_  I  -VR862'89&"62'8962& r2c|jdijdijd}|siSdddddd }i}|jD] \}}||||<|S) N meta_dataimdscomputeImagePublisher ImageOfferImageSKU ImageVersionVMSize) publisherofferskuversionvmSizerRitems)ds_datar_name_to_report_map azure_datasrc_keyreport_key_names r0_get_azure_datarqskk+r*..vr:>>yIG  %! J$6$<$<$>7 &-g&6 ?#7 r2c|jdijdijd}|siShd}|jDcic] \}}||vs ||c}}Scc}}w)Ndynamiczinstance-identitydocument>regionimageId architecture instanceTypebillingProductsrj)rlrt wanted_keyskeyvalues r0 _get_ec2_datar}st Ir"&&':B?CCJO   K&.^^%5 !sE 9KU   s A#A#)azureec2platformctj|}|sy||}|jD],\}}|s |||j|jz<.y)zAdd datasoure specific information from the ds dictionary. ds_data contains the "ds" entry from data from /run/cloud/instance-data.json. N)PLATFORM_SPECIFIC_INFOrRrk capitalize)r,rrl platform_inforetrieved_datar{r|s r0add_datasource_specific_inforsg +..x8M "7+N$**,A U ;@x""$s~~'778Ar2c8 tsytdd5}tj|}dddjd}|srEboolrJrWr[strrqr}rrrr2r0rs "  7 J 'T@,BG"'T$-((S#X"d38n$$3=I A3 AD A *wJsA;;BB