
    x[h!                         S r SSKrSSKrSSKrSSKrSSKJrJrJrJ	r	  \R                  " \5      rSrSS/r0 SS0 S	.rS
 r " S S\R"                  5      rS r\\R(                  \R*                  44/rS rg)zb
This file contains code used to gather the user data passed to an
instance on RHEVm and vSphere.
    N)dmisourcessubputilz/etc/sysconfig/cloud-infomodprobefloppyi  	localhost)zblock-device-mappingzinstance-idzlocal-hostname	placementc                 (   U S-   nU S-   n [         R                  " U5      R                  5       nU$ ! [         aU     [         R                  " U5      R                  5       n U$ ! [         a    [         R                  " [
        S5          gf = ff = f)aB  
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_text_filestripIOErrorlogexcLOG)	mount_dirdeltacloud_user_data_fileuser_data_file	user_datas       F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAltCloud.pyread_user_data_callbackr   &   s    $ !*,G G!11N''(ABHHJ	   	++N;AACI
 	  	KK?@	s&   $2 
B$A$$%B	BBBc                   b   ^  \ rS rSrSrS rS\SS4U 4S jjrS rS	 r	S
 r
S rS rS rSrU =r$ )DataSourceAltCloudH   AltCloudc                     [         R                  R                  XX#5        S U l        SU l        [         R
                  U l        g )N)/zfile://)r   
DataSource__init__seedsupported_seed_startsMETADATA_UNKNOWNsource)selfsys_cfgdistropathss       r   r   DataSourceAltCloud.__init__L   s4    ##D6A	%5"..    ci_pkl_versionreturnNc                 r   > [         TU ]  U5        [        U S5      (       d  [        R                  U l        g g )Nr"   )super	_unpicklehasattrr   r!   r"   )r#   r)   	__class__s     r   r-   DataSourceAltCloud._unpickleR   s/    .)tX&&!22DK 'r(   c                 h    [         R                  R                  U 5      nU< SU R                  < S3$ )Nz [seed=])r   r   __str__r   )r#   roots     r   r3   DataSourceAltCloud.__str__W   s'    !!))$/!%tyy11r(   c                    [         R                  R                  [        5      (       a9   [        R
                  " [        5      R                  5       R                  5       nU$ [        R                  " S5      nU(       d  gUR                  5       nUR                  S5      (       a  gUR                  S5      (       a  gg! [         a#    [        R                  " [        S[        5         gf = f)a  
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.UNKNOWNzsystem-product-nameRHEVVMWAREVSPHERE)ospathexistsCLOUD_INFO_FILEr   r   r   upperr   r   r   r   read_dmi_data
startswith)r#   
cloud_typesystem_namesys_names       r   get_cloud_type!DataSourceAltCloud.get_cloud_type[   s      77>>/**
!''8>>@FFH  ''(=>$$&v&&x(()  !=#
 !!s   6B? ?*C,+C,c                 8   [         R                  S5        U R                  5       n[         R                  S[        U5      5        SU;   a  U R	                  5       (       a  gOSU;   a  U R                  5       (       a  gOg[        R                  " [         S5        g)a4  
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.
zInvoked get_data()zcloud_type: %sr8   Tr:   FzFailed accessing user data.)r   debugrE   struser_data_rhevmuser_data_vspherer   r   r#   rB   s     r   	_get_dataDataSourceAltCloud._get_data   s    $ 			&'((*
		"C
O4Z##%% &*$%%'' (
  	C67r(   c                     U R                  5       nUS:X  a  SU l        UR                  5       < SU R                  < S3$ )z(Return the subplatform metadata details.r8   /dev/fd0z ())rE   r"   lowerrL   s     r   _get_subplatform#DataSourceAltCloud._get_subplatform   s7    ((*
$DK&,,.<<r(   c                    Sn [        5         Sn [        R                  " USS9   [        R                  " U[        5      nXl        [        U l        U(       a  g	g! [        R                   a&  n[        R                  " [
        SU5         SnAgSnAff = f! [        R                  [        4 a&  n[        R                  " [
        SU5         SnAgSnAff = f! [         a)  nUR                  [        R                  :w  a  e  SnANSnAf[        R                   a    [        R                  " [
        SU5         Nf = f)
ag  
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>
NzFailed modprobe: %sFrP      )r=   timeoutzFailed udevadm_settle: %s
-Failed to mount %s when looking for user dataT)modprobe_floppyr   ProcessExecutionErrorr   r   r   udevadm_settleOSErrormount_cbr   errnoENOENTMountFailedErroruserdata_rawMETA_DATA_NOT_SUPPORTEDmetadata)r#   
return_stre
floppy_deverrs        r   rJ   "DataSourceAltCloud.user_data_rhevm   s     
	
  
	z1=

	z3JKJ '/? )) 	KK2A6	 **G4 	KK:A>	  	yyELL( )$$ 	KK?	sK   
A B C B0BBC3CC
E &D

3E ?E c                    Sn[         R                  " S5      nU H.  n [         R                  " U[        5      nU(       a  X0l          OM0     Xl        [        U l        U(       a  gg! [
         a*  nUR                  [        R                  :w  a  e  SnAM{  SnAf[         R                   a     [         R                  " [        SU5         M  f = f)aR  
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>
NzLABEL=CDROMrX   TF)r   find_devs_withr]   r   r"   r\   r^   r_   r`   r   r   ra   rb   rc   )r#   rd   
cdrom_list	cdrom_devrg   s        r   rK   $DataSourceAltCloud.user_data_vsphere   s     
((7
#I!]]96MN
"+K  $  '/!  99, -(( Cs   (A''
C1B3CC)rc   r   r"   r    ra   )__name__
__module____qualname____firstlineno__dsnamer   intr-   r3   rE   rM   rS   rJ   rK   __static_attributes____classcell__)r/   s   @r   r   r   H   sF    F/3 3 3
2)V%N=4l& &r(   r   c                      [         R                   " [        5      u  p[        R                  SSR	                  [        5      U 5        g )NzCommand: %s
Output%s )r   CMD_PROBE_FLOPPYr   rH   join)out_errs     r   rY   rY     s.    		*+ICII%sxx0@'A3Gr(   c                 8    [         R                  " U [        5      $ )N)r   list_from_dependsdatasources)dependss    r   get_datasource_listr   "  s    $$Wk::r(   )__doc__r^   loggingr;   os.path	cloudinitr   r   r   r   	getLoggerrn   r   r>   rx   rb   r   r   r   rY   DEP_FILESYSTEMDEP_NETWORKr~   r    r(   r   <module>r      s   
   	  . .! . )  !	 DH++ HVH '00'2E2EFG;r(   