
­­­­­­­­­­­­­­­­­­
<!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|sd| }t j| t||rt j	d |rt 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   
	