
    x[h              
           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 ddlmZ dd	lmZ d
egeg dZeed<    ej&                  e      Z G d de      Zdede
dededdf
dZy)z#Set Hostname: Set hostname and FQDN    N)util)
write_json)Cloud)Config)
MetaSchema)ALL_DISTROS)PER_INSTANCEcc_set_hostname)iddistros	frequencyactivate_by_schema_keysmetac                       e Zd ZdZy)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.pyr   r      s    r   r   namecfgcloudargsreturnc                 j   t        j                  |dd      rt        j                  d|        y t        j                  |dd       }||j                  j                  d|       t        j                  |dd       }||j                  j                  d|       t        j                  ||      \  }}}t        j                  j                  |j                  d      d      }	i }
t        j                  j                  |	      rJt        j                  |	      j                  dkD  r(t        j                  t        j                  |	            }
||
j!                  d	      k7  xs ||
j!                  d
      k7  }|st        j                  d       y |r|dk(  rt        j                  d       y t        j                  d||       	 |j                  j#                  ||       t+        |	||d       y # t$        $ r9}d|d|d}t        j&                  t        |       t)        |d|      |d }~ww xY w)Npreserve_hostnameFzVConfiguration option 'preserve_hostname' is set, not setting the hostname in module %sprefer_fqdn_over_hostnamecreate_hostname_filedatazset-hostnamer   hostnamefqdnz*No hostname changes. Skipping set_hostname	localhostz6Hostname is localhost. Let other services handle this.zSetting the hostname to %s (%s)zFailed to set the hostname to z ()z: )r#   r$   )r   get_cfg_option_boolLOGdebugdistro
set_optionget_hostname_fqdnospathjoin	get_cpathexistsstatst_size	load_jsonload_text_filegetset_hostname	Exceptionlogexcr   r   )r   r   r   r   hostname_fqdnr!   r#   r$   
is_defaultprev_fnprev_hostnamehostname_changedemsgs                 r   handlerA   '   s   %8%@		5	

 	 ,,($M   ;]K  33#T ' 68LM#'#9#9#u#E XtZ ggll5??62NCGM	ww~~g2777#3#;#;a#?t':':7'CD=#4#4$  +	""6*	*  		>?h+-		JKII/x@;!!(D1
 wXt<=	  ;9=xHC323:;s   G0 0	H294H--H2)r   loggingr-   	cloudinitr   cloudinit.atomic_helperr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.settingsr	   r   __annotations__	getLoggerr   r(   r8   r   strlistrA   r   r   r   <module>rN      s    *  	  . ! # . ) + }!	j  g!y 4> 4>6 4>% 4>t 4> 4>r   