HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_set_hostname.cpython-36.pyc
3

\�me��	@s�UdZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZdd	lmZdd
lmZeZdZdd
deegeded�ggd�Zeee�Zeje�ZGdd�de�Zeee
edd�dd�ZdS)z#Set Hostname: Set hostname and FQDN�N)�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.
Zcc_set_hostnamezSet HostnamezSet hostname and FQDNzpreserve_hostname: truezz            hostname: myhost
            fqdn: myhost.example.com
            prefer_fqdn_over_hostname: true
            )�id�name�title�descriptionZdistros�	frequencyZexamplesZactivate_by_schema_keysc@seZdZdZdS)�SetHostnameErrorz�Raised 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__�rr�%/usr/lib/python3.6/cc_set_hostname.pyrKsr)r�cfg�cloud�args�returncCs�tj|dd�rtjd|�dStj|dd�}|dk	rB|jjd|�tj|dd�}|dk	rf|jjd|�tj||�\}}}tjj	|j
d�d�}	i}
tjj|	�r�tj|	�j
dkr�tjtj|	��}
||
jd	�kp�||
jd
�k}|s�tjd�dS|o�|dk�rtjd
�dStjd||�y|jj||�WnNtk
�rt}z0d||f}
tjt|
�td|
|f�|�WYdd}~XnXt|	||d��dS)NZpreserve_hostnameFzVConfiguration option 'preserve_hostname' is set, not setting the hostname in module %sZprefer_fqdn_over_hostname�create_hostname_file�datazset-hostnamer�hostname�fqdnz*No hostname changes. Skipping set_hostnameZ	localhostz6Hostname is localhost. Let other services handle this.zSetting the hostname to %s (%s)z%Failed to set the hostname to %s (%s)z%s: %s)rr)rZget_cfg_option_bool�LOG�debugZdistroZ
set_optionZget_hostname_fqdn�os�path�joinZ	get_cpath�exists�stat�st_sizeZ	load_jsonZ	load_file�getZset_hostname�	ExceptionZlogexcrr)rrrrZ
hostname_fqdnrrrZ
is_defaultZprev_fnZ
prev_hostnameZhostname_changed�e�msgrrr�handleSsF



$r+)rZloggingr!�textwraprZ	cloudinitrZcloudinit.atomic_helperrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.distrosr	Zcloudinit.settingsr
rZMODULE_DESCRIPTION�metaZ	getLoggerrrr(r�str�listr+rrrr�<module>s4