+
    g                         ^ RI t ^ RIt^ RIHtHt ^ RIHtHtHtH	t	H
t
 ^ RIHt RtRt]]3tRtRtR	tR
tRtRtRtRt]R,           t]P2                  ! ]
P4                  ! ]4      4      t ! R R]4      tR# )    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                     a  ] tR t^t o RtRtV 3R lR lt]]P                  ! ]
P                  . ROR7      V 3R lR l4       4       t]P                  ! ]
P                  . ROR7      V 3R lR l4       t]V 3R	 lR
 l4       tR t]P                  ! ]
P                  . ROR7      R 4       t]V 3R lR l4       t]V 3R lR l4       tV 3R lR ltV 3R lR ltRtV tR# )AWSAutoAttachInstanceNc                    < V ^8  d   QhRS[ /# )   urlstr)format__classdict__s   "5/usr/lib/python3/dist-packages/uaclient/clouds/aws.py__annotate__"AWSAutoAttachInstance.__annotate__   s      #     c                    \         P                  ! W^R7      pVP                  ^8X  d   VP                  # \        P
                  ! VP                  VP                  R7      h)   )headerstimeoutcodebody)r   readurlr   r   r   CloudMetadataError)selfr   r   responses   &&& r   _get_imds_url_response,AWSAutoAttachInstance._get_imds_url_response   sH    <<a@==C== //]] r   )retry_sleepsc                6   < V ^8  d   QhRS[ S[S[3,          /# r   return)r   r   r   )r   r   s   "r   r   r   ,   s     , ,d38n ,r   c                    V P                  4       p\        P                  V P                  4      pV P	                  W!R 7      p\
        P                  P                  V4       RV/# )r   pkcs7)_request_imds_v2_token_headersIMDS_URLr   _ip_addressr$   r   secrets
add_secret)r"   r   r   imds_url_responses   &   r   identity_doc"AWSAutoAttachInstance.identity_doc*   s[     557ood../ 777M))*;<*++r   c                    < V ^8  d   QhRS[ /# r(   )r   )r   r   s   "r   r   r   4   s      T r   c                &   V P                  4       p\        P                  V P                  4      p \        P
                  ! V P                  W!R7      4      pV#   \        P                   d#   p\        P                  RT4       / u Rp?# Rp?ii ; i)z
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_doc!AWSAutoAttachInstance._get_ii_doc3   s     557""4#3#34	ZZ++C+AF  ## 	IIEqII	s   &A B.BBBc                    < V ^8  d   QhRS[ /# r(   bool)r   r   s   "r   r   r   J   s     I It Ir   c                    V P                  4       pVP                  RR4      pVP                  RR4      p\        V4      ;'       g    \        V4      # )z
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)r?   getrC   )r"   r=   billing_productsmarketplace_product_codess   &   r   is_likely_pro#AWSAutoAttachInstance.is_likely_proI   sP     !!#!::&7>$*JJ/H$$O!$%HH.G)HHr   c                8   \          F  p V P                  VR 7      pWn         M	  V P                  f+   \        P                  ! RP                  \         4      R7      hX#   \         d.   p\        P                  RT\        TRR4      4        Rp?K  Rp?ii ; i))
ip_addressz*Could not reach AWS IMDS at http://%s: %s
reason Nz, )	addresses)
IMDS_IP_ADDRESS_get_imds_v2_token_headersr/   	Exceptionr;   warninggetattrr   AWSNoValidIMDSjoin)r"   addressr   r>   s   &   r   r-   4AWSAutoAttachInstance._request_imds_v2_token_headersX   s    &G
99W9M $+  ' #++))O4    AAx, s   A!!B,"BBc                $   V P                   R 8X  d   R# V P                   '       d   \        V P                   /# \        P                  ! \        P                  V4      R\        \        /^R7      pVP                  ^8X  dM   VP                  V n         \        P                  P                  V P                   4       \        V P                   /# VP                  R8X  d
   R V n         R# \        P                  ! VP                  VP                  R7      h)IMDSv1NPUT)methodr   r   i  r   )
_api_tokenAWS_TOKEN_PUT_HEADERr   r    IMDS_V2_TOKEN_URLr   AWS_TOKEN_REQ_HEADERAWS_TOKEN_TTL_SECONDSr   r   r   r0   r1   r   r!   )r"   rM   r#   s   && r   rR   0AWSAutoAttachInstance._get_imds_v2_token_headersk   s    ??h&___($//::<<$$Z0)+@A	
 ==C&mmDO""--doo>($//::==C&DO++X]]
 	
r   c                    < V ^8  d   QhRS[ /# r(   r   )r   r   s   "r   r   r      s      C r   c                    R # )aws r"   s   &r   
cloud_type AWSAutoAttachInstance.cloud_type       r   c                    < V ^8  d   QhRS[ /# r(   rB   )r   r   s   "r   r   r      s      4 r   c                f    \         P                  ! \        4      pRVR,          8X  d   R#  \         P                  ! \        4      P                  4       p\         P                  ! \        4      P                  4       pRVR,          u;8X  d   VR,          8X  d    R#  R# R#   \         d     Li ; i)z$This machine is a viable AWSInstanceec2:r      NTF)r   	load_fileSYS_HYPERVISOR_PRODUCT_UUIDFileNotFoundErrorDMI_PRODUCT_UUIDlowerDMI_PRODUCT_SERIAL)r"   hypervisor_uuiddmi_uuid
dmi_serials   &   r   	is_viableAWSAutoAttachInstance.is_viable   s    	$../JKO,, - ##$45;;=%%&89??A
HSM4Z_4 5 ! 	 	s   (B" "B0/B0c                    < V ^8  d   QhRS[ /# r(   rB   )r   r   s   "r   r   r      s      T r   c                    R# )UnsupportedFrg   rh   s   &r   should_poll_for_pro_license1AWSAutoAttachInstance.should_poll_for_pro_license   rk   r   c                &   < V ^8  d   QhRS[ RS[ /# )r   wait_for_changer)   rB   )r   r   s   "r   r   r      s     ; ; ;$ ;r   c               ,    \         P                  ! 4       h)N)r   InPlaceUpgradeNotSupportedError)r"   r   s   &$r   is_pro_license_present,AWSAutoAttachInstance.is_pro_license_present   s    88::r   )r^   r/   )g      ?r   r   )r   r      )__name__
__module____qualname____firstlineno__r^   r/   r$   propertyr	   retryr   r!   r3   r?   rJ   r-   rR   ri   ry   r~   r   __static_attributes____classdictcell__)r   s   @r   r   r      s     JK  	ZZ
--KH, I , 
ZZ
--KH I* I I& 
ZZ
--IF
 G
0    " ; ;r   r   )r8   loggingtypingr   r   uaclientr   r   r   r   r	   uaclient.cloudsr
   IMDS_IPV4_ADDRESSIMDS_IPV6_ADDRESSrQ   r`   r.   r7   rq   ru   rs   rb   r_   ra   	getLoggerreplace_top_level_logger_namer   r;   r   rg   r   r   <module>r      s       C C 9% % $&780 =E4 7 3  1 +n< ::8DED;9 D;r   