f!dZddlZddlZddlZddlZddlmZmZmZm Z eje Z dZ ddgZiddid Zd ZGd d ej"Zd Zeej(ej*ffgZdZy)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|dz}|dz} tj|j}|S#t$rR tj|j}Y|S#t$rtjt dYYywxYwwxYw)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_datas F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAltCloud.pyread_user_data_callbackr&s$!*,G G!11N''(ABHHJ    ++N;AACI    KK? @ s&#1 B #A!!#BB BB c:eZdZdZdZdZdZdZdZdZ dZ y ) DataSourceAltCloudAltCloudcdtjj||||d|_d|_y)N)/zfile://)r DataSource__init__seedsupported_seed_starts)selfsys_cfgdistropathss rrzDataSourceAltCloud.__init__Ls+##D'65A %5"cdtjj|}|d|jdS)Nz [seed=])rr__str__r)r roots rr'zDataSourceAltCloud.__str__Qs'!!))$/!%tyy11r$ctjjtr8 t j tj j}|Stjd}|sy|j}|jdry|jdryy#t$r"t jtdtYywxYw)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 upperrrrr read_dmi_data startswith)r cloud_type system_namesys_names rget_cloud_typez!DataSourceAltCloud.get_cloud_typeUs 77>>/ * !''8>>@FFH ''(=> $$&   v &   x () ! =# !  !s5B))(CCctjd|j}tjdt|d|vr|j ryd|vr|j ryyt jtdy)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.)rdebugr8struser_data_rhevmuser_data_vsphererrr r5s r _get_datazDataSourceAltCloud._get_datasy$ &'((*  "C O4 Z ##% * $%%' C67r$c|j}t|dstj|_|dk(rd|_|j d|jdS)z(Return the subplatform metadata details.sourcer+/dev/fd0z ())r8hasattrrMETADATA_UNKNOWNrAlowerr>s r_get_subplatformz#DataSourceAltCloud._get_subplatformsN((* tX&!22DK  $DK&,,. < 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: %sFrB)r0timeoutzFailed udevadm_settle: %s -Failed to mount %s when looking for user dataT)modprobe_floppyrProcessExecutionErrorrrrudevadm_settleOSErrormount_cbrerrnoENOENTMountFailedError userdata_rawMETA_DATA_NOT_SUPPORTEDmetadata)r return_stre floppy_deverrs rr<z"DataSourceAltCloud.user_data_rhevms           z1 = z3JKJ'/ ?))  KK2A 6 **G4  KK:A >   yyELL()$$  KK?  sK ABCB,B  BC-C  C D5D1D54D5c|d}tjd}|D](} tj|t}|r ||_n*||_ t|_ |ryy#t $r(}|j t jk7rYd}~md}~wtj$rtjtd|YwxYw)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=CDROMrKTF)rfind_devs_withrPrrArOrQrRrSrrrTrUrV)r rW cdrom_list cdrom_devrZs rr=z$DataSourceAltCloud.user_data_vspheres ((7 # I !]]96MN "+DK  '/ ! 99 ,-((  C s#A B;$B1B;:B;N) __name__ __module__ __qualname__dsnamerr'r8r?rGr<r=r$rrrHs- F6 2)V%N=4l&r$rctjt\}}tjddj t|y)NzCommand: %s Output%s )rCMD_PROBE_FLOPPYrr:join)out_errs rrLrLs0 *+ICII%sxx0@'A3Gr$c6tj|tS)N)rlist_from_depends datasources)dependss rget_datasource_listrns  $ $Wk ::r$)__doc__rQloggingr.os.path cloudinitrrrr getLoggerr_rr1rfrUrrrrLDEP_FILESYSTEM DEP_NETWORKrlrnrcr$rrvs   ..g!.)! DD++DNH'00'2E2EFG ;r$