f,2dZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZejeZdZdZded efd Zd ej.efd Zd Zd ZdZdZdZGdde j<Zee j@ffgZ!dZ"y)zr This file contains code used to gather the user data passed to an instance on rootbox / hyperone cloud platforms N) IPv4Address)sourcessubputil) EventScope EventTypez /etc/hostsctjtd}|rtj dytj dy)NT)quietz5/etc/hosts exists - setting manage_etc_hosts to FalseFz=/etc/hosts does not exists - setting manage_etc_hosts to True)rload_text_file ETC_HOSTSLOGdebug)hostss F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.pyget_manage_etc_hostsrs7     6E  IJIIMN increturnc Ttttt||zSN)strrint)addrrs r increment_ipr#s! {3{401C78 99rc4|t|dt|dgS)zReturn a list of 3 IP addresses: [addr, addr + 2, addr + 3] @param addr: an object that is passed to IPvAddress @return: list of strings )r)rs r get_three_ipsr's% T1T1 rc4tjdg|zS)z Uses the preferred cloud-init subprocess def of subp.subp and runs arping. Breaking this to a separate function for later use in mocking and unittests arping)r)cmds r_sub_arpr"4s 99hZ#% &&rc d}|jdvrd}|D]} tdd||d|dgy#tj$r(}tj d|d|d|Yd}~Sd}~wwxYw) Nz-S)fedoracentosrhelz-sz-c2source destinationz&Failed to arping from "%s" to "%s": %s)namer"rProcessExecutionErrorr warning)itemsdistro source_paramitemerrors rgratuitous_arpr2=sL {{22   sL$x.$}:MN  ))  KK8X]#    s2A-A((A-cttjdtjdz}|sy|D]'} tj|tgd}|r|cS)tjdd j|y#t $r(}|j t jk7rYd}~|d}~wtj$rtjtd|YwxYw) zAReturns False (not found or error) or a dictionary with metadata.z LABEL=CLOUDMDz LABEL=cloudmdF)vfatfatmsdosfs)devicecallbackmtypeNz-Failed to mount %s when looking for user dataz0Did not find RbxCloud data, searched devices: %s,) setrfind_devs_withmount_cbread_user_data_callbackOSErrorerrnoENOENTMountFailedErrorlogexcr rjoin)devicesr7rbx_dataerrs rget_mdrHRs O,   o . /G  }}00H "II:CHHWr>s  " "i)N OI##ggll9k2$I 9 9 CCD}}126:::FH}}126::9bIH D}})2.22:>-.z:8D%i&9:G$T?51'of5 $H-  Tl 'y(9)(DE  )}V < < <  $%56"#(+3 ! & 4 6  D>II&'IIdO K7 s;/F6 ceZdZdZej ejejejhiZ dZ dZ dZ edZdZdZdZd Zy ) DataSourceRbxCloudRbxCloudcVtjj||||d|_yr)r DataSource__init__seed)selfsys_cfgr.pathss rrzDataSourceRbxCloud.__init__s###D'65A rcdtjj|}|d|jdS)Nz [seed=])rr__str__r)rroots rrzDataSourceRbxCloud.__str__s'!!))$/!%tyy11rcrt}|dury|d|_|d|_|d|_|d|_y)zw Metadata is passed to the launching instance which is used to perform instance configuration. Frzr{r2r|T)rH userdata_rawr{r2r|)rrFs r _get_datazDataSourceRbxCloud._get_datasK 8 u $Z0 , &'78E?rc |jdS)Nrxr|rs rrxz!DataSourceRbxCloud.network_configsxx())rc |jdS)Nrn)r{rs rget_public_ssh_keysz&DataSourceRbxCloud.get_public_ssh_keyss}}]++rc|jSr)rrs rget_userdata_rawz#DataSourceRbxCloud.get_userdata_raws   rc|jSrrrs rget_config_objz!DataSourceRbxCloud.get_config_objs xxrcDt|j|jyr)r2r.)rr|is_new_instances ractivatezDataSourceRbxCloud.activatest**DKK8rN)__name__ __module__ __qualname__dsnamerNETWORKrBOOT_NEW_INSTANCEBOOT BOOT_LEGACYdefault_update_eventsrrrpropertyrxrrrrrrrrsm F  ' ' NN  ! ! 2 **,!9rrc6tj|tSr)rlist_from_depends datasources)dependss rget_datasource_listr s  $ $Wk ::r)#__doc__r@loggingros.pathtyping ipaddressr cloudinitrrrcloudinit.eventrr getLoggerrr r rrrrListrr"r2rHrcr>rrDEP_FILESYSTEMrrrrrrs   !))1g!  :C:C: 6;;s+ '*>B=@.9++.9f'0023 ;r