o x[hi*@sddlZddlZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZeeZdZd ZGd d d ejZdd dZedfddZ dddZdddZdS)N)List)distrossubputil)Apt)PackageManager) HostnameConf)CLOUDINIT_NETPLAN_FILEa8# 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} z/etc/default/localecseZdZdZdedZededededddZd Zd Z fd d Z d dZ d+ddZ fddZ ddZddZddZd,ddZddZdd Zd-d!d"Zd#d$Zd%ed&ed'ed(efd)d*ZZS).Distroz /etc/hostnamez'/etc/network/interfaces.d/50-cloud-init)eninetplanr )eni_path eni_headerr T) netplan_pathnetplan_headerpostcmdsz /var/lib/dhcpzdhclient\.\w+\.leasescs@t|||d|_d|_d|_t|j||_|jg|_ dS)NdebianzC.UTF-8) super__init__osfamilydefault_locale system_localer from_config_runneraptpackage_managers)selfnamecfgpaths __class__:/usr/lib/python3/dist-packages/cloudinit/distros/debian.pyr7s zDistro.__init__cCs |jst|_|jr |jS|jS)z9Return the default locale if set, else use default locale)rread_system_localerrr"r"r# get_localeBs  zDistro.get_localeNLANGc Cs|st}|s td|}tj|}|j }|r#tdt|j ntd|jt| | kp7| p7|}| p>|p>|}|rKt ||||j dn td||j||rdt ||||j dd|_dSdS)zeApply specified locale to system, regenerate if specified locale differs from system default.zFailed to provide locale value.zVSystem locale not found in %s. Assuming system locale is %s based on hardcoded defaultzSystem locale set to %s via %s)keynameinstall_functionz9System has '%s=%s' requested '%s', skipping regeneration.N)LOCALE_CONF_FN ValueErrorr&ospathexistsrLOGdebugrlowerregenerate_localeinstall_packagesupdate_locale_conf) rlocaleout_fnr( distro_localeconf_fn_existssys_locale_unset need_regen need_confr"r"r# apply_localeMs\  zDistro.apply_localecsttj|i|SN)_maybe_remove_legacy_eth0r_write_network_state)rargskwargsr r"r#r?szDistro._write_network_statecCsxd}z||}Wnty%t|jdd}|rntdYdSYnw|s,td}||t |t |ddS)Ncreate_hostname_fileTz8create_hostname_file is False; hostname file not created) _read_hostname_confIOErrorrget_cfg_option_bool_cfgr/infor set_hostname write_filestr)rhostnamefilenameconfrBr"r"r#_write_hostnames&   zDistro._write_hostnamecCs||j}|j|fSr=)_read_hostnamehostname_conf_fn)r sys_hostnamer"r"r#_read_system_hostnames  zDistro._read_system_hostnamecCstt|}||Sr=)rrload_text_fileparse)rrNrOr"r"r#rEszDistro._read_hostname_confcCs8d}z ||}|j}Wn tyYnw|s|S|Sr=)rErMrF)rrNdefaultrMrOr"r"r#rQs   zDistro._read_hostnamecCsdS)Nz 127.0.1.1r"r%r"r"r#_get_localhost_ipszDistro._get_localhost_ipcCstj|||ddS)N)tztz_file)rset_etc_timezone _find_tz_file)rrYr"r"r# set_timezoneszDistro.set_timezonecCs(|dkr td|d|jddS)NupgradezUnable to handle z command) RuntimeErrorrrun_package_command)rcommandr@pkgsr"r"r#package_commandszDistro.package_commandcCstSr=)rget_dpkg_architecturer%r"r"r#get_primary_archszDistro.get_primary_archlayoutmodelvariantoptionsc Cs^dddd|dd|dd|dd|ddd dg }tjd |d d d |dddS)N z'# This file was generated by cloud-initrCz XKBMODEL=""z XKBLAYOUT="z XKBVARIANT="z XKBOPTIONS="zBACKSPACE="guess"z/etc/default/keyboardrDw)rNcontentmodeomoderestartz console-setup)joinrrKmanage_service)rrfrgrhricontentsr"r"r# set_keymaps&      zDistro.set_keymap)Nr'r=)NN)__name__ __module__ __qualname__rRr network_conf_fnNETWORK_FILE_HEADERrenderer_configsdhclient_lease_directorydhclient_lease_file_regexrr&r<r?rPrTrErQrXr]rcrerLrt __classcell__r"r"r r#r !s8   ;   "r "/etc/network/interfaces.d/eth0.cfgcCstj|sdSd}z(t|}ddg}dd|D}||kr+t|d|}n|d|}WntyA|d |}Ynwt |dS) aOUbuntu cloud images previously included a 'eth0.cfg' that had hard coded content. That file would interfere with the rendered configuration if it was present. if the file does not exist do nothing. If the file exists: - with known content, remove it and warn - with unknown content, leave it and warn Nz(Dynamic networking config may not apply.z auto eth0ziface eth0 inet dhcpcSsg|] }|ds|qS)#) startswithstrip).0fr"r"r# s  z-_maybe_remove_legacy_eth0..zremoved %s with known contentsz* '%s' exists with user configured content.z" %s exists, but could not be read.) r,r-r.rrU splitlinesdel_file Exceptionr/warning)r-bmsgrsknown_contentslinesmsgr"r"r#r>s$      r>r'cCsDd}|s td|tj|r t|}t|}||d}|S)z.Read system default locale setting, if presentrCzInvalid path: %s)r+r,r-r.rrUload_shell_contentget)sys_pathr(sys_vallocale_content sys_defaultsr"r"r#r$ s     r$cCsHtd|||tds|dgtjdd|d||fgdddS) zUpdate system locale configz%Updating %s with locale setting %s=%sz update-localelocalesz--locale-file=z%s=%sFcaptureN)r/r0rwhichr5rr(r)r"r"r#r4s    r4cCsT|dvrtd||dStds|dgtd|tjd|gdddS) z Run locale-gen for the provided locale and set the default system variable `keyname` appropriately in the provided `sys_path`. )czc.utf-8posixz$%s=%s does not require rengenerationNz locale-genrzGenerating locales for %sFr)r1r/r0rrrr"r"r#r2+s    r2)r~)r'N)loggingr,typingr cloudinitrrr(cloudinit.distros.package_management.aptr4cloudinit.distros.package_management.package_managerr"cloudinit.distros.parsers.hostnamercloudinit.net.netplanr getLoggerrur/ryr*r r>r$r4r2r"r"r"r#s$        J