o
    w7e@                  
   @   s   U d Z ddlZddlZddlmZ ddlmZ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 dd	lmZmZ dd
lmZ ddd edegeededgg dZeed< eeZ eeZdZdZdedede
deddf
ddZ dS )z3Install hotplug udev rules if supported and enabled    N)dedent)stagessubputil)Cloud)Config)
MetaSchemaget_meta_doc)ALL_DISTROS)
EventScope	EventType)PER_INSTANCEcc_install_hotplugzInstall Hotplugas          This module will install the udev rules to enable hotplug if
        supported by the datasource and enabled in the userdata. The udev
        rules will be installed as
        ``/etc/udev/rules.d/10-cloud-init-hook-hotplug.rules``.

        When hotplug is enabled, newly added network devices will be added
        to the system by cloud-init. After udev detects the event,
        cloud-init will referesh the instance metadata from the datasource,
        detect the device in the updated metadata, then apply the updated
        network configuration.

        Currently supported datasources: Openstack, EC2
    z            # Enable hotplug of network devices
            updates:
              network:
                when: ["hotplug"]
        z            # Enable network hotplug alongside boot event
            updates:
              network:
                when: ["boot", "hotplug"]
        )idnametitledescriptiondistros	frequencyexamplesactivate_by_schema_keysmetaz2/etc/udev/rules.d/10-cloud-init-hook-hotplug.rulesz# Installed by cloud-init due to network hotplug userdata
ACTION!="add|remove", GOTO="cloudinit_end"
LABEL="cloudinit_hook"
SUBSYSTEM=="net", RUN+="{libexecdir}/hook-hotplug"
LABEL="cloudinit_end"
r   cfgcloudargsreturnc                 C   s   d|v od|d v od|d d v od|d d d v }t j|jt jgtjt v }tj	|j|t jtjd}|r=|sft
jtrVtd tt tg d d S |r_td d S td	 d S td
srtd d S d}t
j|s|d}tjttj|dd tg d d S )Nupdatesnetworkwhenhotplug)
datasourcer   event_source_typescopez!Uninstalling hotplug, not enabled)udevadmcontrolz--reload-ruleszOHotplug is unsupported by current datasource. Udev rules will NOT be installed.z%Skipping hotplug install, not enabledr#   z+Skipping hotplug install, udevadm not foundz/usr/libexec/cloud-initz/usr/lib/cloud-init)
libexecdir)filenamecontent)r   HOTPLUGr    get_supported_eventsgetr   NETWORKsetr   update_event_enabledospathexistsHOTPLUG_UDEV_PATHLOGdebugr   del_filer   warningwhich
write_fileHOTPLUG_UDEV_RULES_TEMPLATEformat)r   r   r   r   network_hotplug_enabledhotplug_supportedhotplug_enabledr%    r=   E/usr/lib/python3/dist-packages/cloudinit/config/cc_install_hotplug.pyhandleH   sT   






r?   )!__doc__loggingr.   textwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.distrosr
   cloudinit.eventr   r   cloudinit.settingsr   r   __annotations__	getLogger__name__r2   r1   r8   strlistr?   r=   r=   r=   r>   <module>   sB   +
"	