
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼me{  ã               @   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eƒZ ej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ÚtitleÚdescriptionÚdistrosZexamplesZ	frequencyZactivate_by_schema_keys)r   ÚcfgÚcloudÚargsÚreturnc       
      C   sô   t j|ddƒrtjd| ƒ d S t j|dd ƒ}|d k	rB|jjd|ƒ t j|dd ƒ}|d k	rf|jjd|ƒ t j||ƒ\}}}|r’|dkr’tjdƒ d S y6tjj	|j
dƒd	ƒ}	tjd
||ƒ |jj|||	ƒ W n& tk
rî   t j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_hostnameÚcreate_hostname_fileZ	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_fqdnr   ZhostnameZfqdnZ
is_defaultZprev_fn© r   ú(/usr/lib/python3.6/cc_update_hostname.pyÚhandleV   s2    


r   )Ú__doc__Zloggingr   Útextwrapr   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   ÚmetaZ	getLoggerÚ__name__r   ÚstrÚlistr   r   r   r   r   Ú<module>	   s<   		
