o
    f                  
   @   s   U d Z ddlZddl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 ddlmZ ddlmZmZ dd	lmZ dd
lmZ degeg dZeed< eeZdZdZdede
defd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)stagessubputil)Cloud)Config)
MetaSchema)ALL_DISTROS)
EventScope	EventType)PER_INSTANCE)
DataSourcecc_install_hotplug)iddistros	frequencyactivate_by_schema_keysmetaz2/etc/udev/rules.d/90-cloud-init-hook-hotplug.rulesz# Installed by cloud-init due to network hotplug userdata
ACTION!="add|remove", GOTO="cloudinit_end"{extra_rules}
LABEL="cloudinit_hook"
SUBSYSTEM=="net", RUN+="{libexecdir}/hook-hotplug"
LABEL="cloudinit_end"

datasourcecfgnetwork_hotplug_enabledc                 C   s  t j| t jgtjt v }tj| |t jtjd}|r|sHt	j
tr8td tt tg d d S |rAtd d S td d S tdsTtd d S | jd ur\| jnd}|rdd	| }d
}t	j
|snd}td tjttj||dd tg d d S )N)r   r   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 found 
z/usr/libexec/cloud-initz/usr/lib/cloud-initzInstalling hotplug.)extra_rules
libexecdir)filenamecontent)r
   HOTPLUGget_supported_eventsgetr	   NETWORKsetr   update_event_enabledospathexistsHOTPLUG_UDEV_PATHLOGdebugr   del_filer   warningwhichextra_hotplug_udev_rulesinfo
write_fileHOTPLUG_UDEV_RULES_TEMPLATEformat)r   r   r   hotplug_supportedhotplug_enabledr   r    r6   E/usr/lib/python3/dist-packages/cloudinit/config/cc_install_hotplug.pyinstall_hotplug%   sX   






r8   namecloudargsreturnc                 C   sJ   d|v od|d v od|d d v od|d d d v }t |j|| d S )Nupdatesnetworkwhenhotplug)r8   r   )r9   r   r:   r;   r   r6   r6   r7   handle[   s   
rA   )"__doc__loggingr&   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   cloudinit.eventr	   r
   cloudinit.settingsr   cloudinit.sourcesr   r   __annotations__	getLogger__name__r*   r)   r2   boolr8   strlistrA   r6   r6   r6   r7   <module>   s6   
	
"6