
    Jh                         d dl Z d dlZd dlmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ  e j0                   ej2                  e            ZdedefdZdefdZy)    N)actions
exceptionslocksystemutil)_is_attached)AutoAttachInstance)AzureAutoAttachInstance)GCPAutoAttachInstance)cloud_instance_factory)LXDAutoAttachInstance)UAConfig)retry_auto_attachcfgcloudc                    	 t        j                  d      5  t        j                  | |       d d d        t
        j                  d       y # 1 sw Y   xY w# t        $ rk}t
        j                  |       t        j                          t
        j                  d       t        j                  t        j                         Y d }~y d }~ww xY w)Nzpro.daemon.attempt_auto_attach)lock_holderz%creating flag file to trigger retrieszSuccessful auto attach)r   	RetryLockr   auto_attach	ExceptionLOGerrorclear_lock_file_if_presentinfor   create_filer   FLAG_FILE_PATH)r   r   es      F/usr/lib/python3/dist-packages/uaclient/daemon/poll_for_pro_license.pyattempt_auto_attachr      s    ^^(HI 	,U+	, HH%&	, 	, 		!'')89,;;<s.   A AA AA 	C"A!CCc                    t        j                  | j                  d      rt        j	                  d       y t        |       j                  rt        j	                  d       y t        j                         st        j	                  d       y 	 t               t        fdt        t        t        fD              }|st        j	                  d       y j!                         st        j	                  d	       y 	 j#                  d
      }|rt%        |        y | j*                  st        j	                  d       y 	 	 t-        j,                         }j#                  d      }t-        j,                         }t        |       j                  rt        j	                  d       y |rt%        |        y ||z
  dk  r@t        j	                  d| j.                         t-        j0                  | j.                         # t        j                  $ r t        j	                  d       Y y w xY w# t        j&                  $ r t        j	                  d       Y y t        j(                  $ r Y Nw xY w# t        j&                  $ r t        j	                  d       Y y t        j(                  $ r# t-        j0                  | j.                         Y w xY w)Nzfeatures.disable_auto_attach)configpath_to_valuez,Configured to not auto attach, shutting downzAlready attached, shutting downzNot on LTS, shutting downzNot on cloud, shutting downc              3   6   K   | ]  }t        |        y w)N)
isinstance).0cloud_instancer   s     r   	<genexpr>z'poll_for_pro_license.<locals>.<genexpr>1   s        	5.)s   z.Not on supported cloud platform, shutting downz(Not on supported instance, shutting downF)wait_for_changezCancelling pollingz5Configured to not poll for pro license, shutting downT
   zdwait_for_change returned quickly and no pro license present. Waiting %d seconds before polling again)r   is_config_value_truer   r   r   r   is_attachedr   is_current_series_ltsr   r   CloudFactoryErroranyr   r
   r   should_poll_for_pro_licenseis_pro_license_presentr   CancelProLicensePollingDelayProLicensePollingpoll_for_pro_licensetimepolling_error_retry_delaysleep)r   is_supported_cloudpro_license_presentstartendr   s        @r   r3   r3      sk     ww&D 	?@C$$23''),-&(
   "#!
  AB,,.;<#::! ; 
 U+##HI
	IIKE"'">"> $ #? # ))+C C ,,:;"#C/U{RH11
 

38899 Q '' ./0 -- %&,,  	( 11 	HH)*00 	JJs445	sB   
G= ;H+  :I. =(H('H(+(I+I+*I+.(K1KK)loggingr4   uaclientr   r   r   r   r   (uaclient.api.u.pro.status.is_attached.v1r   uaclient.cloudsr	   uaclient.clouds.azurer
   uaclient.clouds.gcpr   uaclient.clouds.identityr   uaclient.clouds.lxdr   uaclient.configr   uaclient.daemonr   	getLoggerreplace_top_level_logger_name__name__r   r   r3        r   <module>rJ      sk      < < A . 9 5 ; 5 $ -g:::8DE
'X 
'.@ 
'Sh SrI   