ó oBú]c@sdZddlZddlZddlZddlmZddlmZddlmZddl m Z ej e ƒZ dZdd gZiid 6d d 6d d6id6Zd„Zdejfd„ƒYZd„ZeejejffgZd„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-infotmodprobetfloppysblock-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((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytread_user_data_callback)s     tDataSourceAltCloudcBsMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(tAltCloudcCs/tjj||||ƒd|_d|_dS(Nt/sfile://(Rsfile://(Rt DataSourcet__init__R tseedtsupported_seed_starts(tselftsys_cfgtdistrotpaths((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyROs cCs#tjj|ƒ}d||jfS(Ns %s [seed=%s](RRt__str__R(Rtroot((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyRTscCs¬tjjtƒr]ytjtƒjƒjƒ}Wn%tk rXtj t dtƒdSX|Stj dƒ}|svdS|jƒ}|j dƒr•dS|j dƒr¨dSdS(st 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' s'Unable to access cloud info file at %s.tUNKNOWNssystem-product-nametRHEVtVMWAREtVSPHERE( tostpathtexiststCLOUD_INFO_FILERRR tupperR R R t read_dmi_datat startswith(Rt cloud_typet system_nametsys_name((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytget_cloud_typeXs"   cCs…tjdƒ|jƒ}tjdt|ƒƒd|krN|jƒrqtSn#d|krm|jƒrqtSntStj tdƒtS(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()scloud_type: %sR!R#sFailed accessing user data.( R tdebugR.tstrtuser_data_rhevmtTruetuser_data_vspheretFalseRR (RR+((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyt _get_data~s      cCsY|jƒ}t|dƒs*tj|_n|dkrBd|_nd|jƒ|jfS(s(Return the subplatform metadata details.tsourceR!s/dev/fd0s%s (%s)(R.thasattrRtMETADATA_UNKNOWNR6tlower(RR+((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyt_get_subplatform¥s    cCsd}y tƒWn'tk r:}tjtd|ƒtSXd}ytjd|ddƒWn-ttfk rŠ}tjtd|ƒtSXytj |t ƒ}WnQtk rÎ}|j t j krõ‚qõn'tj k rôtjtd|ƒnX||_t|_|rtStSdS( 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 / sFailed modprobe: %ss/dev/fd0R&ttimeoutisFailed udevadm_settle: %s s-Failed to mount %s when looking for user dataN(R tmodprobe_floppyRRR R R4tudevadm_settletOSErrortmount_cbRterrnotENOENTtMountFailedErrort userdata_rawtMETA_DATA_NOT_SUPPORTEDtmetadataR2(Rt return_strtet floppy_devterr((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR1®s2      cCsÇd}tjdƒ}x‹|D]ƒ}y)tj|tƒ}|rJ||_PnWqtk rx}|jtjkrŸ‚qŸqtj k 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_withR?RR6R>R@RARBR R RCRDRER2R4(RRFt cdrom_listt cdrom_devRI((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR3ás&      ( t__name__t __module__tdsnameRRR.R5R:R1R3(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyRKs   & ' 3cCs5tjtƒ\}}tjddjtƒ|ƒdS(NsCommand: %s Output%st (RtsubptCMD_PROBE_FLOPPYR R/tjoin(toutt_err((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyR<scCstj|tƒS(N(Rtlist_from_dependst datasources(tdepends((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pytget_datasource_lists(t__doc__R@R$tos.patht cloudinitRtloggingRRtcloudinit.utilRt getLoggerRMR R'RRRDRRRR<tDEP_FILESYSTEMt DEP_NETWORKRWRY(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyt s(      "¼