OwlCyberSecurity - MANAGER
Edit File: poll_for_pro_license.cpython-38.pyc
U ��g� � @ s� d dl Z d dlZd dlmZmZmZmZmZ d dlm Z d dl mZ d dlm Z d dlmZ d dlmZ d dlmZ d d lmZ d d lmZ e �e�e��Zeed�dd �Zed�dd�ZdS )� N)�actions� exceptions�lock�system�util)�_is_attached)�AutoAttachInstance)�AzureAutoAttachInstance)�GCPAutoAttachInstance)�cloud_instance_factory)�LXDAutoAttachInstance)�UAConfig)�retry_auto_attach)�cfg�cloudc C s� z(t jdd�� t�| |� W 5 Q R X W nP tk rx } z2t�|� t �� t�d� t � tj� W Y �d S d }~X Y nX t�d� d S )Nzpro.daemon.attempt_auto_attach)Zlock_holderz%creating flag file to trigger retrieszSuccessful auto attach) r Z RetryLockr Zauto_attach� Exception�LOG�errorZclear_lock_file_if_present�infor Zcreate_filer ZFLAG_FILE_PATH)r r �e� r �F/usr/lib/python3/dist-packages/uaclient/daemon/poll_for_pro_license.py�attempt_auto_attach s r )r c s t j| jdd�rt�d� d S t| �jr6t�d� d S t�� sLt�d� d S z t � � W n" t jk rx t�d� Y d S X t� fdd�t ttfD ��}|s�t�d � d S � �� s�t�d � d S z� jdd�}W n8 t jk r� t�d � Y d S t jk �r Y nX |�rt| � � d S | j�s2t�d� d S z t�� }� jdd�}t�� }W nL t jk �rv t�d � Y d S t jk �r� t�| j� Y �q2Y n\X t| �j�r�t�d� d S |�r�t| � � d S || dk �r2t�d| j� t�| j� �q2�q2d S )Nzfeatures.disable_auto_attach)ZconfigZ path_to_valuez,Configured to not auto attach, shutting downzAlready attached, shutting downzNot on LTS, shutting downzNot on cloud, shutting downc 3 s | ]}t � |�V qd S )N)� isinstance)�.0Zcloud_instance�r r r � <genexpr>1 s �z'poll_for_pro_license.<locals>.<genexpr>z.Not on supported cloud platform, shutting downz(Not on supported instance, shutting downF)Zwait_for_changezCancelling 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 Zis_config_value_truer r r r Zis_attachedr Zis_current_series_ltsr r ZCloudFactoryError�anyr r r Zshould_poll_for_pro_licenseZis_pro_license_presentZCancelProLicensePollingZDelayProLicensePollingr �poll_for_pro_license�time�sleepZpolling_error_retry_delay)r Zis_supported_cloudZpro_license_present�start�endr r r r s� � �� � � �r )Zloggingr Zuaclientr r r r r Z(uaclient.api.u.pro.status.is_attached.v1r Zuaclient.cloudsr Zuaclient.clouds.azurer Zuaclient.clouds.gcpr Zuaclient.clouds.identityr Zuaclient.clouds.lxdr Zuaclient.configr Zuaclient.daemonr Z getLoggerZreplace_top_level_logger_name�__name__r r r r r r r �<module> s