o x[h!@sdZddlZddlZddlZddlZddlmZmZmZm Z e e Z dZ ddgZiddid Zd d ZGd d d ejZddZeejejffgZddZdS)zb This file contains code used to gather the user data passed to an instance on RHEVm and vSphere. N)dmisourcessubputilz/etc/sysconfig/cloud-infomodprobefloppyi localhost)zblock-device-mappingz instance-idzlocal-hostname placementc Csn|d}|d}z t|}W|Sty6z t|}WY|Sty5ttdYYdSww)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)rload_text_filestripIOErrorlogexcLOG) mount_dirdeltacloud_user_data_fileuser_data_file user_datarF/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAltCloud.pyread_user_data_callback&s  rcsbeZdZdZddZdeddffdd Zd d Zd d Zd dZ ddZ ddZ ddZ Z S)DataSourceAltCloudAltCloudcCs*tj||||d|_d|_tj|_dS)N)/zfile://)r DataSource__init__seedsupported_seed_startsMETADATA_UNKNOWNsource)selfsys_cfgdistropathsrrrrLs zDataSourceAltCloud.__init__ci_pkl_versionreturnNcs&t|t|dstj|_dSdS)Nr)super _unpicklehasattrrrr)rr# __class__rrr&Rs   zDataSourceAltCloud._unpicklecCstj|}d||jfS)Nz %s [seed=%s])rr__str__r)rrootrrrr*Ws zDataSourceAltCloud.__str__cCstjtr$z tt}W|Sty#t t dtYdSwt d}|s-dS|}| dr8dS| dr?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.UNKNOWNzsystem-product-nameRHEVVMWAREVSPHERE)ospathexistsCLOUD_INFO_FILErr r upperr r rr read_dmi_data startswith)r cloud_type system_namesys_namerrrget_cloud_type[s,     z!DataSourceAltCloud.get_cloud_typecCsbtd|}tdt|d|vr|rdSn d|vr'|r&dSndSttddS)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.)rdebugr:struser_data_rhevmuser_data_vsphererr rr7rrr _get_datas  zDataSourceAltCloud._get_datacCs(|}|dkr d|_d||jfS)z(Return the subplatform metadata details.r-/dev/fd0z%s (%s))r:rlowerr?rrr_get_subplatformsz#DataSourceAltCloud._get_subplatformc Csd}ztWntjy"}zttd|WYd}~dSd}~wwd}z tj|ddWntjtfyK}zttd|WYd}~dSd}~wwzt|t }Wn)tym}z |j t j krcWYd}~nd}~wtj y}ttd|Ynw||_ t|_|rd SdS) 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: %sFrA)r2timeoutzFailed udevadm_settle: %s -Failed to mount %s when looking for user dataT)modprobe_floppyrProcessExecutionErrorrr rudevadm_settleOSErrormount_cbrerrnoENOENTMountFailedError userdata_rawMETA_DATA_NOT_SUPPORTEDmetadata)r return_stre floppy_deverrrrrr=sF   z"DataSourceAltCloud.user_data_rhevmc Csd}td}|D];}zt|t}|r||_Wn+Wq ty4}z |jtjkr*WYd}~q d}~wtjyDt t d|Yq w||_ t |_ |rOdSdS)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=CDROMrFTF)rfind_devs_withrKrrrJrLrMrNr rrOrPrQ)rrR cdrom_list cdrom_devrUrrrr>s4    z$DataSourceAltCloud.user_data_vsphere)__name__ __module__ __qualname__dsnamerintr&r*r:r@rCr=r> __classcell__rrr(rrHs+'6rcCs&tt\}}tddt|dS)NzCommand: %s Output%s )rCMD_PROBE_FLOPPYrr;join)out_errrrrrGsrGcCs t|tS)N)rlist_from_depends datasources)dependsrrrget_datasource_list"s rg)__doc__rLloggingr0os.path cloudinitrrrr getLoggerrYrr3r`rPrrrrGDEP_FILESYSTEM DEP_NETWORKrergrrrrs*  "L