
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me              	   @   s   U d Z ddl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eZ ejeZdddZdd Zee
eeddddZdS )z$Fan: Configure ubuntu fan networking    N)dedent)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.
ZubuntuZcc_fanZ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distrosZ	frequencyZexamplesZactivate_by_schema_keysz/etc/network/fan)configconfig_pathc             C   s   y| j d| d}W n6 tjk
rJ } zd}tjd|| W Y d d }~X nX |jds^|d7 }tj||dd y | j d| |rtjd	| W n2 tjk
r } ztjd
|| W Y d d }~X nX | j d| d S )NstopFTzfailed to stop %s: %s
w)omodestartzsuccess: %s startedzfailed to start %s: %senable)Zmanage_servicer   ZProcessExecutionErrorLOGZwarningendswithr   
write_file)distroserviceconfig_filecontentZstop_failede r    /usr/lib/python3.6/cc_fan.pystop_update_startC   s      
 r"   )r   cfgcloudargsreturnc             C   s   |j d}|si }tj|tg}|j ds:tjd|  d S tj|j d|j ddd |j}tj	dsr|j
dg t|d|j d|j dd	 d S )
Nr
   r   z$%s: no 'fan' config entry. disablingr   r   )r   Zfanctlz
ubuntu-fan)r   r   r   )getr   ZmergemanydictBUILTIN_CFGr   debugr   r   r   ZwhichZinstall_packagesr"   )r   r#   r$   r%   ZcfginZmycfgr   r    r    r!   handleY   s     


r*   )__doc__Zloggingtextwrapr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr	   ZMODULE_DESCRIPTIONr   metaZ	getLogger__name__r   r(   r"   strlistr*   r    r    r    r!   <module>   s0   

