Ë
    GKÕi­  ã                   óà   — d dl Z d dlZd dlmZmZ d dlmZmZmZm	Z	m
Z
 d dlmZ dZdZeefZdZdZd	Zd
ZdZdZdZdZedz   Z ej2                   e
j4                  e«      «      Z G d„ de«      Zy)é    N)ÚAnyÚDict)Ú
exceptionsÚhttpÚsecret_managerÚsystemÚutil)ÚPublicCloudAutoAttachInstancez169.254.169.254z[fd00:ec2::254]zhttp://{}/latest/api/tokenz0http://{}/latest/dynamic/instance-identity/pkcs7z3http://{}/latest/dynamic/instance-identity/documentz/sys/hypervisor/uuidz /sys/class/dmi/id/product_serialz/sys/class/dmi/id/product_uuidÚ21600zX-aws-ec2-metadata-tokenz-ttl-secondsc                   óˆ  — e Zd ZdZdZdefd„Ze ej                  e
j                  g d¢¬«      deeef   fd„«       «       Z ej                  e
j                  g d¢¬«      defd„«       Zedefd	„«       Zd
„ Z ej                  e
j                  g d¢¬«      d„ «       Zedefd„«       Zedefd„«       Zdefd„Zdedefd„Zy)ÚAWSAutoAttachInstanceNÚurlc                 ó¾   — t        j                  ||d¬«      }|j                  dk(  r|j                  S t	        j
                  |j                  |j                  ¬«      ‚)Né   )ÚheadersÚtimeoutéÈ   ©ÚcodeÚbody)r   Úreadurlr   r   r   ÚCloudMetadataError)Úselfr   r   Úresponses       ú5/usr/lib/python3/dist-packages/uaclient/clouds/aws.pyÚ_get_imds_url_responsez,AWSAutoAttachInstance._get_imds_url_response   sJ   € Ü—<‘< ¨W¸aÔ@ˆØ�=‰=˜CÒØ—=‘=Ð ä×/Ñ/Ø—]‘]¨¯©ôð ó    )g      à?r   r   )Úretry_sleepsÚreturnc                 óÌ   — | j                  «       }t        j                  | j                  «      }| j	                  ||¬«      }t
        j                  j                  |«       d|iS )N©r   Úpkcs7)Ú_request_imds_v2_token_headersÚIMDS_URLÚformatÚ_ip_addressr   r   ÚsecretsÚ
add_secret)r   r   r   Úimds_url_responses       r   Úidentity_docz"AWSAutoAttachInstance.identity_doc*   s]   € ð ×5Ñ5Ó7ˆÜ�o‰o˜d×.Ñ.Ó/ˆØ ×7Ñ7¸ÀWÐ7ÓMÐÜ×Ñ×)Ñ)Ð*;Ô<ØÐ*Ð+Ð+r   c                 ó"  — | j                  «       }t        j                  | j                  «      }	 t	        j
                  | j                  ||¬«      «      }|S # t        j                  $ r"}t        j                  d|«       i cY d}~S d}~ww xY w)a  
        Get the instance identity doc associated with the current instance.

        See
        https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/retrieve-iid.html
        for more context.

        @return: Dict containing the instance identity document.
        r!   z-Error decoding instance identity document: %sN)
r#   Ú_IMDS_IID_URLr%   r&   ÚjsonÚloadsr   ÚJSONDecodeErrorÚLOGÚdebug)r   r   r   Úii_docÚes        r   Ú_get_ii_docz!AWSAutoAttachInstance._get_ii_doc3   s�   € ð ×5Ñ5Ó7ˆÜ×"Ñ" 4×#3Ñ#3Ó4ˆð	Ü—Z‘ZØ×+Ñ+¨C¸Ð+ÓAóˆFð ˆøô ×#Ñ#ò 	Ü�I‰IÐEÀqÔIØ�Iûð	ús   ±&A ÁBÁ,B	ÂBÂ	Bc                 óš   — | j                  «       }|j                  dd«      }|j                  dd«      }t        |«      xs t        |«      S )a  
        Determines if the instance is likely Ubuntu Pro.

        Criteria: if any billing-product or marketplace-product-code is
        present, then is likely a Pro instance.

        @return: Boolean indicating if the instance is likely pro or not.
        ÚbillingProductsNÚmarketplaceProductCodes)r4   ÚgetÚbool)r   r2   Úbilling_productsÚmarketplace_product_codess       r   Úis_likely_proz#AWSAutoAttachInstance.is_likely_proI   sM   € ð ×!Ñ!Ó#ˆØ!Ÿ:™:Ð&7¸Ó>ÐØ$*§J¡JÐ/HÈ$Ó$OÐ!ÜÐ$Ó%ÒH¬Ð.GÓ)HÐHr   c                 ó,  — t         D ]  }	 | j                  |¬«      }|| _         n | j                  €)t        j                  dj                  t         «      ¬«      ‚S # t        $ r,}t        j                  d|t        |dd«      «       Y d }~Œ‡d }~ww xY w)N)Ú
ip_addressz*Could not reach AWS IMDS at http://%s: %s
ÚreasonÚ z, )Ú	addresses)
ÚIMDS_IP_ADDRESSÚ_get_imds_v2_token_headersr&   Ú	Exceptionr0   ÚwarningÚgetattrr   ÚAWSNoValidIMDSÚjoin)r   Úaddressr   r3   s       r   r#   z4AWSAutoAttachInstance._request_imds_v2_token_headersX   sŸ   € Ü&ò 	ˆGð
Ø×9Ñ9ÀWÐ9ÓM�ð $+�Ô Ùð	ð ×ÑÐ#Ü×+Ñ+ØŸ)™)¤OÓ4ôð ð ˆøô ò Ü—‘ØAØÜ˜A˜x¨Ó,÷ñ ûðús   ‹AÁ	BÁ'"BÂB)r   é   é   c                 ó  — | j                   dk(  ry | j                   rt        | j                   iS t        j                  t        j                  |«      dt        t        id¬«      }|j                  dk(  rL|j                  | _         t        j                  j                  | j                   «       t        | j                   iS |j                  dk(  rd| _         y t        j                  |j                  |j                  ¬«      ‚)NÚIMDSv1ÚPUTr   )Úmethodr   r   r   i”  r   )Ú
_api_tokenÚAWS_TOKEN_PUT_HEADERr   r   ÚIMDS_V2_TOKEN_URLr%   ÚAWS_TOKEN_REQ_HEADERÚAWS_TOKEN_TTL_SECONDSr   r   r   r'   r(   r   r   )r   r>   r   s      r   rC   z0AWSAutoAttachInstance._get_imds_v2_token_headersk   sÈ   € à�?‰?˜hÒ&ØØ�_Š_Ü(¨$¯/©/Ð:Ð:ä—<‘<Ü×$Ñ$ ZÓ0ØÜ)Ô+@ÐAØô	
ˆð �=‰=˜CÒØ&Ÿm™mˆDŒOÜ×"Ñ"×-Ñ-¨d¯o©oÔ>Ü(¨$¯/©/Ð:Ð:Ø�=‰=˜CÒØ&ˆDŒOØä×+Ñ+Ø—‘ X§]¡]ô
ð 	
r   c                  ó   — y)NÚaws© ©r   s    r   Ú
cloud_typez AWSAutoAttachInstance.cloud_type„   ó   € àr   c                 ó.  — 	 t        j                  t        «      }d|dd k(  ry	 t        j                  t        «      j                  «       }t        j                  t        «      j                  «       }d|dd cxk(  r|dd k(  ry yy# t        $ r Y Œnw xY w)z$This machine is a viable AWSInstanceÚec2r   é   TF)r   Ú	load_fileÚSYS_HYPERVISOR_PRODUCT_UUIDÚFileNotFoundErrorÚDMI_PRODUCT_UUIDÚlowerÚDMI_PRODUCT_SERIAL)r   Úhypervisor_uuidÚdmi_uuidÚ
dmi_serials       r   Ú	is_viablezAWSAutoAttachInstance.is_viableˆ   sŸ   € ð	Ü$×.Ñ.Ô/JÓKˆOØ˜¨¨!Ð,Ò,Øð -ô ×#Ñ#Ô$4Ó5×;Ñ;Ó=ˆÜ×%Ñ%Ô&8Ó9×?Ñ?ÓAˆ
Ø�H˜Q˜q�MÔ4 Z°°! _Ò4Øð 5áøô !ò 	ñ ð	ús   ‚!B Â	BÂBc                  ó   — y)ÚUnsupportedFrW   rX   s    r   Úshould_poll_for_pro_licensez1AWSAutoAttachInstance.should_poll_for_pro_licenseš   rZ   r   Úwait_for_changec                ó*   — t        j                  «       ‚)N)r   ÚInPlaceUpgradeNotSupportedError)r   rk   s     r   Úis_pro_license_presentz,AWSAutoAttachInstance.is_pro_license_presentž   s   € Ü×8Ñ8Ó:Ð:r   )Ú__name__Ú
__module__Ú__qualname__rP   r&   Ústrr   Úpropertyr	   Úretryr   r   r   r   r*   r4   r9   r<   r#   rC   rY   rg   rj   rn   rW   r   r   r   r      s&  „ Ø€JØ€Kð¨#ó ð Ø€T‡Z�Z�
×-Ñ-ºKÔHð,˜d 3¨ 8™nò ,ó Ió ð,ð €T‡Z�Z�
×-Ñ-ºKÔHð˜Tò ó Iðð* ðI˜tò Ió ðIòð& €T‡Z�Z�
×-Ñ-ºIÔFñ
ó Gð
ð0 ð˜Cò ó ðð ð˜4ò ó ðð"¨Tó ð;¸ð ;À$ô ;r   r   )r-   ÚloggingÚtypingr   r   Úuaclientr   r   r   r   r	   Úuaclient.cloudsr
   ÚIMDS_IPV4_ADDRESSÚIMDS_IPV6_ADDRESSrB   rR   r$   r,   r_   rc   ra   rT   rQ   rS   Ú	getLoggerÚreplace_top_level_logger_namero   r0   r   rW   r   r   ú<module>r}      s–   ðÛ Û ß ç CÕ CÝ 9à%Ð Ø%Ð à$Ð&7Ð8€Ø0Ð Ø=€ØE€à4Ð Ø7Ð Ø3Ð àÐ Ø1Ð Ø+¨nÑ<Ð à€g×ÑÐ:˜×:Ñ:¸8ÓDÓE€ôD;Ð9õ D;r   