U
    bm  ã                   @   sJ   d dl mZmZmZmZ d dlmZ d dlmZ dZ	G dd„ dej
ƒZ
dS )é    )ÚdistrosÚhelpersÚsubpÚutil)ÚHostnameConf)ÚPER_INSTANCEa7  # This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}

c                   @   s¤   e Zd ZdgZdZdZdeedœiZdd„ Zdd	„ Z	d%dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zd&dd„Zdd„ Zdd„ Zd'dd„Zdd„ Zedd „ ƒZd(d#d$„Zd
S ))ÚDistroz
rc-servicez/etc/profile.d/locale.shz/etc/network/interfacesZeni)Zeni_pathZ
eni_headerc                 C   s6   t j | |||¡ t |¡| _d| _d| _d|d< d S )NzC.UTF-8ZalpineZsshdZssh_svcname)r   r   Ú__init__r   ZRunnersÚ_runnerÚdefault_localeZosfamily)ÚselfÚnameZcfgÚpaths© r   ú:/usr/lib/python3/dist-packages/cloudinit/distros/alpine.pyr	      s
    zDistro.__init__c                 C   s   | j S )zgThe default locale for Alpine Linux is different than
        cloud-init's DataSource default.
        )r   ©r   r   r   r   Ú
get_locale)   s    zDistro.get_localeNc                 C   sB   |s
| j }|s| j}ddddd| ddg}t |d |¡d¡ d S )	Nú#z?# This file is created by cloud-init once per new instance bootzexport CHARSET=UTF-8zexport LANG=%szexport LC_COLLATE=CÚ Ú
é¤  )r   Úlocale_conf_fnr   Ú
write_fileÚjoin)r   ZlocaleZout_fnÚlinesr   r   r   Úapply_locale/   s    ù	zDistro.apply_localec                 C   s   |   ¡  | jd|d� d S )NÚadd)Úpkgs)Úupdate_package_sourcesÚpackage_command)r   Úpkglistr   r   r   Úinstall_packagesB   s    zDistro.install_packagesc                 C   sT   d }z|   |¡}W n tk
r&   Y nX |s4tdƒ}| |¡ t |t|ƒd¡ d S )Nr   r   )Ú_read_hostname_confÚIOErrorr   Zset_hostnamer   r   Ústr)r   ÚhostnameÚfilenameÚconfr   r   r   Ú_write_hostnameF   s    
zDistro._write_hostnamec                 C   s   |   | j¡}| j|fS ©N)Ú_read_hostnameZhostname_conf_fn)r   Zsys_hostnamer   r   r   Ú_read_system_hostnameS   s    zDistro._read_system_hostnamec                 C   s   t t |¡ƒ}| ¡  |S r)   )r   r   Z	load_fileÚparse)r   r&   r'   r   r   r   r"   W   s    zDistro._read_hostname_confc                 C   s:   d }z|   |¡}|j}W n tk
r,   Y nX |s6|S |S r)   )r"   r%   r#   )r   r&   Údefaultr%   r'   r   r   r   r*   \   s    

zDistro._read_hostnamec                 C   s   dS )Nz	127.0.1.1r   r   r   r   r   Ú_get_localhost_ipg   s    zDistro._get_localhost_ipc                 C   s   t j||  |¡d� d S )N)ÚtzZtz_file)r   Zset_etc_timezoneZ_find_tz_file)r   r/   r   r   r   Úset_timezonej   s    zDistro.set_timezonec                 C   sš   |d krg }dg}|  d¡ |r6t|tƒr6|  |¡ n|rNt|tƒrN| |¡ |r\|  |¡ |dkrr| ddg¡ t d|¡}| |¡ tj|dd� d S )	NZapkz--quietZupgradez--update-cachez--availablez%s-%sF)Zcapture)ÚappendÚ
isinstancer$   ÚlistÚextendr   Zexpand_package_listr   )r   ÚcommandÚargsr   Úcmdr    r   r   r   r   m   s    



zDistro.package_commandc                 C   s   | j jd| jdgtd� d S )Nzupdate-sourcesÚupdate)Zfreq)r
   Úrunr   r   r   r   r   r   r   †   s    üzDistro.update_package_sourcesc                 C   s   | j sddg| _ | j S )z7Allow distro to determine the preferred ntp client listZchronyZntp)Z_preferred_ntp_clientsr   r   r   r   Úpreferred_ntp_clientsŽ   s    
zDistro.preferred_ntp_clientsÚpoweroffÚnowc              
   C   sn   |dg}|dkr|dg7 }nNz|  tt|ƒd ƒ¡ W n2 tk
rh } ztd|f ƒ|‚W 5 d }~X Y nX |S )Nz-dr<   Ú0é<   z?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.)r1   r$   ÚintÚ
ValueErrorÚ	TypeError)r   ÚmodeZdelayÚmessager5   Úer   r   r   Úshutdown_command–   s    ÿÿýzDistro.shutdown_command)N)N)NN)r;   r<   N)Ú__name__Ú
__module__Ú__qualname__Zinit_cmdr   Znetwork_conf_fnÚNETWORK_FILE_HEADERZrenderer_configsr	   r   r   r!   r(   r+   r"   r*   r.   r0   r   r   Úpropertyr:   rE   r   r   r   r   r      s*    ÿ




r   N)Z	cloudinitr   r   r   r   Z"cloudinit.distros.parsers.hostnamer   Zcloudinit.settingsr   rI   r   r   r   r   r   Ú<module>	   s   
