o
    wÚ7eŒ  ã                   @   sÜ   U d Z ddlZddl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mZ ddlmZ d	Zd
gZdddeeedƒedƒedƒedƒedƒgeg dœZeed< eeƒZ e e¡Zdede
dededdf
dd„ZdS )z)Update Hostname: Update hostname and fqdné    N)Údedent)Úutil)ÚCloud)ÚConfig)Ú
MetaSchemaÚget_meta_doc)Ú
PER_ALWAYSzöThis module will update the system hostname and fqdn. If ``preserve_hostname``
is set ``true``, then the hostname will not be altered.

.. note::
    for instructions on specifying hostname and fqdn, see documentation for
    ``cc_set_hostname``
ÚallÚcc_update_hostnamezUpdate HostnamezUpdate hostname and fqdna¡          # By default: when ``preserve_hostname`` is not specified cloud-init
        # updates ``/etc/hostname`` per-boot based on the cloud provided
        # ``local-hostname`` setting. If you manually change ``/etc/hostname``
        # after boot cloud-init will no longer modify it.
        #
        # This default cloud-init behavior is equivalent to this cloud-config:
        preserve_hostname: false
        zh        # Prevent cloud-init from updating the system hostname.
        preserve_hostname: true
        ze        # Prevent cloud-init from updating ``/etc/hostname``
        preserve_hostname: true
        z©        # Set hostname to "external.fqdn.me" instead of "myhost"
        fqdn: external.fqdn.me
        hostname: myhost
        prefer_fqdn_over_hostname: true
        zÇ        # Set hostname to "external" instead of "external.fqdn.me" when
        # cloud metadata provides the ``local-hostname``: "external.fqdn.me".
        prefer_fqdn_over_hostname: false
        )ÚidÚnameÚtitleÚdescriptionÚdistrosÚexamplesÚ	frequencyÚactivate_by_schema_keysÚmetar   ÚcfgÚcloudÚargsÚreturnc           	   	   C   sÈ   t  |dd¡rt d| ¡ d S t  |dd ¡}|d ur!|j d|¡ t  ||¡\}}}|r7|dkr7t d¡ d S ztj 	| 
d¡d¡}t d	||¡ |j |||¡ W d S  tyc   t  td
||¡ ‚ w )NÚpreserve_hostnameFzWConfiguration option 'preserve_hostname' is set, not updating the hostname in module %sÚprefer_fqdn_over_hostnameÚ	localhostz6Hostname is localhost. Let other services handle this.Údatazprevious-hostnamezUpdating hostname to %s (%s)z(Failed to update the hostname to %s (%s))r   Úget_cfg_option_boolÚLOGÚdebugÚdistroÚ
set_optionÚget_hostname_fqdnÚosÚpathÚjoinÚ	get_cpathÚupdate_hostnameÚ	ExceptionÚlogexc)	r   r   r   r   Úhostname_fqdnÚhostnameÚfqdnÚ
is_defaultÚprev_fn© r.   úE/usr/lib/python3/dist-packages/cloudinit/config/cc_update_hostname.pyÚhandleV   s2   ýÿ
ÿür0   )Ú__doc__Úloggingr"   Útextwrapr   Ú	cloudinitr   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   r   Úcloudinit.settingsr   ÚMODULE_DESCRIPTIONr   r   Ú__annotations__Ú	getLoggerÚ__name__r   ÚstrÚlistr0   r.   r.   r.   r/   Ú<module>   sL   	ÿÿÿÿÿà(Ñ2
"