ó 'KXc@sdZddlZddlZddlZddlmZddlmZddlmZddl m Z ej e ƒZ dZdd d gZd d gZd dddgZiid6dd6dd6id6Zd„Zdejfd„ƒYZeejejffgZd„ZdS(sb This file contains code used to gather the user data passed to an instance on RHEVm and vSphere. iÿÿÿÿN(tlog(tsources(tutil(tProcessExecutionErrors/etc/sysconfig/cloud-infos/usr/sbin/dmidecodes--stringssystem-product-names/sbin/modprobetfloppys /sbin/udevadmtsettles--quiets --timeout=5sblock-device-mappingiÇs instance-idt localhostslocal-hostnamet placementcCsƒ|d}|d}ytj|ƒjƒ}WnOtk r~ytj|ƒjƒ}Wqtk rztjtdƒdSXnX|S(sn 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 s/deltacloud-user-data.txts/user-data.txts Failed accessing user data file.N(Rt load_filetstriptIOErrortlogexctLOGtNone(t mount_dirtdeltacloud_user_data_filetuser_data_filet user_data((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytread_user_data_callback7s     tDataSourceAltCloudcBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs/tjj||||ƒd|_d|_dS(Nt/sfile://(Rsfile://(Rt DataSourcet__init__R tseedtsupported_seed_starts(tselftsys_cfgtdistrotpaths((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyRZs cCs#tjj|ƒ}d||jfS(Ns %s [seed=%s](RRt__str__R(Rtroot((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR_scCstjƒd}|jdƒs:|dks:|jdƒrKtjdƒdSt}ytj|ƒ\}}Wnmtk r£}tjddj |ƒ|j fƒdSt k rÙ}tjddj |ƒ|j fƒdSX|j ƒjd ƒród S|j ƒjd ƒr d SdS( sâ Description: Get the type for the cloud back end this instance is running on by examining the string returned by: dmidecode --string system-product-name On VMWare/vSphere dmidecode returns: RHEV Hypervisor On VMWare/vSphere dmidecode returns: VMware Virtual Platform Input: None Returns: One of the following strings: 'RHEV', 'VSPHERE' or 'UNKNOWN' itarmtaarch64tppcs3Disabling AltCloud datasource on arm (LP: #1243287)tUNKNOWNsFailed command: %s %st tRHEVtVMWAREtVSPHERE( tostunamet startswithR tdebugtCMD_DMI_SYSTEMRtsubpRtjointmessagetOSErrortupper(Rt uname_archtcmdtcmd_outt_err((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytget_cloud_typecs(*   cCsâtjdƒtjjtƒriytjtƒjƒj ƒ}Wqut k retj tdtƒt SXn |j ƒ}tjdt|ƒƒd|kr«|jƒrÎtSn#d|krÊ|jƒrÎtSnt Stj tdƒt S(sœ 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. sInvoked get_data()s'Unable to access cloud info file at %s.s cloud_type: R$R&sFailed accessing user data.(R R*R'tpathtexiststCLOUD_INFO_FILERRR R0R R tFalseR5tstrtuser_data_rhevmtTruetuser_data_vsphere(Rt cloud_type((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytget_datas&        cCsd}y?t}tj|ƒ\}}tjddj|ƒ|fƒWnktk r}}tjtddj|ƒ|j ƒt St k r²}tjtddj|ƒ|j ƒt SXd}yPt }|j d|ƒtj|ƒ\}}tjddj|ƒ|fƒWnktk rA}tjtddj|ƒ|j ƒt St k rv}tjtddj|ƒ|j ƒt SXytj|tƒ}WnQt k rº}|jtjkrá‚qán'tjk ràtjtd|ƒnX||_t|_|rýtSt SdS(s¿ 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 / sCommand: %s Output%sR#sFailed command: %s %ss/dev/fd0s--exit-if-exists=s-Failed to mount %s when looking for user dataN(R tCMD_PROBE_FLOPPYRR,R R*R-RR R.R9R/tCMD_UDEVADM_SETTLEtappendtmount_cbRterrnotENOENTtMountFailedErrort userdata_rawtMETA_DATA_NOT_SUPPORTEDtmetadataR<(Rt return_strR2R3R4t floppy_devterr((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR;¿sP$  $       cCs¾d}tjdƒ}x‚|D]z}y tj|tƒ}|rAPnWqtk ro}|jtjkr–‚q–qtjk r•tj t d|ƒqXqW||_ t |_ |r¶tStSdS(s¢ 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 / s LABEL=CDROMs-Failed to mount %s when looking for user dataN(R Rtfind_devs_withRCRR/RDRERFR R RGRHRIR<R9(RRJt cdrom_listt cdrom_devRL((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR=s$     (t__name__t __module__RRR5R?R;R=(((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyRYs    - / BcCstj|tƒS(N(Rtlist_from_dependst datasources(tdepends((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytget_datasource_list/s(t__doc__RDR'tos.patht cloudinitRtloggingRRtcloudinit.utilRt getLoggerRPR R8R+R@RARHRRRtDEP_FILESYSTEMt DEP_NETWORKRSRU(((sQ/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyts*      "Ñ