U '¡Dg™ ã@s¶UdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZd egegd œZe ed <e e¡ZGd d„deƒZee eeddœdd„ZdS)z#Set Hostname: Set hostname and FQDNéN)Úutil)Ú write_json)ÚCloud)ÚConfig)Ú MetaSchema)Ú ALL_DISTROS)Ú PER_INSTANCEZcc_set_hostname)ÚidZdistrosZ frequencyZactivate_by_schema_keysÚmetac@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úB/usr/lib/python3/dist-packages/cloudinit/config/cc_set_hostname.pyr sr )ÚnameÚcfgÚcloudÚargsÚreturnc CsŒt |dd¡rt d|¡dSt |dd¡}|dk rB|j d|¡t |dd¡}|dk rf|j d|¡t ||¡\}}}tj  |  d¡d¡} i} tj  | ¡r¼t  | ¡j dkr¼t t | ¡¡} ||  d ¡kpÖ||  d ¡k} | sêt d ¡dS|r|d krt d ¡dSt d||¡z|j ||¡WnNtk rv} z.d||f} t t| ¡td| | fƒ| ‚W5d} ~ XYnXt| ||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_jsonZload_text_fileÚgetZ set_hostnameÚ ExceptionZlogexcr r)rrrrZ hostname_fqdnrrrZ is_defaultZprev_fnZ prev_hostnameZhostname_changedÚeÚmsgrrrÚhandle'sXýÿÿÿ þ    $r')rZloggingrZ cloudinitrZcloudinit.atomic_helperrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.distrosrZcloudinit.settingsrr Ú__annotations__Z getLoggerr rr$r ÚstrÚlistr'rrrrÚs"       ü