
    f              
       L   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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j6                  e      ZdZdZdedede fdZ!de"dede
de#ddf
dZ$y)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)
DataSourcecc_install_hotplugzInstall Hotplugar          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/90-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 refresh 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/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                    t         j                  | j                  t         j                  g      j                  t        j
                  t                     v }t        j                  | |t         j                  t        j
                        }|r|st        j                  j                  t              rFt        j                  d       t        j                   t               t#        j"                  g d       y |rt        j%                  d       y t        j                  d       y t#        j&                  d      st        j                  d       y | j(                  | j(                  nd}|rd	|z   }d
}t        j                  j                  |      sd}t        j+                  d       t        j,                  t        t.        j1                  ||             t#        j"                  g d       y )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%   s          E/usr/lib/python3/dist-packages/cloudinit/config/cc_install_hotplug.pyinstall_hotplugr?   K   s   
 "))''):):(;<@@	

 11#++  	O /77>>+,II9:MM+,II>? 	 %KK4 	 II=>::i 		?@ ..: 	++ 
 [(*J77>>*%*
HH"#OO"+22#
 3 
 	II67    r   cloudargsreturnc                     d|v xr" d|d   v xr d|d   d   v xr d|d   d   d   v }t        |j                  ||       y )Nupdatesnetworkwhenhotplug)r?   r   )r   r   rA   rB   r   s        r>   handlerI      sh    S 	;Y'	;c)nY//	; Y	26::	  E$$c+BCr@   )%__doc__loggingr.   textwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar	   r
   cloudinit.distrosr   cloudinit.eventr   r   cloudinit.settingsr   cloudinit.sourcesr   r   __annotations__	getLogger__name__r2   r1   r:   boolr?   strlistrI    r@   r>   <module>r\      s   9  	  ( ( ! # < ) 1 + ( B	  }	
 		
$  "Q)j )V t
g!
 I  3838	38 "38lD D6 D% Dt D Dr@   