
"·T`Q  ã            &   @   s  d  Z  y& d d l m Z m Z m Z d Z Wn e k
 rF d Z Yn Xd 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	 d% Z
 d& d' d( „ Z d& d) d* „ Z d& d+ d, „ Z d& d- d. „ Z d/ d0 „  Z d1 d2 „  Z d& S)3zCloud-init apport interfaceé    )Úattach_fileÚattach_root_command_outputsÚroot_command_outputTFZAliYunZAltCloudzAmazon - Ec2ZAzureZBigstepZ	BrightboxZ
CloudSigmaZ
CloudStackZDigitalOceanZE24CloudzGCE - Google Compute EngineZExoscalezHetzner Cloudz 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ZStackZOtherz/var/log/cloud-init.logz/var/log/cloud-init-output.logz%/var/lib/cloud/instance/user-data.txtNc             C   sC   t  |  d d d d i ƒ t d d d d g ƒ t |  d d	 ƒ d
 S)zBAttach cloud-init logs and tarfile from 'cloud-init collect-logs'.zcloud-init-log-warningsz-egrep -i "warn|error" /var/log/cloud-init.logzcloud-init-output.log.txtz"cat /var/log/cloud-init-output.logz
cloud-initzcollect-logsz-tz/tmp/cloud-init-logs.tgzzlogs.tgzN)r   r   r   )ÚreportÚui© r   ú2/usr/lib/python3/dist-packages/cloudinit/apport.pyÚattach_cloud_init_logs6   s    r	   c             C   s2   d } | r. | j  | ƒ 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_hwinfoA   s    r   c             C   st   | rp d } | j  | ƒ } | d k r- t ‚ | rp d } | j | t ƒ } | rf t | 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_infoK   s    r   c             C   sP   | rL d j  t ƒ } | j | ƒ } | d k r6 t ‚ | rL t |  t d ƒ d S)z(Optionally provide user-data if desired.z°Your user-data or cloud-config file 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)ÚformatÚUSER_DATA_FILEr
   r   r   )r   r   r   r   r   r   r   Úattach_user_data\   s    	r   c             C   s6   d |  j  ƒ  k r2 |  d } d | k r2 d |  d <d S)z$Add any appropriate tags to the bug.ZJournalErrorszBreaking ordering cyclezsystemd-orderingZTagsN)Úkeys)r   Úerrorsr   r   r   Úadd_bug_tagsk   s    
r   c             C   sT   t  s t d ƒ ‚ 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_infos   s    	
r   )Ú__doc__Zapport.hookutilsr   r   r   r   ÚImportErrorr   ZCLOUDINIT_LOGZCLOUDINIT_OUTPUT_LOGr   r	   r   r   r   r   r   r   r   r   r   Ú<module>   sX   
	
