oB]c@siddlmZddlZddlZddlZddlZddlZddlmZ ddlm Z ddlm Z ddl m Z ddlmZmZddlmZdd lmZdd lmZdd lmZdd 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(t enable_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_dirt environmenttcfgtsupported_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-dsovfs instance-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(ORt get_ovf_envR+RRt read_dmi_datatLOGtdebugRRRtread_ovf_environmentRtappendtlowerR"tget_cfg_option_boolR)R!t search_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 startswitht read_seededt mergemanydictRtmetadatat userdata_rawR('R(tfoundtmdtudtvmwareImcConfigFilePathtnicspathtdefaultstseedfiletcontentst system_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/s vmware (%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(Ns public-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(Rt nameserversRt config_list((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRs  cCsi}i}d}|jrO|jr?|jd|j|d<sisNo 'PropertySection'scSs |jdkS(NtProperty(R(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyRCstkeytvalue( Rt parseStringtdocumentElementRtXmlErrorRRRjt 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_dependst datasources(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(tprefixterrorteventt config_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_eventR R[t4cloudinit.sources.helpers.vmware.imc.guestcust_stateR t3cloudinit.sources.helpers.vmware.imc.guestcust_utilR RRRt getLoggerRRBRSRTRRRRIRLR!R&RR^RRMRDR@RRiRhRRRHRYRtDEP_FILESYSTEMt DEP_NETWORKRRRPRdRZ(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOVF.pyt sZ     "      ) %