3 \me!@sdddlZddlZddlmZmZmZmZddlmZddl m Z ej e Z dZGdddejZdS)N)distroshelperssubputil) 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@seZdZdZdZdZdZdeediZddZ d d Z d0d d Z e j dddZddZddZddZd1ddZddZeeeedddZddZd2d d!Zd"d#Zed$d%Zd3d(d)Zed*d+Zed d,eeed-d.d/Zd S)4Distrozpy3-pipz/usr/share/bkeymaps/z&/etc/profile.d/50-cloud-init-locale.shz/etc/network/interfacesZeni)Zeni_pathZ eni_headercCs6tjj||||tj||_d|_d|_d|d<dS)NzC.UTF-8ZalpineZsshdZ ssh_svcname)rr__init__rZRunners_runnerdefault_localeZosfamily)selfnameZcfgpathsr/usr/lib/python3.6/alpine.pyr %s  zDistro.__init__cCs|jS)zgThe default locale for Alpine Linux is different than cloud-init's DataSource default. )r )r rrr get_locale/szDistro.get_localeNcCsB|s |j}|s|j}ddddd|ddg}tj|dj|ddS) N#z?# This file is created by cloud-init once per new instance bootzexport CHARSET=UTF-8zexport LANG=%szexport LC_COLLATE=C i)r locale_conf_fnr write_filejoin)r ZlocaleZout_fnlinesrrr apply_locale5szDistro.apply_locale)pkglistcCs|j|jd|ddS)Nadd)pkgs)update_package_sourcespackage_command)r rrrrinstall_packagesHszDistro.install_packagesc Csnd}y|j|}Wn.tk r@tj|jdd}|r8ndSYnX|sNtd}|j|tj|t|ddS)Ncreate_hostname_fileTri) _read_hostname_confIOErrorrZget_cfg_option_boolZ_cfgrZ set_hostnamerstr)r hostnamefilenameconfr rrr_write_hostnameLs   zDistro._write_hostnamecCs|j|j}|j|fS)N)_read_hostnameZhostname_conf_fn)r Z sys_hostnamerrr_read_system_hostname_s zDistro._read_system_hostnamecCsttj|}|j|S)N)rrZ load_fileparse)r r%r&rrrr!cszDistro._read_hostname_confc Cs:d}y|j|}|j}Wntk r,YnX|s6|S|S)N)r!r$r")r r%defaultr$r&rrrr(hs  zDistro._read_hostnamecCsdS)Nz 127.0.1.1r)r rrr_get_localhost_ipsszDistro._get_localhost_ip)layoutmodelvariantoptionscCs|sd}tj|t|tjj|j|}tjj|sPd|}tj|t||sjd}tj|t|tjj|d|}tjj|sd|}tj|t||rtj d|rtj dt j d||gdS) NzKeyboard layout not specified.z,Keyboard layout directory %s does not exist.zKeyboard 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) LOGerror RuntimeErrorospathr keymap_pathisdirisfileZwarningr)r r-r.r/r0msgZkeymap_layout_pathZkeymap_variant_pathrrr set_keymapvs4         zDistro.set_keymapcCstj||j|ddS)N)tzZtz_file)rZset_etc_timezoneZ _find_tz_file)r r;rrr set_timezoneszDistro.set_timezonecCs|dkr g}dg}|jd|r6t|tr6|j|n|rNt|trN|j||r\|j||dkrr|jddgtjd|}|j|tj|dddS) NZapkz--quietZupgradez--update-cachez --availablez%s-%sF)capture)append isinstancer#listextendrZexpand_package_listr)r commandargsrcmdrrrrrs      zDistro.package_commandcCs|jjd|jdgtddS)Nzupdate-sourcesupdate)Zfreq)r Zrunrr)r rrrrs zDistro.update_package_sourcescCs|jsddg|_|jS)z7Allow distro to determine the preferred ntp client listZchronyZntp)Z_preferred_ntp_clients)r rrrpreferred_ntp_clientss zDistro.preferred_ntp_clientspoweroffnowcCsn|dg}|dkr|dg7}nNy|jtt|dWn2tk rh}ztd|f|WYdd}~XnX|S)Nz-drH0<z?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.)r>r#int ValueError TypeError)r modeZdelaymessagerBerrrshutdown_commands zDistro.shutdown_commandcCsdS)z1 Alpine uses OpenRC, not systemd Frrrrr uses_systemdszDistro.uses_systemd)rcs)actionservice extra_argsc Gsddg}ddg}t||dgt||dgt|d|gt|d|gt||dgt||dgt||dgt||d gd }t||}tj|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-updatestopstartdelrrestartstatus)rWrXdisableenablerZreloadz try-reloadr[T)r=rS)r@r) r rTrUrSrVZinit_cmdZ update_cmdZcmdsrDrrrmanage_services  zDistro.manage_service)N)N)NN)rGrHN) __name__ __module__ __qualname__Zpip_package_namer6rZnetwork_conf_fnNETWORK_FILE_HEADERZrenderer_configsr rrrZ PackageListrr'r)r!r(r,r#r:r<rrpropertyrFrQ staticmethodrR classmethodr_rrrrrs.   "    r)Zloggingr4Z cloudinitrrrrZ"cloudinit.distros.parsers.hostnamerZcloudinit.settingsrZ getLoggerr`r1rcrrrrr s