x[h!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 cVeZdZdZdZdeddffd ZdZdZd Z d Z d Z d Z xZ S) DataSourceAltCloudAltCloudctjj||||d|_d|_tj |_y)N)/zfile://)r DataSource__init__seedsupported_seed_startsMETADATA_UNKNOWNsource)selfsys_cfgdistropathss rrzDataSourceAltCloud.__init__Ls8##D'65A %5".. ci_pkl_versionreturnNcht||t|dstj|_yy)Nr!)super _unpicklehasattrrr r!)r"r' __class__s rr+zDataSourceAltCloud._unpickleRs, .)tX&!22DK'r&cdtjj|}|d|jdS)Nz [seed=])rr__str__r)r"roots rr0zDataSourceAltCloud.__str__Ws'!!))$/!%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_type[s 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: %sr4Tr6FzFailed accessing user data.)rdebugrAstruser_data_rhevmuser_data_vsphererrr"r>s r _get_datazDataSourceAltCloud._get_datasy$ &'((*  "C O4 Z ##% * $%%' C67r&cz|j}|dk(rd|_|jd|jdS)z(Return the subplatform metadata details.r4/dev/fd0z ())rAr!lowerrGs r_get_subplatformz#DataSourceAltCloud._get_subplatforms7((*  $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: %sFrJ)r9timeoutzFailed 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 rrEz"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=CDROMrQTF)rfind_devs_withrVrr!rUrWrXrYrrrZr[r\)r"r] cdrom_list cdrom_devr`s rrFz$DataSourceAltCloud.user_data_vspheres ((7 # I !]]96MN "+DK  '/ ! 99 ,-((  C s#A B;$B1B;:B;)__name__ __module__ __qualname__dsnamerintr+r0rArHrMrErF __classcell__)r-s@rrrHsA F/ 333 2)V%N=4l&r&rctjt\}}tjddj t|y)NzCommand: %s Output%s )rCMD_PROBE_FLOPPYrrCjoin)out_errs rrRrRs0 *+ICII%sxx0@'A3Gr&c6tj|tS)N)rlist_from_depends datasources)dependss rget_datasource_listru"s  $ $Wk ::r&)__doc__rWloggingr7os.path cloudinitrrrr getLoggerrerr:rmr[rrrrRDEP_FILESYSTEM DEP_NETWORKrsrur&rr~s   ..g!.)! DH++HVH'00'2E2EFG ;r&