Viewing File: /usr/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(fdYZ)de)fdYZ*dZ+ddddZ,e-e.e/dZ0e/e/e/dZ1dZ2dZ3dZ4dZ5e-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
DataSourceOVFcBsSeZdZdZdZdZdZdZdZe	dZ
RS(tOVFcCstjj||||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}	|	dkrntjdn|rtj	j
|jj|}
t|\}}}||_|j
|
nH|	rd|	jkrtjd|jstjdqtj|jd	tsd8}d}
d}x7|D]/}t||
}|r,tjd|Pq,q,W|rt|j}tjdtjdddtdd|f}n
tjd|rtjd|tdddddd}qtjdqtjdn|rd|_y*t|}t||_t|j\}}}t||_tj	j|}|jj}t |tj	j
|jj!d }|o|}|jj"}t#t$t%d!}|jd"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|ryt1||}|j2Wqt-k
r}t.d'|t/j0|qXqny2tjd(t3|jtt|j4j5|_6Wn)t-k
r"}t.d)|t/j7|nX|rtjd*t8}|jj9}yB|jj:}|sf|r|j;|||j4n
tjd+Wn)t-k
r}t.d,|t/j0|nX|ry t<|||}|j2Wqt-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@|jt&t'jAt)jBn|d0tCfd1tDfg} d}!x'| D]\}!}"|"}|rPqqW|r:t|\}}}||_|j
|!ntE|d2krPtFSd3|kr|d3r|d3}#tF}$x*|jGD]}%|#jH|%r|%}$PqqW|$stjd4|#|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
	
	
			
		!
	

	


	
	 	


			
	
			cCs7tjdj}|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|tr3|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,RRRRtpropertyR(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR5s	
					tDataSourceOVFNetcBseZdZRS(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	(RRR(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRJscCsd}d}|}|s|Syt|j||}Wn$tk
r^tjd||nX|dkrtjd||||}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
		
	iis/var/run/vmware-imccCsld}x_||krgtjj||}tjj|r@|Stjdtj|||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|jS(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|d6nidd6|d6S(Nt
nameserverttypetaddresstsearchitversionR(RE(RtnameserversRtconfig_list((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRs
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(RRqRRr((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRMs			
c	Cst|}i}i}d}dg}ddddg}x|jD]\}}|dkrgd}n||kr|||<qF||kr|||<qF|dkrFytj|j}Wqtk
r|j}qXqFqFW|||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.pyRDs&		


cCsd}x||D]t}tjj||}tjj|r
ytj|}||fSWqtk
r}tjtd|qXq
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(RRRRRt	load_fileRYtlogexcRBRR&(RNt	env_namestfnametfull_fnRw((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR@s

cCs|s
tSt|tjs/td|ntjj|}|jdrf|j	dd}n|jdr|j
dd}n|jddkrtS|stSd}tjj
d|}tj|}|j|dk	S(	sTest 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/iRis^(sr[0-9]+|hd[a-z]|xvd.*)tCLOUD_INIT_CDROM_DEV_REGEXN(R&Rtsixtstring_typesRRRtnormpathRkt	partitiontsplittcounttenvironRtretcompiletmatchR(tdevnamet
default_regext
devname_regextcdmatch((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pytmaybe_cdrom_devices"c
CsMtj}xz|jD]l\}}|d}|dkrG|rGqnt|sYqn|d}t|\}}|tk	r|SqW|rd}nd}gtj|rd|ndD]}t|r|^q}	xj|	D]b}y"tj|td|\}}Wn'tj	k
r4t
jd|qnX|tk	r|SqWdS(Ntfstypetiso9660t
mountpointsTYPE=%stmtypes%s not mountable as iso9660(RtmountsRRR@R&Rtfind_devs_withtmount_cbtMountFailedErrorRBRC(
trequire_isoRtdevtinfoRtmpt_fnameRwRtdevs((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRis4

	#
"cCsd}d}tj|s|S|dg}y6tj|\}}|rM|Stjd||WnKtjk
r}|jdkrtjd||jtj|qnX|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}|js|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	Cstj|}|jjdkr0tdn|jjsNtdnd}t|jd}t|dkrtdni}t|dd}xH|D]@}|jj	|d	j
}|jj	|d
j
}|||<qW|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(RtparseStringtdocumentElementRtXmlErrorRRRjt
attributestgetNamedItemNSR(	RwtdomtenvNsURItpropSectionsRt	propElemstelemRR((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyR.s$	

cCsX|s|rdSx?tj|D].\}}}||kr"tjj||Sq"WdS(N(RRtwalkRR(RR5R-t_dirstfiles((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRHMsRcBseZRS((RR(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRXscCstj|tS(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	cCstjdtjj|d|d}xEtj|D]4}|jdr:tjtjj||q:q:Wt	|dj
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.pyRZs(Dtxml.domRRRRRRt	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	getLoggerRRBRSRTRRRRIRLR!R&RR^RRMRDR@RRiRhRRRHRYRtDEP_FILESYSTEMtDEP_NETWORKRRRPRdRZ(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt<module>sZ"	
				
	)%		
					
Back to Directory File Manager