a '¡Dg®!ã@s dZddlZddlZddlZddlZddlmZmZmZm Z e  e ¡Z dZ ddgZiddid œZd d „ZGd d „d ejƒZdd„ZeejejffgZdd„ZdS)zb This file contains code used to gather the user data passed to an instance on RHEVm and vSphere. éN)ÚdmiÚsourcesÚsubpÚutilz/etc/sysconfig/cloud-infoZmodprobeZfloppyiÇZ localhost)zblock-device-mappingz instance-idzlocal-hostnameZ placementc Csp|d}|d}zt |¡ ¡}WnHtyjzt |¡ ¡}Wn"tydt td¡YYdS0Yn0|S)an Description: This callback will be applied by util.mount_cb() on the mounted file. Deltacloud file name contains deltacloud. Those not using Deltacloud but instead instrumenting the injection, could drop deltacloud from the file name. Input: mount_dir - Mount directory Returns: User Data z/deltacloud-user-data.txtz/user-data.txtz Failed accessing user data file.N)rÚload_text_fileÚstripÚIOErrorÚlogexcÚLOG)Z mount_dirZdeltacloud_user_data_fileZuser_data_fileZ user_data©r úH/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceAltCloud.pyÚread_user_data_callback&s   r cs`eZdZdZdd„Zeddœ‡fdd„ Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z ‡Z S)ÚDataSourceAltCloudZAltCloudcCs*tj ||||¡d|_d|_tj|_dS)N)ú/zfile://)rÚ DataSourceÚ__init__ÚseedZsupported_seed_startsÚMETADATA_UNKNOWNÚsource)ÚselfZsys_cfgZdistroÚpathsr r r rLszDataSourceAltCloud.__init__N)Úci_pkl_versionÚreturncs"tƒ |¡t|dƒstj|_dS)Nr)ÚsuperÚ _unpickleÚhasattrrrr)rr©Ú __class__r r rRs  zDataSourceAltCloud._unpicklecCstj |¡}d||jfS)Nz %s [seed=%s])rrÚ__str__r)rÚrootr r r rWs zDataSourceAltCloud.__str__cCs„tj t¡rJzt t¡ ¡ ¡}Wn"tyDt  t dt¡YdS0|St   d¡}|s\dS| ¡}|  d¡rrdS|  d¡r€dSdS)at Description: Get the type for the cloud back end this instance is running on by examining the string returned by reading either: CLOUD_INFO_FILE or the dmi data. Input: None Returns: One of the following strings: 'RHEV', 'VSPHERE' or 'UNKNOWN' z'Unable to access cloud info file at %s.ZUNKNOWNzsystem-product-nameÚRHEVZVMWAREÚVSPHERE)ÚosÚpathÚexistsÚCLOUD_INFO_FILErrrÚupperrr r rZ read_dmi_dataÚ startswith)rÚ cloud_typeZ system_nameZsys_namer r r Úget_cloud_type[s* ÿ ý   z!DataSourceAltCloud.get_cloud_typecCsbt d¡| ¡}t dt|ƒ¡d|vr8| ¡rRdSnd|vrN| ¡rRdSndSt td¡dS)aœ Description: User Data is passed to the launching instance which is used to perform instance configuration. Cloud providers expose the user data differently. It is necessary to determine which cloud provider the current instance is running on to determine how to access the user data. Images built with image factory will contain a CLOUD_INFO_FILE which contains a string identifying the cloud provider. Images not built with Imagefactory will try to determine what the cloud provider is based on system information. zInvoked get_data()zcloud_type: %sr Tr!FzFailed accessing user data.)r Údebugr)ÚstrÚuser_data_rhevmÚuser_data_vsphererr ©rr(r r r Ú _get_data†s  zDataSourceAltCloud._get_datacCs(| ¡}|dkrd|_d| ¡|jfS)z(Return the subplatform metadata details.r ú/dev/fd0z%s (%s))r)rÚlowerr.r r r Ú_get_subplatform­sz#DataSourceAltCloud._get_subplatformc Csd}z tƒWn6tjyD}zt td|¡WYd}~dSd}~00d}ztj|ddWn:tjtfy–}zt td|¡WYd}~dSd}~00zt |t ¡}WnTtyÚ}z|j t j krÆ‚WYd}~n,d}~0tj yüt td|¡Yn0||_ t|_|rd SdSdS) a¿ RHEVM specific userdata read If on RHEV-M the user data will be contained on the floppy device in file To access it: modprobe floppy Leverage util.mount_cb to: mkdir mount /dev/fd0 The call back passed to util.mount_cb will do: read / NzFailed modprobe: %sFr0é)r$ÚtimeoutzFailed udevadm_settle: %s ú-Failed to mount %s when looking for user dataT)Úmodprobe_floppyrZProcessExecutionErrorrr r Zudevadm_settleÚOSErrorÚmount_cbr ÚerrnoÚENOENTÚMountFailedErrorÚ userdata_rawÚMETA_DATA_NOT_SUPPORTEDÚmetadata)rÚ return_strÚeZ floppy_devÚerrr r r r,´s8  ý z"DataSourceAltCloud.user_data_rhevmc Cs¨d}t d¡}|D]x}z t |t¡}|r4||_WqŒWqtyh}z|jtjkrT‚WYd}~qd}~0tjyˆt  t d|¡Yq0q||_ t |_ |r dSdSdS)a¢ vSphere specific userdata read If on vSphere the user data will be contained on the cdrom device in file To access it: Leverage util.mount_cb to: mkdir mount /dev/fd0 The call back passed to util.mount_cb will do: read / Nz LABEL=CDROMr5TF)rZfind_devs_withr8r rr7r9r:r;r r r<r=r>)rr?Z cdrom_listZ cdrom_devrAr r r r-ês,    ý z$DataSourceAltCloud.user_data_vsphere)Ú__name__Ú __module__Ú __qualname__ZdsnamerÚintrrr)r/r2r,r-Ú __classcell__r r rr rHs+'6rcCs&t t¡\}}t dd t¡|¡dS)NzCommand: %s Output%sú )rÚCMD_PROBE_FLOPPYr r*Újoin)ÚoutZ_errr r r r6sr6cCs t |t¡S)N)rZlist_from_dependsÚ datasources)Zdependsr r r Úget_datasource_list"srL)Ú__doc__r9Zloggingr"Zos.pathZ cloudinitrrrrZ getLoggerrBr r%rHr=r rrr6ZDEP_FILESYSTEMZ DEP_NETWORKrKrLr r r r Ú s( ü"L ÿ