Current File : //lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyo
�
oB�]c@siddlmZddlZddlZddlZddlZddlZddlmZ	ddlm
Z
ddlmZddlm
Z
ddlmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZm Z m!Z!m"Z"e	j#e$�Z%dZ&dZ'de
j(fd��YZ)de)fd��YZ*d�Z+dddd�Z,e-e.e/d�Z0e/e/e/d�Z1d�Z2d�Z3d�Z4d�Z5e-d �Z6d!�Z7d"�Z8d#�Z9d$�Z:d%e;fd&��YZ<e)e
j=ffe*e
j=e
j>fffZ?d'�Z@d(�ZAd)�ZBd*�ZCdS(+i����(tminidomN(tlog(tsources(tutil(tConfig(tPreCustomScripttPostCustomScript(t
ConfigFile(tNicConfigurator(tPasswordConfigurator(tGuestCustErrorEnum(tGuestCustEventEnum(tGuestCustStateEnum(tenable_nicstget_nics_to_enabletset_customization_statustget_tools_configt	deployPkgsenable-custom-scriptst
DataSourceOVFcBsSeZdZd�Zd�Zd�Zd�Zd�Zd�Ze	d��Z
RS(tOVFcCs�tjj||||�d|_tjj|jd�|_d|_	i|_
d|_t|_
d|_d|_d|_t|_dS(Ntovft/sfile://(Rsfile://(Rt
DataSourcet__init__tNonetseedtostpathtjointseed_dirtenvironmenttcfgtsupported_seed_startstTruetvmware_customization_supportedt_network_configt_vmware_nics_to_enablet_vmware_cust_conftFalset_vmware_cust_found(tselftsys_cfgtdistrotpaths((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR9s								cCs#tjj|�}d||jfS(Ns%s [seed=%s](RRt__str__R(R(troot((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR,Fsc'CsVg}i}d}d}d}idd6}t|jj�\}}tjd�}	|	dkrntjd�n|r�tj	j
|jj|�}
t|�\}}}||_|j
|
�nH|	rd|	j�krtjd�|js�tjd�qtj|jd	t�s�d8}d}
d}x7|D]/}t||
�}|r,tjd|�Pq,q,W|r�t|j�}tjdtjdddtdd|f�}n
tjd�|r�tjd|�tdddddd�}qtjd�qtjd�n|r�d|_y*t|�}t|�|_t|j�\}}}t|�|_tj	j|�}|jj}t |tj	j
|jj!d ��}|o�|}|jj"}t#t$t%d!�}|j�d"kr|r|rd#}tj|�t&t'j(t)j*�t+|��qntj	j
|jj,d$�d%�}Wn)t-k
ri}t.d&|t/j0|�nX|r�|r�yt1||�}|j2�Wq�t-k
r�}t.d'|t/j0|�q�Xq�ny2tjd(�t3|jtt|j4j5�|_6Wn)t-k
r"}t.d)|t/j7|�nX|rtjd*�t8�}|jj9}yB|jj:}|sf|r|j;|||j4�n
tjd+�Wn)t-k
r�}t.d,|t/j0|�nX|ry t<|||�}|j2�Wqt-k
r
}t.d-|t/j0|�qXqn|rly&t=|tj	j
|jj!d ��Wqlt-k
rh}t.d.|t/j0|�qlXnt|_>|j
d/�tj?tj	j|��t@|j�t&t'jAt)jB�n|d0tCfd1tDfg} d}!x'| D]\}!}"|"�}|r�Pq�q�W|r:t|�\}}}||_|j
|!�ntE|�d2krPtFSd3|kr|d3r|d3}#tF}$x*|jGD]}%|#jH|%�r�|%}$Pq�q�W|$s�tjd4|#|�tFStjI|#d5d�\}&}tjd6|#�tjJ||&g�}|j
|#�ntjJ||g�}d7j
|�|_K||_L||_M||_NtS(9Nts	iid-dsovfsinstance-idssystem-product-namesNo system-product-name foundtvmwares$VMware Virtualization Platform founds3Skipping the check for VMware Customization supporttdisable_vmware_customizations/usr/lib/vmware-toolss/usr/lib64/vmware-toolss/usr/lib/open-vm-toolss/usr/lib64/open-vm-toolsslibdeployPkgPlugin.sos$Found the customization plugin at %stlogfunctmsgswaiting for configuration filetfunctargsscust.cfgs&Did not find the customization plugin.s,Found VMware Customization Config File at %stfilenamesnics.txttmaxwaiti
tnaplenis-Did not find VMware Customization Config Files.Customization for VMware platform is disabled.tdatatfalsettrues-Custom script is disabled by VM Administratortscriptssper-instances+Error parsing the customization Config Files(Error executing pre-customization scripts#Preparing the Network configurations%Error preparing Network ConfigurationsApplying password customizationsChanging password is not neededs%Error applying Password Configurations)Error executing post-customization scriptsError creating marker filessvmware-toolsscom.vmware.guestInfotisoitseedfroms Seed from %s not supported by %sttimeoutsUsing seeded cache data from %st,(s/usr/lib/vmware-toolss/usr/lib64/vmware-toolss/usr/lib/open-vm-toolss/usr/lib64/open-vm-tools(ORtget_ovf_envR+RRt
read_dmi_datatLOGtdebugRRRtread_ovf_environmentRtappendtlowerR"tget_cfg_option_boolR)R!tsearch_filetget_max_wait_from_cfgtds_cfgtlog_timetwait_for_imc_cfg_fileR$RRR%tread_vmware_imcRtdirnamet	marker_idtcheck_marker_existst	cloud_dirtcustom_script_nameRt CONFGROUPNAME_GUESTCUSTOMIZATIONt&GUESTCUSTOMIZATION_ENABLE_CUST_SCRIPTSRRtGUESTCUST_STATE_RUNNINGR
tGUESTCUST_ERROR_SCRIPT_DISABLEDtRuntimeErrort	get_cpatht	Exceptiont_raise_error_statustGuestCustEventt GUESTCUST_EVENT_CUSTOMIZE_FAILEDRtexecutetget_network_config_from_confR*tosfamilyR#t$GUESTCUST_EVENT_NETWORK_SETUP_FAILEDR	tadmin_passwordtreset_passwordt	configureRtsetup_marker_filesR'tdel_dirR
tGUESTCUST_STATE_DONEtGUESTCUST_ERROR_SUCCESSttransport_vmware_guestinfottransport_iso9660tlenR&R t
startswithtread_seededt
mergemanydictRtmetadatatuserdata_rawR('R(tfoundtmdtudtvmwareImcConfigFilePathtnicspathtdefaultstseedfiletcontentstsystem_typeRRtsearch_pathstplugintdeployPkgPluginPathRtmax_waittcft
imcdirpathtproduct_markert
hasmarkerfiletspecial_customizationtcustomscripttcustScriptConfigR2tccScriptsDirtetprecusttpwdConfiguratortadminpwdtresetpwdtpostcusttnptnamet	transfuncR=t	seedfoundtprototmd_seed((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt	_get_dataJsr
	
	
			
		!
	

	


	
	 	


			
	
			cCs7tjd�j�}|dkr,d|jSd|jS(Nssystem-product-nameR/svmware (%s)sovf (%s)(RRARFR(R(Rx((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt_get_subplatform0scCs>d|jkrgS|jd}t|t�r3|S|gSdS(Nspublic-keys(Rnt
isinstancetlist(R(tpks((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytget_public_ssh_keys6s
cCs|jS(N(R(R(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytget_config_objBscCs|jS(N(R#(R(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytnetwork_configEs(t__name__t
__module__tdsnameRR,R�R�R�R�tpropertyR�(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR5s	
		�			tDataSourceOVFNetcBseZd�ZRS(cCsGtj||||�tjj|jd�|_d|_t|_dS(Nsovf-netshttp://shttps://sftp://(shttp://shttps://sftp://(	RRRRRRR R&R"(R(R)R*R+((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRKs	(R�R�R(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR�JscCs�d}d}|}|s|Syt|j||��}Wn$tk
r^tjd||�nX|dkr�tjd|||�|}n|S(NiZtvmware_cust_file_max_waitsFailed to get '%s', using %sis/Invalid value '%s' for '%s', using '%s' instead(tinttgett
ValueErrorRBtwarning(Rtdefault_max_waittmax_wait_cfg_optionR|((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRIRs
		
	i�is/var/run/vmware-imccCsld}x_||krgtjj||�}tjj|�r@|Stjd�tj|�||7}q	WdS(Nis,Waiting for VMware Customization Config File(	RRRtisfileRBRCttimetsleepR(R5R6R7tdirpathtwaitedtfileFullPath((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRLhs

cCs:t|j|�}|j||�}t||j|j�S(N(Rtnicstgeneratetget_network_configtname_serverstdns_suffixes(tconfigtuse_system_devicesRcR_tnicConfiguratort
nics_cfg_list((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR^vs
cCsI|}|s|r7|jidd6|d6|d6�nidd6|d6S(Nt
nameserverttypetaddresstsearchitversionR�(RE(R�tnameserversR�tconfig_list((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR��s
cCsi}i}d}|jrO|jr?|jd|j|d<qO|j|d<n|jrh|j|d<nd|d<|||fS(Nt.slocal-hostnamettimezonesiid-vmware-imcsinstance-id(Rt	host_nametdomain_nameR�(R�RqRRr((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRM�s			
c	Cs�t|�}i}i}d}dg}ddddg}x�|j�D]�\}}|dkrgd}n||kr�|||<qF||kr�|||<qF|dkrFytj|j��}Wq�tk
r�|j�}q�XqFqFW|||fS(NtpasswordR=slocal-hostnamespublic-keyssinstance-idthostnames	user-data(tget_propertiesRtitemstbase64t	b64decodetencodeRY(	RwtpropsRqRRrt	cfg_propstmd_propstproptval((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRD�s&		


cCs�d}x||D]t}tjj||�}tjj|�r
ytj|�}||fSWq�tk
r}tjtd|�q�Xq
q
Wdt
fS(Nsovf-env.xmlsovf_env.xmlsOVF_ENV.XMLsOVF-ENV.XMLsFailed loading ovf file %s(sovf-env.xmlsovf_env.xmlsOVF_ENV.XMLsOVF-ENV.XML(RRRR�Rt	load_fileRYtlogexcRBRR&(RNt	env_namestfnametfull_fnRw((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR@�s

cCs�|s
tSt|tj�s/td|��ntjj|�}|jd�rf|j	d�d}n|jd�r�|j
d�d}n|jd�dkr�tS|s�tSd}tjj
d|�}tj|�}|j|�dk	S(	s�Test if devname matches known list of devices which may contain iso9660
       filesystems.

    Be helpful in accepting either knames (with no leading /dev/) or full path
    names, but do not allow paths outside of /dev/, like /dev/foo/bar/xxx.
    s Unexpected input for devname: %ss/dev/i����Ris^(sr[0-9]+|hd[a-z]|xvd.*)tCLOUD_INIT_CDROM_DEV_REGEXN(R&R�tsixtstring_typesR�RRtnormpathRkt	partitiontsplittcounttenvironR�tretcompiletmatchR(tdevnamet
default_regext
devname_regextcdmatch((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytmaybe_cdrom_device�s"c
CsMtj�}xz|j�D]l\}}|d}|dkrG|rGqnt|�sYqn|d}t|�\}}|tk	r|SqW|r�d}nd}gtj|r�d|nd�D]}t|�r�|^q�}	xj|	D]b}y"tj|td|�\}}Wn'tj	k
r4t
jd|�q�nX|tk	r�|Sq�WdS(Ntfstypetiso9660t
mountpointsTYPE=%stmtypes%s not mountable as iso9660(RtmountsR�R�R@R&Rtfind_devs_withtmount_cbtMountFailedErrorRBRC(
trequire_isoR�tdevtinfoR�tmpt_fnameRwR�tdevs((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRi�s4

	#
"cCs�d}d}tj|�s|S|dg}y6tj|�\}}|rM|Stjd||�WnKtjk
r�}|jdkr�tjd||j�tj|�q�nX|S(Nsvmware-rpctoolsinfo-get guestinfo.ovfEnvs%cmd %s exited 0 with empty stdout: %sis%s exited with code %d(	RRtwhichtsubpRBRCtProcessExecutionErrort	exit_codeR�(trpctoolt	not_foundtcmdtoutt_errR�((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRhscCsJg}|j�s|Sx-|jD]"}||�r |j|�q q W|S(N(t
hasChildNodest
childNodesRE(tnodetfilter_functrettchild((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt
find_child$sc	Cs�tj|�}|jjdkr0td��n|jj�sNtd��nd}t|jd��}t|�dkr�td��ni}t|dd��}xH|D]@}|jj	|d	�j
}|jj	|d
�j
}|||<q�W|S(NtEnvironmentsNo Environment NodesNo Child Nodess)http://schemas.dmtf.org/ovf/environment/1cSs
|jdkS(NtPropertySection(t	localName(tn((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt<lambda><sisNo 'PropertySection'scSs
|jdkS(NtProperty(R(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRCstkeytvalue(RtparseStringtdocumentElementRtXmlErrorR�R�Rjt
attributestgetNamedItemNSR(	RwtdomtenvNsURItpropSectionsR�t	propElemstelemRR�((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR�.s$	

cCsX|s|rdSx?tj|�D].\}}}||kr"tjj||�Sq"WdS(N(RRtwalkRR(R�R5R-t_dirstfiles((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRHMsRcBseZRS((R�R�(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRXscCstj|t�S(N(Rtlist_from_dependstdatasources(tdepends((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytget_datasource_listdscCsA|s
tStjj|d|d�}tjj|�r=tStS(sg
    Check the existence of a marker file.
    Presence of marker file determines whether a certain code path is to be
    executed. It is needed for partial guest customization in VMware.
    @param markerid: is an unique string representing a particular product
                     marker.
    @param: marker_dir: The directory in which markers exist.
    s.markerfile-s.txt(R&RRRtexistsR!(tmarkeridt
marker_dirt
markerfile((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRPis	cCs�tjd�tjj|d|d�}xEtj|�D]4}|jd�r:tjtjj||��q:q:Wt	|d�j
�dS(s"
    Create a new marker file.
    Marker files are unique to a full customization workflow in VMware
    environment.
    @param markerid: is an unique string representing a particular product
                     marker.
    @param: marker_dir: The directory in which markers exist.

    sHandle marker creations.markerfile-s.txts.markerfiletwN(RBRCRRRtlistdirRkRtdel_filetopentclose(RRRR�((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRd{s

#cCsFtjd||�ttj|�tjtjj	|��|�dS(s�
    Raise error and send customization status to the underlying VMware
    Virtualization Platform. Also, cleanup the imc directory.
    s%s: %sN(
RBRCRRRURReRRRN(tprefixterrorteventtconfig_file((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRZ�s(Dtxml.domRR�RR�R�R�t	cloudinitRtloggingRRt+cloudinit.sources.helpers.vmware.imc.configRt9cloudinit.sources.helpers.vmware.imc.config_custom_scriptRRt0cloudinit.sources.helpers.vmware.imc.config_fileRt/cloudinit.sources.helpers.vmware.imc.config_nicRt2cloudinit.sources.helpers.vmware.imc.config_passwdR	t4cloudinit.sources.helpers.vmware.imc.guestcust_errorR
t4cloudinit.sources.helpers.vmware.imc.guestcust_eventRR[t4cloudinit.sources.helpers.vmware.imc.guestcust_stateRt3cloudinit.sources.helpers.vmware.imc.guestcust_utilR
RRRt	getLoggerR�RBRSRTRRR�RIRLR!R&RR^R�RMRDR@R�RiRhR�R�RHRYRtDEP_FILESYSTEMtDEP_NETWORKRRRPRdRZ(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt<module>sZ"�	
				
	)%