fk(2dZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z  ddl mZmZmZmZdZgd Zd Zd Zd efdZddZddZddZddZddZddZdZdZ d eeeffdZ!d eeeffdZ"e!e"dZ#ded dfdZ$ddZ%y#e$rd ZY]wxYw)zCloud-init apport interfaceN)Dict)read_cfg_paths)INSTALLER_APPORT_FILES INSTALLER_APPORT_SENSITIVE_FILES)is_cloud_init_enabled) attach_fileattach_file_if_existsattach_root_command_outputsroot_command_outputTF)$AliYunAltCloudAkamaiz Amazon - Ec2AzureBigstep Brightbox CloudSigma CloudStack DigitalOceanE24CloudzGCE - Google Compute Enginez Huawei CloudExoscalez Hetzner CloudNWCSz IBM - (aka SoftLayer or BlueMix)LXDMAASNoCloud OpenNebula OpenStackOracleOVFz'RbxCloud - (HyperOne, Rootbox, Rubikon)OpenTelekomCloudzSAP Converged CloudScalewaySmartOSUpCloudVMwareVultrZStackOutscaleWSLOtherz/var/log/cloud-init.logz/var/log/cloud-init-output.logreturnc8t}|jdS)N userdata_raw)r get_ipath_cur)pathss 2/usr/lib/python3/dist-packages/cloudinit/apport.py_get_user_data_filer/Ls  E   ~ ..cVt|dddtgdt|ddy)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.txt)z cloud-initz collect-logsz-t/tmp/cloud-init-logs.tgzr2zlogs.tgzN)r r rreportuis r.attach_cloud_init_logsr6Qs:@)M  H*Jr0cNd}|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 )r4r5prompts r. attach_hwinfor;ds2 0  bhhv#FZ,@Arr0c|rjt} t|jd5}tj|}|j dij dsJ dddyyyy#1swYnxYwn.#t tjjtf$rYnwxYwd}|j|}|t|s[d}|j|t}|rt|d|d<yd |d<) 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_datav1 cloud_nameNz/Is this machine running in a cloud environment?zOPlease select the cloud vendor or environment in which this instance is runningr CloudNameNone)ropen get_runpathjsonloadgetIOErrordecoderJSONDecodeErrorAssertionErrorr9 StopIterationchoiceKNOWN_CLOUD_NAMES)r4r5r-filer=r:responses r.attach_cloud_inforPos    e''89 T $ $ $((r266|DDD       55~F   C88F#    , yy):;H&7 &D{#&,{#s(A;:A."A;.A73A;;(B&%B&ctD]B}tjj|j}t |||j Dy)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)rospathrealpathr label)r4r5 apport_filerTs r.attach_installer_filesrWsA.C 77##K$4$45fh 0A0ABCr0ctjjd}t||tjj |r2|j dd|dr |dxxdz cc<|dxxdz cc<yy)z 6Nc !Nv,&  r0cf|rt}dj|}|j|}|t|rxtj j |}t||dtD]B}tj j |j }t|||jDyyy)z(Optionally provide user-data if desired.zYour user-data, cloud-config or autoinstall files can optionally be provided from {0} and could be useful to developers when addressing this bug. Do you wish to attach user-data to this bug?Nz user_data.txt) r/formatr9rKrRrSrTrrr rU)r4r5user_data_filer:rOrTrVs r.attach_user_datarbs ,. F>*  88F#    ww''7H / :?  77++K,<,<=%Hk&7&7   r0cg}|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-installerrYrZr[N)rFappendkeysr]join)r4new_tagserrorss r. add_bug_tagsrosH zz- ! zz.! $&++-'( $ . OO. / zz(23&"% &> 6Nc !Nv#((8,, r0cts tdt||t||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 RuntimeErrorr6r;rPrbrWr^ror3s r.add_inforss`  I  62&&"fb!VR 62&62& r0c|jdijdijd}|siSdddddd }i}|jD] \}}||||<|S) N meta_dataimdscomputeImagePublisher ImageOfferImageSKU ImageVersionVMSize) publisherofferskuversionvmSizerFitems)ds_datarwname_to_report_map azure_datasrc_keyreport_key_names r._get_azure_datarskk+r*..vr:>>yIG  %! J$6$<$<$>7 &-g&6 ?#7 r0c|jdijdijd}|siShd}|jDcic] \}}||vs ||c}}Scc}}w)Ndynamiczinstance-identitydocument>regionimageId architecture instanceTypebillingProductsr)rr wanted_keyskeyvalues r. _get_ec2_datarst 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_INFOrFr capitalize)r4rr platform_inforetrieved_datarrs r.add_datasource_specific_inforsg +..x8M "7+N$**,A U ;@x""$s~~'778Ar0c8 tsytdd5}tj|}dddjd}|sz8instance-data.json lacks 'v1' metadata. Present keys: %sCloudIDr@CloudArchitecture CloudPlatform CloudRegionCloudSubPlatform)cloud_idr?machinerr subplatformrds) rrBrDrEFileNotFoundErrorlogging getLoggerwarningrFsortedrkrr)r4_fopenr=r>r report_keyrs r.general_add_infor%s" $&  6 < - IIe,M -   4 B ## F =%%' (  !&#)  eg 'Zs  !&F:  '!: 1 1$ 7; - - ## 1   s, C* C*CC*C'#C**,DD)N)r)N)&__doc__rDrrRtypingrcloudinit.cmd.develrcloudinit.cmd.devel.logsrrcloudinit.cmd.statusrapport.hookutilsrr r r rq ImportErrorrM CLOUDINIT_LOGCLOUDINIT_OUTPUT_LOGstrr/r6r;rPrWr^rbrorsrrrrrr0r.rs "  .7 J %P* 7/S/ &B%-P C'.-(*S#X"d38n$$3=I A3 AD A *SJsB BB