Current File : //lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyc
�
oB�]c@sdZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
eje�Z
dZdd	gZiid
6dd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�sinstance-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|Stjd�}|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
RRt
read_dmi_datat
startswith(Rt
cloud_typetsystem_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}yt�Wn'tk
r:}tjtd|�tSXd}ytjd|dd�Wn-ttfk
r�}tjtd|�tSXytj	|t
�}WnQtk
r�}|jtj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 <user_data_file>
         To access it:
           modprobe floppy

           Leverage util.mount_cb to:
               mkdir <tmp mount dir>
               mount /dev/fd0 <tmp mount dir>
               The call back passed to util.mount_cb will do:
                   read <tmp mount dir>/<user_data_file>
        sFailed modprobe: %ss/dev/fd0R&ttimeoutisFailed udevadm_settle: %s
s-Failed to mount %s when looking for user dataN(R
tmodprobe_floppyRRRR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
td|�qXqW||_t
|_|r�tStSdS(s�
        vSphere specific userdata read

        If on vSphere the user data will be contained on the
        cdrom device in file <user_data_file>
        To access it:
           Leverage util.mount_cb to:
               mkdir <tmp mount dir>
               mount /dev/fd0 <tmp mount dir>
               The call back passed to util.mount_cb will do:
                   read <tmp mount dir>/<user_data_file>
        sLABEL=CDROMs-Failed to mount %s when looking for user dataN(R
Rtfind_devs_withR?RR6R>R@RARBRR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_dependstdatasources(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_FILESYSTEMtDEP_NETWORKRWRY(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAltCloud.pyt<module>
s(
	"�