3
\¼me{ ã @ sÐ U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZm
Z
ddlmZ d Zd
gZddd
eeedƒedƒedƒedƒedƒgeg dœZee
eƒZ ejeƒZee
eeddœdd„ZdS )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``
ÚallZcc_update_hostnamezUpdate HostnamezUpdate 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ÚdistrosZexamplesZ frequencyZactivate_by_schema_keys)r ÚcfgÚcloudÚargsÚreturnc
C sô t j|ddƒrtjd| ƒ d S t j|dd ƒ}|d k rB|jjd|ƒ t j|dd ƒ}|d k rf|jjd|ƒ t j||ƒ\}}}|r’|dkr’tjdƒ d S y6tjj |j
dƒd ƒ} tjd
||ƒ |jj||| ƒ W n& tk
rî t j
td||ƒ ‚ Y nX d S )NZpreserve_hostnameFzWConfiguration option 'preserve_hostname' is set, not updating the hostname in module %sZprefer_fqdn_over_hostnameÚcreate_hostname_fileZ localhostz6Hostname is localhost. Let other services handle this.Údatazprevious-hostnamezUpdating hostname to %s (%s)z(Failed to update the hostname to %s (%s))r Zget_cfg_option_boolÚLOGÚdebugZdistroZ
set_optionZget_hostname_fqdnÚosÚpathÚjoinZ get_cpathZupdate_hostnameÚ ExceptionZlogexc)
r r r r Z
hostname_fqdnr ZhostnameZfqdnZ
is_defaultZprev_fn© r ú(/usr/lib/python3.6/cc_update_hostname.pyÚhandleV s2
r )Ú__doc__Zloggingr Útextwrapr Z cloudinitr Zcloudinit.cloudr Zcloudinit.configr Zcloudinit.config.schemar r Zcloudinit.settingsr ZMODULE_DESCRIPTIONr ÚmetaZ getLoggerÚ__name__r ÚstrÚlistr r r r r Ú