o
    x[hÍ  ã                
   @   s¦   U d Z ddlZddl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	ged
gdœZe
ed< e e¡ZdddœZdd„ Zdededededdf
dd„ZdS )z$Fan: Configure ubuntu fan networkingé    N)ÚsubpÚutil)ÚCloud)ÚConfig)Ú
MetaSchema)ÚPER_INSTANCEÚcc_fanÚubuntuÚfan)ÚidÚdistrosÚ	frequencyÚactivate_by_schema_keysÚmetaz/etc/network/fan)ÚconfigÚconfig_pathc              
   C   sÖ   z
|   d|¡ d}W n tjy& } zd}t d||¡ W Y d }~nd }~ww | d¡s0|d7 }tj||dd� z|   d|¡ |rGt d	|¡ W n tjyb } zt d
||¡ W Y d }~nd }~ww |   d|¡ d S )NÚstopFTzfailed to stop %s: %sÚ
Úw©ÚomodeÚstartzsuccess: %s startedzfailed to start %s: %sÚenable)Úmanage_servicer   ÚProcessExecutionErrorÚLOGÚwarningÚendswithr   Ú
write_file)ÚdistroÚserviceÚconfig_fileÚcontentÚstop_failedÚe© r%   ú9/usr/lib/python3/dist-packages/cloudinit/config/cc_fan.pyÚstop_update_start   s*   €þ
€€ÿr'   ÚnameÚcfgÚcloudÚargsÚreturnc                 C   s’   |  d¡}|s	i }t |tg¡}|  d¡st d| ¡ d S tj|  d¡|  d¡dd� |j}t 	d¡s9| 
dg¡ t|d|  d¡|  d¡d	� d S )
Nr
   r   z$%s: no 'fan' config entry. disablingr   r   r   Úfanctlz
ubuntu-fan)r    r!   r"   )Úgetr   ÚmergemanydictÚBUILTIN_CFGr   Údebugr   r   r   ÚwhichÚinstall_packagesr'   )r(   r)   r*   r+   ÚcfginÚmycfgr   r%   r%   r&   Úhandle5   s"   



ür6   )Ú__doc__ÚloggingÚ	cloudinitr   r   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   Úcloudinit.settingsr   r   Ú__annotations__Ú	getLoggerÚ__name__r   r0   r'   ÚstrÚlistr6   r%   r%   r%   r&   Ú<module>   s$   ü
þ"