+
    ig                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
Ht ^ RIHtHt ]P                  ! ]4      tRtR tR R ltR	 R
 ltR tR tR tR tR t ! R R]	P6                  4      t]]	P:                  33.tR tR# )zr
This file contains code used to gather the user data passed to an
instance on rootbox / hyperone cloud platforms
N)IPv4Address)sourcessubputil)
EventScope	EventTypez
/etc/hostsc                      \         P                  ! \        R R7      p V '       d   \        P	                  R4       R# \        P	                  R4       R # )T)quietz5/etc/hosts exists - setting manage_etc_hosts to FalseFz=/etc/hosts does not exists - setting manage_etc_hosts to True)r   load_text_file	ETC_HOSTSLOGdebug)hostss    F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.pyget_manage_etc_hostsr      s7    	6E		IJIIMN    c                0    V ^8  d   QhR\         R\        /# )   increturn)intstr)formats   "r   __annotate__r   #   s     : :C :C :r   c           	      \    \        \        \        \        V 4      4      V,           4      4      # N)r   r   r   )addrr   s   &&r   increment_ipr   #   s!    {3{401C7899r   c                N    V ^8  d   QhR\         P                  \        ,          /# )r   r   )typingListr   )r   s   "r   r   r   '   s     
 
6;;s+ 
r   c                4    V \        V ^4      \        V ^4      .# )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   )r   s   &r   get_three_ipsr"   '   s%     	T1T1 r   c                >    \         P                   ! R.V ,           4      # )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&   4   s     99hZ#%&&r   c           	         R pVP                   R9   d   RpV  F!  p \        RRW#R,          VR,          .4       K#  	  R#   \        P                   d2   p\        P                  RTR,          TR,          T4        Rp?Kh  Rp?ii ; i)	z-Sz-sz-c2sourcedestinationz&Failed to arping from "%s" to "%s": %sN)fedoracentosrhel)namer&   r   ProcessExecutionErrorr   warning)itemsdistrosource_paramitemerrors   &&   r   gratuitous_arpr6   =   s    L{{22	sLx.$}:MN 
 )) 		 KK8X]#	 			s   ?B&B  Bc                    \        \        P                  ! R4      \        P                  ! R4      ,           4      p V '       g   R# V  F/  p \        P                  ! V\        . R	OR7      pV'       d   Vu # K1  	  \        P                  RRP                  V 4      4       R#   \
         d,   pTP                  \        P                  8w  d   h  Rp?K  Rp?i\        P                   d!    \        P                  ! \        RT4        K  i ; i)
zAReturns False (not found or error) or a dictionary with metadata.zLABEL=CLOUDMDzLABEL=cloudmdF)devicecallbackmtypeNz-Failed to mount %s when looking for user dataz0Did not find RbxCloud data, searched devices: %s,)vfatfatmsdosfs)setr   find_devs_withmount_cbread_user_data_callbackOSErrorerrnoENOENTMountFailedErrorlogexcr   r   join)devicesr8   rbx_dataerrs       r   get_mdrL   R   s    O,


o
.	/G 	}}00H
   " II:CHHW<M   	yyELL( )$$ 	KKDf	s$   (B!!D
, CD
)D
	D
c                   R^R\        V 4       UUUu. uF  w  rRRRRP                  \        V4      4      RVR,          P                  4       R	VR
,           Uu. uFI  pRRRVR,          RVR,          R,          RRRVR,          R,          RVR,          R,          R,          /NKK  	  up/NK  	  uppp/# u upi u upppi )zGenerate network configuration

@param netadps: A list of network adapter settings

@returns: A dict containing network config
versionconfigtypephysicalr.   zeth{}mac_address
macaddresssubnetsipstaticaddressnetmasknetworkcontrolautogatewaydns_nameserversdnsnameservers)	enumerater   r   lower)netadpsinetadprU   s   &   r   generate_network_configre   q   s     	1& 'w/'
& 0	# 
s1v.vl399; %Tl + !2i=!6)#4Y#?!6!6)#4Y#?)6)+<U+C),	 +	$ 0'
 
s   AB;AB6"(B;6B;c                .   \         P                  ! \         P                  ! \        P                  P                  V R4      R7      R7      p\         P                  ! \        P                  P                  V R4      RR7      pRV9  g   RV9  d   \         P                  ! \        R	4       R
# VP                  R/ 4      P                  R4      pVP                  R/ 4      P                  R. 4      pR
pVP                  R/ 4      P                  R4      '       d   VR,          R,          R,          p\        VR,          4      pRTRRVR,          R,          RVR,          R,          R. /RVR,           UUU	u. uF@  pVR,           F0  p\        VR,          R,          4       F  p	RVR,          RV	/NK  	  K2  	  KB  	  up	ppRRRR RR!R"RVR#VR$R%.R&VR'R(R)V//R*VR+\        4       //p
\        P                  R,4       \        P                  V
4       V
# u up	ppi )-zThis callback will be applied by util.mount_cb() on the mounted
drive.

@param mount_dir: String representing path of directory where mounted drive
is available

@returns: A dict containing userdata, metadata and cfg based on metadata.
z
cloud.json)fname)textz	user.dataT)rg   r	   vmrd   z(Failed to load metadata. Invalid format.NadditionalMetadatausernamesshKeyspasswordsha512userdatametadatazinstance-id_idzlocal-hostnamer.   public-keysr6   rU   rY   r\   r)   rW   r*   cfg
ssh_pwauthdisable_rootsystem_infodefault_usergecossudozALL=(ALL) NOPASSWD:ALLpasswdlock_passwdFssh_authorized_keysnetwork_configmanage_etc_hostszreturning DATA object:)r   	load_jsonload_binary_fileospathrH   r
   rG   r   getre   r"   r   r   )	mount_dir	meta_data	user_datark   ssh_keyshashrY   rd   rU   targetdatas   &          r   rB   rB      s    ""i)NOI ##ggll9k2$I 9	 9CCD}}126:::FH}}126::9bIHD}})2.22:>>-.z:8D%i&9:G 	I9T?51iof52

 	#H-
-Tll'y(9)(DE r)}mV< F =" =-
 	$DHX56d!5)8!	 g 4 6
D> II&'IIdOK7
s   5AHc                      a  ] tR t^t o Rt]P                  ]P                  ]P                  ]P                  0/tR tR tR t]R 4       tR tR tR tR	 tR
tV tR# )DataSourceRbxCloudRbxCloudc                p    \         P                  P                  WW#4       R V n        R V n        R V n        R # r   )r   
DataSource__init__seedr6   rs   )selfsys_cfgr2   pathss   &&&&r   r   DataSourceRbxCloud.__init__   s.    ##D6A	"r   c                h    \         P                  P                  V 4      pV: R V P                  : R2# )z [seed=])r   r   __str__r   )r   roots   & r   r   DataSourceRbxCloud.__str__   s'    !!))$/!%tyy11r   c                    \        4       pVRJ d   R# VR,          V n        VR,          V n        VR,          V n        VR,          V n        R# )z_
Metadata is passed to the launching instance which
is used to perform instance configuration.
Fro   rp   r6   rs   T)rL   userdata_rawrp   r6   rs   )r   rJ   s   & r   	_get_dataDataSourceRbxCloud._get_data   sK    
 8u$Z0 ,&'78E?r   c                (    V P                   R ,          # )r}   rs   r   s   &r   r}   !DataSourceRbxCloud.network_config   s    xx())r   c                (    V P                   R ,          # )rr   )rp   r   s   &r   get_public_ssh_keys&DataSourceRbxCloud.get_public_ssh_keys   s    }}]++r   c                    V P                   # r   )r   r   s   &r   get_userdata_raw#DataSourceRbxCloud.get_userdata_raw   s       r   c                    V P                   # r   r   r   s   &r   get_config_obj!DataSourceRbxCloud.get_config_obj   s    xxr   c                F    \        V P                   V P                  4       R # r   )r6   r2   )r   rs   is_new_instances   &&&r   activateDataSourceRbxCloud.activate  s    t**DKK8r   )rs   r6   rp   r   r   N)__name__
__module____qualname____firstlineno__dsnamer   NETWORKr   BOOT_NEW_INSTANCEBOOTBOOT_LEGACYdefault_update_eventsr   r   r   propertyr}   r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      su     F''NN!!
2 * *,!9 9r   r   c                 8    \         P                  ! V \        4      # r   )r   list_from_dependsdatasources)dependss   &r   get_datasource_listr     s    $$Wk::r   ) __doc__rD   loggingr   os.pathr   	ipaddressr   	cloudinitr   r   r   cloudinit.eventr   r   	getLoggerr   r   r   r   r   r"   r&   r6   rL   re   rB   r   r   DEP_FILESYSTEMr   r    r   r   <module>r      s      	   ! ) ) 1!	:
'*>B=@09++ 09j '0023;r   