U
    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ee
eeddœ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``
ÚallZ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ÚtitleZdescriptionÚdistrosZexamplesZ	frequencyZactivate_by_schema_keysÚmeta)r   ÚcfgÚcloudÚargsÚreturnc           	   	   C   sÐ   t  |dd¡rt d| ¡ d S t  |dd ¡}|d k	rB|j d|¡ t  ||¡\}}}|rn|dkrnt d¡ d S z6tj 	| 
d¡d¡}t d	||¡ |j |||¡ W n& tk
rÊ   t  td
||¡ ‚ Y nX d S )NZpreserve_hostnameFzWConfiguration option 'preserve_hostname' is set, not updating the hostname in module %sZprefer_fqdn_over_hostnameZ	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   Zget_cfg_option_boolÚLOGÚdebugZdistroZ
set_optionZget_hostname_fqdnÚosÚpathÚjoinZ	get_cpathZupdate_hostnameÚ	ExceptionZlogexc)	r   r   r   r   Zhostname_fqdnZhostnameZfqdnZ
is_defaultZprev_fn© r   úE/usr/lib/python3/dist-packages/cloudinit/config/cc_update_hostname.pyÚhandleV   s:    ý  ÿ
   ÿr   )Ú__doc__Zloggingr   Útextwrapr   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   r   Ú__annotations__Z	getLoggerÚ__name__r   ÚstrÚlistr   r   r   r   r   Ú<module>	   sJ   	ÿÿÿÿÿà(Ñ2
