
    f              
          U d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ d	Zd
gZdddee ed       ed       ed      gedgdZeed<    ee      Z  ej(                  e      Zdede
dededdf
dZy)z@Update Etc Hosts: Update the hosts file (usually ``/etc/hosts``)    N)dedent)	templaterutil)Cloud)Config)
MetaSchemaget_meta_doc)
PER_ALWAYSa  This module will update the contents of the local hosts database (hosts file;
usually ``/etc/hosts``) based on the hostname/fqdn specified in config.
Management of the hosts file is controlled using ``manage_etc_hosts``. If this
is set to false, cloud-init will not manage the hosts file at all. This is the
default behavior.

If set to ``true``, cloud-init will generate the hosts file
using the template located in ``/etc/cloud/templates/hosts.tmpl``. In the
``/etc/cloud/templates/hosts.tmpl`` template, the strings ``$hostname`` and
``$fqdn`` will be replaced with the hostname and fqdn respectively.

If ``manage_etc_hosts`` is set to ``localhost``, then cloud-init will not
rewrite the hosts file entirely, but rather will ensure that a entry for the
fqdn with a distribution dependent ip is present (i.e. ``ping <hostname>`` will
ping ``127.0.0.1`` or ``127.0.1.1`` or other ip).

.. note::
    if ``manage_etc_hosts`` is set ``true``, the contents
    of the hosts file will be updated every boot. To make any changes to
    the hosts file persistent they must be made in
    ``/etc/cloud/templates/hosts.tmpl``

.. note::
    for instructions on specifying hostname and fqdn, see documentation for
    ``cc_set_hostname``
allcc_update_etc_hostszUpdate Etc Hostsz.Update the hosts file (usually ``/etc/hosts``)z    # Do not update or manage /etc/hosts at all. This is the default behavior.
    #
    # Whatever is present at instance boot time will be present after boot.
    # User changes will not be overwritten.
    manage_etc_hosts: false
    aT      # Manage /etc/hosts with cloud-init.
    # On every boot, /etc/hosts will be re-written from
    # ``/etc/cloud/templates/hosts.tmpl``.
    #
    # The strings '$hostname' and '$fqdn' are replaced in the template
    # with the appropriate values either from the config-config ``fqdn`` or
    # ``hostname`` if provided. When absent, the cloud metadata will be
    # checked for ``local-hostname` which can be split into <hostname>.<fqdn>.
    #
    # To make modifications persistent across a reboot, you must modify
    # ``/etc/cloud/templates/hosts.tmpl``.
    manage_etc_hosts: true
    a!      # Update /etc/hosts every boot providing a "localhost" 127.0.1.1 entry
    # with the latest hostname and fqdn as provided by either IMDS or
    # cloud-config.
    # All other entries will be left as is.
    # 'ping `hostname`' will ping 127.0.1.1
    manage_etc_hosts: localhost
    manage_etc_hosts)idnametitledescriptiondistrosexamples	frequencyactivate_by_schema_keysmetar   cfgcloudargsreturnc                    t        j                  |dd      }|j                  j                  }t        j                  |dg      r|dk(  rt        j
                  ddd       t        j                  ||      \  }}}|st        j                  d	       y |j                  d
|j                  j                  z        }	|	s"t        d|j                  j                  z        t        j                  |	|||d       y |dk(  ret        j                  ||      \  }}}|st        j                  d	       y t        j                  d|       |j                  j                  ||       y t        j                  d||        y )Nr   Ftemplate)addonsz+Value 'template' for key 'manage_etc_hosts'z22.2zUse 'true' instead.)
deprecateddeprecated_versionextra_messagez<Option 'manage_etc_hosts' was set, but no hostname was foundzhosts.%sz.No hosts template could be found for distro %s)hostnamefqdn	localhostzManaging localhost in %szPConfiguration option 'manage_etc_hosts' is not set, not managing %s in module %s)r   get_cfg_option_strdistrohosts_fntranslate_bool	deprecateget_hostname_fqdnLOGwarningget_template_filenameosfamilyRuntimeErrorr   render_to_filedebugupdate_etc_hosts)
r   r   r   r   manage_hostsr&   r!   r"   _tpl_fn_names
             F/usr/lib/python3/dist-packages/cloudinit/config/cc_update_etc_hosts.pyhandler6   e   sb   **30BEJL||$$H<=:%NNH#)3
 #44S%@4KKN  11%,,//0
 @<<((* 
 	  $#G	
 
	$"44S%@4KKN 		,h7%%h5		,		
    )__doc__loggingtextwrapr   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.settingsr
   MODULE_DESCRIPTIONr   r   __annotations__	getLogger__name__r*   strlistr6    r7   r5   <module>rG      s    G   % ! # < ) 8 '  =%	
 		
  			
5$J  23Y-j -^ t
g!1
 1
6 1
% 1
t 1
 1
r7   