U
    ¯Adù  ã                "   @   s  d Z ddlZddlmZ ddlmZmZ z ddlmZm	Z	m
Z
mZ dZW n ek
r`   dZY nX dd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)g"Zd*Zd+Zed,œd-d.„Zd=d/d0„Zd>d1d2„Zd?d3d4„Zd@d5d6„ZdAd7d8„Zd9d:„ Zd;d<„ ZdS )BzCloud-init apport interfaceé    N)Úread_cfg_paths)ÚINSTALLER_APPORT_FILESÚ INSTALLER_APPORT_SENSITIVE_FILES)Úattach_fileÚattach_file_if_existsÚattach_root_command_outputsÚroot_command_outputTFZAliYunZAltCloudzAmazon - Ec2ZAzureZBigstepZ	BrightboxZ
CloudSigmaZ
CloudStackZDigitalOceanZE24CloudzGCE - Google Compute EnginezHuawei CloudZExoscalezHetzner CloudZNWCSz IBM - (aka SoftLayer or BlueMix)ZLXDZMAASZNoCloudZ
OpenNebulaZ	OpenStackZOracleZOVFz'RbxCloud - (HyperOne, Rootbox, Rubikon)ZOpenTelekomCloudzSAP Converged CloudZScalewayZSmartOSZUpCloudZVMwareZVultrZZStackZOutscaleZOtherz/var/log/cloud-init.logz/var/log/cloud-init-output.log)Úreturnc                  C   s   t ƒ } |  d¡S )NZuserdata_raw)r   Zget_ipath_cur)Úpaths© r   ú2/usr/lib/python3/dist-packages/cloudinit/apport.pyÚ_get_user_data_fileF   s    r   c                 C   s0   t | dddœƒ tddddgƒ t| ddƒ d	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)zcloud-init-log-warningszcloud-init-output.log.txtz
cloud-initzcollect-logsz-tz/tmp/cloud-init-logs.tgzzlogs.tgzN)r   r   r   ©ÚreportÚuir   r   r   Úattach_cloud_init_logsK   s    üþ	
ÿr   c                 C   s$   d}|r |  |¡r t| ddiƒ dS )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?zlshw.txtZlshwN)Úyesnor   )r   r   Úpromptr   r   r   Úattach_hwinfo\   s    ÿr   c                 C   sT   |rPd}|  |¡}|dkrt‚|rPd}| |t¡}|rHt|d  | d< nd| d< dS )z&Prompt for cloud details if available.z/Is this machine running in a cloud environment?NzOPlease select the cloud vendor or environment in which this instance is runningr   Z	CloudNameÚNone)r   ÚStopIterationZchoiceÚKNOWN_CLOUD_NAMES)r   r   r   Úresponser   r   r   Úattach_cloud_infog   s    
ÿr   c                 C   s*   t D ] }tj |j¡}t| ||jƒ qdS )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Úrealpathr   Úlabel)r   r   Úapport_filer   r   r   r   Úattach_installer_filesz   s    r   c                 C   sp   |rlt ƒ }d |¡}| |¡}|dkr*t‚|rltj |¡}t| |dƒ tD ] }tj |j¡}t	| ||j
ƒ qJdS )z(Optionally provide user-data if desired.z¿Your 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   Úformatr   r   r   r   r   r   r   r   r   )r   r   Zuser_data_filer   r   r   r   r   r   r   Úattach_user_data‡   s    ýÿ
r!   c                 C   s¨   g }|   d¡r| d¡ |   d¡r,| d¡ d|  ¡ krR| d }d|krR| d¡ |   d¡rf| d	¡ |r¤|  d
d¡ | d
 rŽ| d
  d7  < | d
  d |¡7  < dS )z$Add any appropriate tags to the bug.ZCurtinErrorZcurtinZSubiquityLogZ	subiquityZJournalErrorszBreaking ordering cyclezsystemd-orderingZUdiLogzubuntu-desktop-installerZTagsÚ ú N)ÚgetÚappendÚkeysÚ
setdefaultÚjoin)r   Znew_tagsÚerrorsr   r   r   Úadd_bug_tagsœ   s     






r*   c                 C   sJ   t stdƒ‚t| |ƒ t| |ƒ t| |ƒ t| |ƒ t| |ƒ t| ƒ dS )a-  This is an entry point to run cloud-init's apport functionality.

    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ÚRuntimeErrorr   r   r   r!   r   r*   r   r   r   r   Úadd_info°   s    ÿ




r-   )N)N)N)N)N)Ú__doc__r   Zcloudinit.cmd.develr   Zcloudinit.cmd.devel.logsr   r   Zapport.hookutilsr   r   r   r   r+   ÚImportErrorr   ZCLOUDINIT_LOGZCLOUDINIT_OUTPUT_LOGÚstrr   r   r   r   r   r!   r*   r-   r   r   r   r   Ú<module>   sj   
Þ&




