
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
cj                 @   s   U d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ ejeZd	d
dZdZdddedddddddddddddddgeedgd gd!ZeeeZ d"d# Zee
eedd$d%d&ZdS )'z"Resolv Conf: configure resolv.conf    N)dedent)	templaterutil)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEzresolv.confzsystemd.resolved.conf)z/etc/resolv.confz/etc/systemd/resolved.confa  Unless manually editing :file:`/etc/resolv.conf` is the correct way to manage
nameserver information on your operating system, you do not want to use
this module. Many distros have moved away from manually editing ``resolv.conf``
so please verify that this is the preferred nameserver management method for
your distro before using this module.

Note that using :ref:`network_config` is preferred, rather than using this
module, when possible.

This module is intended to manage resolv.conf in environments where early
configuration of resolv.conf is necessary for further bootstrapping and/or
where configuration management such as puppet or chef own DNS configuration.

When using a :ref:`datasource_config_drive` and a RHEL-like system,
resolv.conf will also be managed automatically due to the available
information provided for DNS servers in the :ref:`network_config_v2` format.
For those that wish to have different settings, use this module.

In order for the ``resolv_conf`` section to be applied, ``manage_resolv_conf``
must be set ``true``.

.. note::
    For Red Hat with sysconfig, be sure to set PEERDNS=no for all DHCP
    enabled NICs.
Zcc_resolv_confzResolv ConfzConfigure resolv.confZ	almalinuxZalpineZ
cloudlinuxZfedoraZmarinerZopensusezopensuse-leapzopensuse-microoszopensuse-tumbleweedZphotonZrhelZsle_hpcz	sle-microZslesZ	openeulera              manage_resolv_conf: true
            resolv_conf:
              nameservers:
                - 8.8.8.8
                - 8.8.4.4
              searchdomains:
                - foo.example.com
                - bar.example.com
              domain: example.com
              sortlist:
                - 10.0.0.1/255
                - 10.0.0.2
              options:
                rotate: true
                timeout: 1
            manage_resolv_conf)idnametitledescriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keysc             C   s   g }g }d|krNx<|d j  D ],\}}t|tr|r@|j| q|j| qW x|| D ]}|d |= qXW |jds|i |d< ||d< tjd|  tj| || d S )NZoptionsflagsz$Writing resolv.conf from template %s)	items
isinstanceboolappendgetLOGdebugr   Zrender_to_file)template_fnparamstarget_fnamer   Zfalse_flagskeyvalflag r   $/usr/lib/python3.6/cc_resolv_conf.pygenerate_resolv_confh   s    

r   )r   cfgcloudargsreturnc             C   s   d|krt jd|  dS tj|dds6t jd|  dS d|krLt jd dS y|jt|jj }W n t	k
r   t jd dS X t
||d |jjd	 dS )
a[  
    Handler for resolv.conf

    @param name: The module name "resolv_conf" from cloud.cfg
    @param cfg: A nested dict containing the entire cloud config contents.
    @param cloud: The L{CloudInit} object in use.
    @param log: Pre-initialized Python logger object to use for logging.
    @param args: Any module arguments from cloud.cfg
    r
   zFSkipping module named %s, no 'manage_resolv_conf' key in configurationNFzGSkipping module named %s, 'manage_resolv_conf' present but set to FalseZresolv_confz3manage_resolv_conf True but no parameters provided!z0No template found, not rendering resolve configs)r   r   r   )r   r   r   Zget_cfg_option_boolZwarningZget_template_filenameRESOLVE_CONFIG_TEMPLATE_MAPZdistroZresolve_conf_fnKeyErrorr   )r   r    r!   r"   r   r   r   r   handle   s0    


r&   )__doc__Zloggingtextwrapr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr	   Z	getLogger__name__r   r$   ZMODULE_DESCRIPTIONmetar   strlistr&   r   r   r   r   <module>	   sJ   
