
­­­­­­­­­­­­­­­­­­
<!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_ALWAYSzThis 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rt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<   		
