܍~cs UdZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZdd lmZdd lmZeZd Zd ddeegededggdZeed<eeZGddeZdede de dededdf dZdS)z#Set Hostname: Set hostname and FQDNN)Logger)dedent)util) write_json)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) PER_INSTANCEa'This module handles setting the system hostname and fully qualified domain name (FQDN). If ``preserve_hostname`` is set, then the hostname will not be altered. A hostname and FQDN can be provided by specifying a full domain name under the ``FQDN`` key. Alternatively, a hostname can be specified using the ``hostname`` key, and the FQDN of the cloud will be used. If a FQDN specified with the ``hostname`` key, it will be handled properly, although it is better to use the ``fqdn`` config key. If both ``fqdn`` and ``hostname`` are set, the ``prefer_fqdn_over_hostname`` will force the use of FQDN in all distros when true, and when false it will force the short hostname. Otherwise, the hostname to use is distro-dependent. .. note:: cloud-init performs no hostname input validation before sending the hostname to distro-specific tools, and most tools will not accept a trailing dot on the FQDN. This module will run in the init-local stage before networking is configured if the hostname is set by metadata or user data on the local system. This will occur on datasources like nocloud and ovf where metadata and user data are available locally. This ensures that the desired hostname is applied before any DHCP requests are performed on these platforms where dynamic DNS is based on initial hostname. cc_set_hostnamez Set HostnamezSet hostname and FQDNzpreserve_hostname: truezz hostname: myhost fqdn: myhost.example.com prefer_fqdn_over_hostname: true )idnametitle descriptiondistros frequencyexamplesactivate_by_schema_keysmetaceZdZdZdS)SetHostnameErrorzRaised when the distro runs into an exception when setting hostname. This may happen if we attempt to set the hostname early in cloud-init's init-local timeframe as certain services may not be running yet. N)__name__ __module__ __qualname____doc__B/usr/lib/python3/dist-packages/cloudinit/config/cc_set_hostname.pyrrJsrrrcfgcloudlogargsreturnctj|ddr|d|dStj|dd}||jd|tj||\}}}t j| dd} i} t j | r&tj tj | } || dkp|| dk} | s|d dS|r|d kr|d dS|d || |j||nE#t$r8} d |d|d} tj|| t#| d| | d} ~ wwxYwt%| ||ddS)Npreserve_hostnameFzVConfiguration option 'preserve_hostname' is set, not setting the hostname in module %sprefer_fqdn_over_hostnamedataz set-hostnamehostnamefqdnz*No hostname changes. Skipping set-hostname localhostz6Hostname is localhost. Let other services handle this.zSetting the hostname to %s (%s)zFailed to set the hostname to z ()z: )r)r*)rget_cfg_option_booldebugdistro set_optionget_hostname_fqdnospathjoin get_cpathexists load_json load_fileget set_hostname Exceptionlogexcrr)rr r!r"r# hostname_fqdnr)r* is_defaultprev_fn prev_hostnamehostname_changedemsgs rhandlerDRs2 %8%@@  5    , ($M   ;]KKK#'#9#u#E#E XtZgll5??622NCCGM w~~g@t~g'>'>?? =#4#4$$+ ""6** *  >???h+-- JKKKII/x@@@; !!(D1111 ;;;;9=xxxH C333233:;wXt<<=====s7F G3GG)rr2loggingrtextwrapr cloudinitrcloudinit.atomic_helperrcloudinit.cloudrcloudinit.configrcloudinit.config.schemar r cloudinit.distrosr cloudinit.settingsr rMODULE_DESCRIPTIONr__annotations__r;rstrlistrDrrrrRs*)) ......!!!!!!######<<<<<<<<))))))++++++  :   $%}!     "#j( ,t  y/> />/>#(/>/5/>=A/> />/>/>/>/>/>r