
"·T`	  ã               @   sƒ   d  d l  m Z d  d l  m Z d  d l  m Z d  d l  m Z d  d l m Z d  d l m Z d Z	 Gd 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 d e d e i 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 „  Z d d „  Z d d d „ Z d d „  Z d d „  Z d d d  d! „ Z d" d# „  Z e d$ d% „  ƒ Z d& d' d d( d) „ Z d S)*ÚDistroz
rc-servicez/etc/profile.d/locale.shz/etc/network/interfacesZeniZeni_pathZ
eni_headerc             C   sK   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/dist-packages/cloudinit/distros/alpine.pyr	   %   s
    		zDistro.__init__c             C   s   |  j  S)zjThe 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   s]   | 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localeÚout_fnÚlinesr   r   r   Úapply_locale5   s    			zDistro.apply_localec             C   s!   |  j  ƒ  |  j d d | ƒd  S)NÚaddÚpkgs)Úupdate_package_sourcesÚpackage_command)r   Úpkglistr   r   r   Úinstall_packagesH   s    
zDistro.install_packagesc             C   s   |  j  | ƒ S)N)Z_supported_write_network_config)r   Z	netconfigr   r   r   Ú_write_network_configL   s    zDistro._write_network_configc             C   sY   d } x  | D] } | d k r d } q W| rB t  j j |  d ƒ St  j j |  | ƒ Sd  S)NFÚallTz-a)r   r   Z_bring_up_interfaceÚ_bring_up_interfaces)r   Zdevice_namesZuse_allÚdr   r   r   r#   O   s    
zDistro._bring_up_interfacesc             C   sj   d  } y |  j  | ƒ } Wn t k
 r- Yn X| s@ t d ƒ } | j | ƒ t j | t | ƒ d ƒ d  S)Nr   i¤  )Ú_read_hostname_confÚIOErrorr   Zset_hostnamer   r   Ústr)r   Zyour_hostnamer   Úconfr   r   r   Ú_write_hostnameY   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_hostnamef   s    zDistro._read_system_hostnamec             C   s#   t  t j | ƒ ƒ } | j ƒ  | S)N)r   r   Z	load_fileÚparse)r   Úfilenamer(   r   r   r   r%   j   s    
zDistro._read_hostname_confc             C   sE   d  } y |  j  | ƒ } | j } Wn t k
 r6 Yn X| sA | S| S)N)r%   Úhostnamer&   )r   r-   Údefaultr.   r(   r   r   r   r*   o   s    zDistro._read_hostnamec             C   s   d S)Nz	127.0.1.1r   )r   r   r   r   Ú_get_localhost_ipz   s    zDistro._get_localhost_ipc             C   s#   t  j d | d |  j | ƒ ƒ d  S)NÚtzZtz_file)r   Zset_etc_timezoneZ_find_tz_file)r   r1   r   r   r   Úset_timezone}   s    zDistro.set_timezonec             C   s¸   | d  k r g  } d g } | j  d ƒ | rM t | t ƒ rM | j  | ƒ n" | ro t | t ƒ ro | j | ƒ | r‚ | j  | ƒ t j d | ƒ } | j | ƒ t j | d d ƒd  S)NZapkz--quietz%s-%sZcaptureF)Ú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 d t ƒd  S)Nzupdate-sourcesÚupdateZ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_clientsZpoweroffÚnowc             C   s‹   | d g } | d k r( | d g 7} n_ y! | j  t t | ƒ d ƒ ƒ Wn; t k
 r† } z t d | f ƒ | ‚ WYd  d  } ~ Xn X| S)Nz-dr<   Ú0é<   z?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.)r3   r'   ÚintÚ
ValueErrorÚ	TypeError)r   ÚmodeZdelayÚmessager7   Úer   r   r   Úshutdown_command¢   s    !
zDistro.shutdown_command)Ú__name__Ú
__module__Ú__qualname__Zinit_cmdr   Znetwork_conf_fnÚNETWORK_FILE_HEADERZrenderer_configsr	   r   r   r    r!   r#   r)   r+   r%   r*   r0   r2   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   	