o
    w7eB                  
   @   s   U d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ d	Zd
gZdddeeeedgdgdZeed< eeZ 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    )dedent)log)subputil)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEa  This module installs, configures and starts the ubuntu fan network system. For
more information about Ubuntu Fan, see:
``https://wiki.ubuntu.com/FanNetworking``.

If cloud-init sees a ``fan`` entry in cloud-config it will:

    - write ``config_path`` with the contents of the ``config`` key
    - install the package ``ubuntu-fan`` if it is not installed
    - ensure the service is started (or restarted if was previously running)

Additionally, the ``ubuntu-fan`` package will be automatically installed
if not present.
ubuntucc_fanFanzConfigure ubuntu fan networkinga              fan:
              config: |
                # fan 240
                10.0.0.0/8 eth0/16 dhcp
                10.0.0.0/8 eth1/16 dhcp off
                # fan 241
                241.0.0.0/8 eth0/16 dhcp
              config_path: /etc/network/fan
            fan)idnametitledescriptiondistros	frequencyexamplesactivate_by_schema_keysmetaNz/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_startC   s*   
r/   r   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   r0   r1   r2   cfginmycfgr'   r-   r-   r.   handleY   s"   



r=   )__doc__textwrapr   	cloudinitr   loggingr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.settingsr
   MODULE_DESCRIPTIONr   r   __annotations__	getLogger__name__r#   r7   r/   strlistr=   r-   r-   r-   r.   <module>   s:   
"