3 \me@ @sUdZddlZddlZddlmZddlmZmZmZddl m Z ddl m Z ddl mZmZddlmZdd lmZmZdd lmZd d ded egeededggdZeeeZejeZdZdZee e eddddZdS)z3Install hotplug udev rules if supported and enabledN)dedent)stagessubputil)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) EventScope EventType) PER_INSTANCEZcc_install_hotplugzInstall 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"] )idnametitle descriptionZdistrosZ frequencyZexamplesZactivate_by_schema_keysz2/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" )rcfgcloudargsreturncCs d|ko6d|dko6d|ddko6d|dddk}tj|jjtjgjtjtk}tj |j|tjtjd}|ox|st j j t rtjdtjt tjddd gn|rtjd n tjd dStjdstjd dSd }t j j |sd}tjt tj|ddtjddd gdS)NZupdatesZnetworkZwhenZhotplug) datasourcerZevent_source_typeZscopez!Uninstalling hotplug, not enabledZudevadmZcontrolz--reload-ruleszOHotplug is unsupported by current datasource. Udev rules will NOT be installed.z%Skipping hotplug install, not enabledz+Skipping hotplug install, udevadm not foundz/usr/libexec/cloud-initz/usr/lib/cloud-init) libexecdir)filenameZcontent)r ZHOTPLUGrZget_supported_eventsgetr ZNETWORKsetrZupdate_event_enabledospathexistsHOTPLUG_UDEV_PATHLOGdebugrZdel_filerZwarningZwhichZ write_fileHOTPLUG_UDEV_RULES_TEMPLATEformat)rrrrZnetwork_hotplug_enabledZhotplug_supportedZhotplug_enabledrr#(/usr/lib/python3.6/cc_install_hotplug.pyhandleHs@         r%) __doc__ZloggingrtextwraprZ cloudinitrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarr Zcloudinit.distrosr Zcloudinit.eventr r Zcloudinit.settingsr metaZ getLogger__name__rrr!strlistr%r#r#r#r$s6