o
    x[hÃ  ã                
   @   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