܍~c)!dZddlZddlZddlZddlmZddlmZddlmZm Z m Z ej e Z dZddgZid d id Zd ZGd dejZdZeejejffgZdZdS)zb This file contains code used to gather the user data passed to an instance on RHEVm and vSphere. N)dmi)log)sourcessubputilz/etc/sysconfig/cloud-infomodprobefloppyi localhost)zblock-device-mappingz instance-idzlocal-hostname placementc2|dz}|dz} tj|}nd#t$rW tj|}n,#t$rtjt dYYdSwxYwYnwxYw|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_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!11NN#<==CCEE  ~66<<>>II    K? @ @ @444  I s2&3 B&A%$B%$B B BBBc<eZdZdZdZdZdZdZdZdZ dZ d S) DataSourceAltCloudAltCloudcftj||||d|_d|_dS)N)/zfile://)r DataSource__init__seedsupported_seed_starts)selfsys_cfgdistropathss rrzDataSourceAltCloud.__init__Ms4##D'65AAA %5"""cZtj|}|d|jdS)Nz [seed=])rr__str__r)r!roots rr(zDataSourceAltCloud.__str__Rs-!))$//!%tyyy11r%ctjtrr t jt}n1#t$r$t j tdtYdSwxYw|Stj d}|sdS|}| drdS| drdSdS)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 rupperrrrr read_dmi_data startswith)r! cloud_type system_namesys_names rget_cloud_typez!DataSourceAltCloud.get_cloud_typeVs 7>>/ * *  !!^O<<BBDDJJLL  ! ! ! =# !yy  ! '(=>>  9$$&&   v & & 6   x ( ( 9ys=A$$*BBcVtd|}tdt|d|vr|rdSnd|vr|rdSndSt jtddS)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.)rdebugr9struser_data_rhevmuser_data_vsphererrr!r6s r _get_datazDataSourceAltCloud._get_datas$ &'''((**  "C OO444 Z  ##%% t  * $ $%%'' t  5 C6777ur%c|}t|dstj|_|dkrd|_|d|jdS)z(Return the subplatform metadata details.sourcer,/dev/fd0z ())r9hasattrrMETADATA_UNKNOWNrBlowerr?s r_get_subplatformz#DataSourceAltCloud._get_subplatformsd((** tX&& 3!2DK   $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: %sFrC)r1timeoutzFailed 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        )    K2A 6 6 655555     z1 = = = = =*G4    K:A > > >55555  z3JKKJJ   yEL(()(((($    K?      '/  45sJAAAA%%B!;BB!%C D C%%-DDcfd}tjd}|D]} tj|t}|r ||_nY)#t $r }|jt jkrYd}~Nd}~wtj$rtj td|Y}wxYw||_ t|_ |rdSdS)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=CDROMrLTF)rfind_devs_withrQrrBrPrRrSrTrrrUrVrW)r!rX cdrom_list cdrom_devr[s rr>z$DataSourceAltCloud.user_data_vspheres (77 #  I !]96MNN "+DKE   9 ,,-,,,,(    C '/  45s#A B A''-BBN) __name__ __module__ __qualname__dsnamerr(r9r@rHr=r>r%rrrIs F666 222'''R%%%N===444l&&&&&r%rctjt\}}tddt|dS)NzCommand: %s Output%s )rCMD_PROBE_FLOPPYrr;join)out_errs rrMrMs@ *++ICII%sxx0@'A'A3GGGGGr%c6tj|tS)N)rlist_from_depends datasources)dependss rget_datasource_listros  $Wk : ::r%)__doc__rRr/os.path cloudinitrrloggingrrr getLoggerr`rr2rgrVrrrrMDEP_FILESYSTEM DEP_NETWORKrmrordr%rrws<  $$$$$$))))))))))g!!.)! DBBBBB+BBBJHHH'0'2EFG ;;;;;r%