
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼me‡!  ã               @   sd   d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 e jeƒZdZG dd„ dejƒZdS )é    N)Ú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ZdZdZdZdeedœiZdd„ Z	d	d
„ Z
d0dd„Zejdœdd„Zdd„ Zdd„ Zdd„ Zd1dd„Zdd„ Zeeeedœdd„Zdd„ Zd2d d!„Zd"d#„ Zed$d%„ ƒZd3d(d)„Zed*d+„ ƒZedd,œeeed-œd.d/„ƒZdS )4ÚDistrozpy3-pipz/usr/share/bkeymaps/z&/etc/profile.d/50-cloud-init-locale.shz/etc/network/interfacesZeni)Zeni_pathZ
eni_headerc             C   s6   t jj| |||ƒ tj|ƒ| _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.6/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j|dj|ƒ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Ú Ú
i¤  )r   Úlocale_conf_fnr   Ú
write_fileÚjoin)r   ZlocaleZout_fnÚlinesr   r   r   Úapply_locale5   s    zDistro.apply_locale)Úpkglistc             C   s   | j ƒ  | jd|d� d S )NÚadd)Úpkgs)Úupdate_package_sourcesÚpackage_command)r   r   r   r   r   Úinstall_packagesH   s    zDistro.install_packagesc             C   sn   d }y| j |ƒ}W n. tk
r@   tj| jddƒ}|r8nd S Y nX |sNtdƒ}|j|ƒ tj|t|ƒdƒ d S )NÚcreate_hostname_fileTr   i¤  )	Ú_read_hostname_confÚIOErrorr   Zget_cfg_option_boolZ_cfgr   Zset_hostnamer   Ústr)r   ÚhostnameÚfilenameÚconfr    r   r   r   Ú_write_hostnameL   s    

zDistro._write_hostnamec             C   s   | j | jƒ}| j|fS )N)Ú_read_hostnameZhostname_conf_fn)r   Zsys_hostnamer   r   r   Ú_read_system_hostname_   s    zDistro._read_system_hostnamec             C   s   t tj|ƒƒ}|jƒ  |S )N)r   r   Z	load_fileÚparse)r   r%   r&   r   r   r   r!   c   s    zDistro._read_hostname_confc             C   s:   d }y| j |ƒ}|j}W n tk
r,   Y nX |s6|S |S )N)r!   r$   r"   )r   r%   Údefaultr$   r&   r   r   r   r(   h   s    

zDistro._read_hostnamec             C   s   dS )Nz	127.0.1.1r   )r   r   r   r   Ú_get_localhost_ips   s    zDistro._get_localhost_ip)ÚlayoutÚmodelÚvariantÚoptionsc             C   sÒ   |sd}t j|ƒ t|ƒ‚tjj| j|ƒ}tjj|ƒsPd| }t j|ƒ t|ƒ‚|sjd}t j|ƒ t|ƒ‚tjj|d| ƒ}tjj|ƒs¢d| }t j|ƒ t|ƒ‚|r°t j	dƒ |r¾t j	dƒ t
j
d||gƒ d S )	NzKeyboard layout not specified.z,Keyboard layout directory %s does not exist.zKeyboard variant not specified.z
%s.bmap.gzz(Keyboard variant file %s does not exist.z+Keyboard model is ignored for Alpine Linux.z.Keyboard options are ignored for Alpine Linux.zsetup-keymap)ÚLOGÚerrorÚRuntimeErrorÚosÚpathr   Úkeymap_pathÚisdirÚisfileZwarningr   )r   r-   r.   r/   r0   ÚmsgZkeymap_layout_pathZkeymap_variant_pathr   r   r   Ú
set_keymapv   s4    





zDistro.set_keymapc             C   s   t j|| j|ƒd� d S )N)ÚtzZtz_file)r   Zset_etc_timezoneZ_find_tz_file)r   r;   r   r   r   Úset_timezone˜   s    zDistro.set_timezonec             C   sš   |d krg }dg}|j dƒ |r6t|tƒr6|j |ƒ n|rNt|tƒrN|j|ƒ |r\|j |ƒ |dkrr|jddgƒ tjd|ƒ}|j|ƒ tj|dd� d S )	NZapkz--quietZupgradez--update-cachez--availablez%s-%sF)Úcapture)ÚappendÚ
isinstancer#   ÚlistÚextendr   Zexpand_package_listr   )r   ÚcommandÚargsr   Úcmdr   r   r   r   r   ›   s    



zDistro.package_commandc             C   s   | j jd| jdgtd� d S )Nzupdate-sourcesÚupdate)Zfreq)r
   Z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_clients)r   r   r   r   Úpreferred_ntp_clients¼   s    
zDistro.preferred_ntp_clientsÚpoweroffÚnowc             C   sn   |dg}|dkr|dg7 }nNy|j tt|ƒd ƒƒ W n2 tk
rh } ztd|f ƒ|‚W Y d d }~X nX |S )Nz-drH   Ú0é<   z?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.)r>   r#   ÚintÚ
ValueErrorÚ	TypeError)r   ÚmodeZdelayÚmessagerB   Úer   r   r   Úshutdown_commandÄ   s    zDistro.shutdown_commandc               C   s   dS )z1
        Alpine uses OpenRC, not systemd
        Fr   r   r   r   r   Úuses_systemdÞ   s    zDistro.uses_systemd)Úrcs)ÚactionÚserviceÚ
extra_argsc      	   
   G   s¢   ddg}ddg}t |ƒ|dg t |ƒ|dg t |ƒd|g t |ƒd|g t |ƒ|dg t |ƒ|dg t |ƒ|dg t |ƒ|d	g d
œ}t || ƒ}tj|d|d�S )a<  
        Perform the requested action on a service. This handles OpenRC
        specific implementation details.

        OpenRC has two distinct commands relating to services,
        'rc-service' and 'rc-update' and the order of their argument
        lists differ.
        May raise ProcessExecutionError
        z
rc-servicez	--nocolorz	rc-updateÚstopÚstartÚdelr   ÚrestartÚstatus)rW   rX   ÚdisableÚenablerZ   Úreloadz
try-reloadr[   T)r=   rS   )r@   r   )	r   rT   rU   rS   rV   Zinit_cmdZ
update_cmdZcmdsrD   r   r   r   Úmanage_serviceå   s    zDistro.manage_service)N)N)NN)rG   rH   N) Ú__name__Ú
__module__Ú__qualname__Zpip_package_namer6   r   Znetwork_conf_fnÚNETWORK_FILE_HEADERZrenderer_configsr	   r   r   r   ZPackageListr   r'   r)   r!   r(   r,   r#   r:   r<   r   r   ÚpropertyrF   rQ   ÚstaticmethodrR   Úclassmethodr_   r   r   r   r   r      s.   


"

r   )Zloggingr4   Z	cloudinitr   r   r   r   Z"cloudinit.distros.parsers.hostnamer   Zcloudinit.settingsr   Z	getLoggerr`   r1   rc   r   r   r   r   r   Ú<module>	   s   
	