x[h-dZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z ddlmZmZddlmZddlmZddlmZdd lmZdd lmZmZdd lmZej<eZ d Z!dd Z"GddejFZ$Gdde$Z%de%ejLfiZ'dZ(dede)fdZ*deddfdZ+ddZ,dede-fdZ.dZ/edk(re"jaZ1e/e!e1yy)z)Handle reconfiguration on hotplug events.N) reportingstagesutil)install_hotplug) EventScope EventType)loggers)read_sys_net_safe)parse_net_config_data)events) DataSourceDataSourceNotFoundException)Initz hotplug-hookc|stjtt}t|_|j dddddg|j dd }d|_|jd d |jdd }|j ddddd|j ddddddg|jdd |S)aBuild or extend an arg parser for hotplug-hook utility. @param parser: Optional existing ArgumentParser instance representing the subcommand which will be extended to support the args of this utility. @returns: ArgumentParser with proper argument configuration. )prog descriptionz-sz --subsystemTzsubsystem to act onnet)requiredhelpchoiceszHotplug Actionhotplug_action)titledestqueryz0Query if hotplug is enabled for given subsystem.)rhandlezHandle the hotplug event.z-dz --devpathPATHzSysfs path to hotplugged device)rmetavarrz-uz --udevactionzSpecify action to take.addremoveenablez%Enable hotplug for a given subsystem.) argparseArgumentParserNAME__doc__r add_argumentadd_subparsersr add_parser)parser subparsers parser_handles B/usr/lib/python3/dist-packages/cloudinit/cmd/devel/hotplug_hook.py get_parserr,s ((dH F   " &&%5'JJH))2*M  .   &! > MceZdZdZej dZeej dZej de fdZ dZ dZ dZ y ) UeventHandlercJ||_||_||_||_||_yN)id datasourcedevpathaction success_fn)selfr2r3r4r5r6s r+__init__zUeventHandler.__init__Rs%&0  $r-ctr1NotImplementedErrorr7s r+applyzUeventHandler.applyY !##r-ctr1r:r<s r+configzUeventHandler.config]s "##r-returnctr1r:r<s r+device_detectedzUeventHandler.device_detectedbr>r-cd}|jdk(rd}n*|jdk(rd}ntd|jz||jk7rtd|jzy)NrTrFzUnknown action: %sz'Failed to detect %s in updated metadata)r5 ValueErrorrC RuntimeErrorr2)r7detect_presences r+detect_hotplugged_devicez&UeventHandler.detect_hotplugged_devicefsm ;;% "O [[H $#O1DKK?@ @ d224 49DGGC  5r-c"|jSr1)r6r<s r+successzUeventHandler.successts  r-c|jjtjg}|s)t d|jdtj|S)Nz Datasource z not updated for event )r3update_metadata_if_supportedrHOTPLUGrF)r7results r+update_metadatazUeventHandler.update_metadatawsO==     ??I$5$57  r-N)__name__ __module__ __qualname__r8abcabstractmethodr=propertyr@boolrCrHrJrOr-r+r/r/Qss% $$$$ $$$ ! r-r/c@eZdZfdZdZedZdefdZxZ S) NetHandlerc~ttjj|d}t||||||y)Naddress)r ospathbasenamesuperr8)r7r3r4r5r6r2 __class__s r+r8zNetHandler.__init__s3 rww//8) D Z&*Er-c|jjj|jdtj j |j}|jjj}|jdk(r6|j|s$tdj|jy|jdk(r6|j|s$tdj|jyy)NF)bring_uprzFailed to bring up device: {}rzFailed to bring down device: {})r3distroapply_network_configr@r\r]r^r4network_activatorr5bring_up_interfacerFformatbring_down_interface)r7interface_name activators r+r=zNetHandler.applys 33 KK 4 ))$,,7OO**<<> ;;% //?"3::4<<H@[[H $11.A"5< ? > J lI . Gathering network configuration again due to IMDS limitations.) rr}rqrr_write_to_cachetimehotplug_retry_settings force_retry try_hotplug sleep_totalsleep sleep_period)rr4r udevactionr3 handler_cls event_handlerstarts r+handle_hotplugrs&|Y?J *95a8KII)95#.// $M IIKE  , , 8 8I}j9 ))+  A A M M MI}j9 L  :44AAB ))+  A A M M Mr-c Xgd}td}t|D]\}}tjd||t | tjd|j |j s%tjd|jtjd|jtjd|jy|#t$r8}tjd|tj||}Yd}~ d}~wwxYw) N)ry z#Bug while processing hotplug event.z!subsystem=%s update attempt %s/%szRefreshing metadataz$Detecting device in updated metadatazApplying config changezUpdating cachez,Exception while processing hotplug event. %s) Exception enumeraterqrrrsrOskip_hotplug_detectrHr=rJrr)rrr3 wait_timeslast_exceptionattemptwaitrs r+rrs"JDEN":.  /    O    II+ ,  ) ) +11 @A668 II. /    ! II& '  ! ! # #.   IIDa H JJt N sB C(( D)1-D$$D)c|jd}|syt|d}tj|j tjgj |t v}|std|tjytj|j}|j|dvr td|d tjy |dj|jtj|jj!d t#j$|d d t'|d |j(y )NrrFryz#hotplug not supported for event of )filescopesz)Not installing hotplug for event of type z. Reason: Already done.Tzhotplug.enabledwi)omodemode)network_hotplug_enabledrz)rr}rrMrrpsetprintsysstderrrread_hotplug_enabled_filepathsvalueappend write_file get_cpathjsondumpsrrz)rrr3r|hotplug_supportedhotplug_enabled_files r+enable_hotplugrs9##W#5J  $Y / 2E!))''):):(;<@@N  1) =CJJ 99,:L:LM {{*844 7 {C% % "))%++6OO$$%67 '(   Dl6F6F r-c tj|td}tg|}|j t j |jd|jvr.tj|jjdtjd||j|jd|vr |jndd|vr |j nd|5 |jdk(r' t#||j}t'rd nd n|jd k(r.t-||j |j|jnt/j0dk7r4t(j2j5dt)j*d t7||jst)j*d t'd|jdddtjdtj<y#t$$r$t'd t)j*d Y:wxYw#t8$rtj;dwxYw#1swYxYw)NT)reporting_enabled)ds_depsreporterrzh%s called with the following arguments: {hotplug_action: %s, subsystem: %s, udevaction: %s, devpath: %s}rr4rz9Unable to determine hotplug state. No datasource detectedryenableddisabledr)rr4rrrz9Root is required. Try prepending your command with sudo. )rrz)Enabled cloud-init hotplug for subsystem=z*Received fatal exception handling hotplug!zExiting hotplug handler)r ReportEventStackr$rread_cfgr setup_loggingrzrupdate_configurationrprqrrrrrr4rrrrexitrr\getuidrwriterr exception flush_events)nameargshotplug_reporterrr3s r+ handle_argsr's.. g-=>L ,**+l&&&&&|'7'7';';K'HIII J   '4/T!T) t '& ""g-  !6$dnn"J:i:>$$0!- LL"nn# 99;!#JJ$$#HHQK%!-HHQK!!% 02A'RII'( G3 #HHQK  <  MMF G  K''sC%I.'I 7H CI )II II  I++I..I7__main__r1)rAN)2r$rSr!rloggingr\rr cloudinitrrr#cloudinit.config.cc_install_hotplugrcloudinit.eventrr cloudinit.logr cloudinit.netr cloudinit.net.network_stater cloudinit.reportingr cloudinit.sourcesr rcloudinit.stagesr getLoggerrPrqr#r,ABCr/rYNETWORKr}rstrrrrrVrr parse_argsrrWr-r+rs 0   --?1!+=&E!g!3l/CGG/d$$P J ** + $   CC$C0:  T FBJ z < " " $Ddr-