oB]c@sddlmZddlZddlZddlmZddlmZmZmZddl m Z m Z m Z m Z ddlmZddlmZddlmZejeZd efd YZd efd YZd efdYZdefdYZdZdefdYZdefdYZdefdYZdefdYZ defdYZ!defdYZ"dZ#dS(i(ttimeN(tStringIO(tNoSectionErrort NoOptionErrortRawConfigParser(t PER_INSTANCEt PER_ALWAYStPER_ONCEt CFG_ENV_NAME(tlog(t type_utils(tutilt LockFailurecBseZRS((t__name__t __module__(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR st DummyLockcBseZRS((R R(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR"stDummySemaphorescBsAeZdZejedZdZdZdZ RS(cCsdS(N((tself((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt__init__'sccs tVdS(N(R(Rt_namet_freqt_clear_on_fail((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pytlock*scCstS(N(tFalse(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pythas_run.scCstS(N(tTrue(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pytclear1scCsdS(N((R((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt clear_all4s( R RRt contextlibtcontextmanagerRRRRR(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR&s    tFileLockcBseZdZdZRS(cCs ||_dS(N(tfn(RR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR9scCsdtj||jfS(Ns<%s using file %r>(R tobj_nameR(R((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt__str__<s(R RRR!(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR8s cCs|jddS(Nt-t_(treplace(tname((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pytcanon_sem_name@stFileSemaphorescBsSeZdZejedZdZdZdZ dZ dZ RS(cCs ||_dS(N(tsem_path(RR(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyREsccsUt|}y|j||VWn-tk rP|rJ|j||nnXdS(N(R&t_acquiret ExceptionR(RR%tfreqt clear_on_fail((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRHs  cCsat|}|j||}ytj|Wn+ttfk r\tjtd|tSXt S(NsFailed deleting semaphore %s( R&t _get_pathR tdel_filetIOErrortOSErrortlogexctLOGRR(RR%R+tsem_file((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRRs cCsHytj|jWn-ttfk rCtjtd|jnXdS(Ns&Failed deleting semaphore directory %s(R tdel_dirR(R/R0R1R2(R((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR\s  cCs|j||rdS|j||}dtjtf}ytj||Wn+tt fk rtj t d|dSXt |S(Ns%s: %s s Failed writing semaphore file %s( RtNoneR-tostgetpidRR t write_fileR/R0R1R2R(RR%R+R3tcontents((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR)cscCs| s|tkrtSt|}|j||}tjj|rKtS||krtjj|j||rtj d||tStS(Ns%s has run without canonicalized name [%s]. likely the migrator has not yet run. It will run next boot. run manually with: cloud-init single --name=migrator( RRR&R-R6tpathtexistsRR2twarning(RR%R+tcnameR3((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRss *  cCsP|j}| s|tkr/tjj||Stjj|d||fSdS(Ns%s.%s(R(RR6R:tjoin(RR%R+R(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR-s ( R RRRRRRRRR)RR-(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR'Ds    tRunnerscBs)eZdZdZdedZRS(cCs||_i|_dS(N(tpathstsems(RR@((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRs cCs|tks| rdSd}|tkr>|jjd}n!|tkr_|jjd}n|sidS||jkrt||j|t instance_linkt boot_finishedtupstart_conf_dtseed_dirt template_tpltlookupsRU(Rt path_cfgstdst template_dir((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR?s6  cCs|j|j|S(N(R-R(RR%((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyReascCs|j|j|S(N(R-R(RR%((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRDfscCs|js dS|jj}|dkr,dSt|jtjd}tjj|j d|}|j j |}|rtjj||}n|S(NR#t instances( RUR5tget_instance_idtstrR$R6tsepR:R>RRR(RR%tiidt path_safe_iidtipathtadd_on((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt _get_ipathks  cCs.|j|}|s&tjddS|SdS(Ns?No per instance data available, is there an datasource/iid set?(RR2R<R5(RR%R((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRC{s  cCs*|dkr|Stjj||j|S(N(R5R6R:R>R(RtbaseR%((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR-s cCs|j|j|S(N(R-R(RR%((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt get_runpathsN( R RR5RReRDRRCR-R(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR>s "    tDefaultingConfigParsercBseeZdZdZeZd ZdZd dZ dZ dZ dZ dZ d dZRS( igcCsJ|j}ytj|||}Wn!tk r5ntk rEnX|S(N(tDEF_BASERRRR(Rtsectiontoptiontvalue((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRs   cCsL|j| r2|jdkr2|j|ntj||||dS(Ntdefault(t has_sectiontlowert add_sectionRR~(RRRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyR~s"cCs,|j||r(tj|||ndS(N(t has_optionRt remove_option(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRscCs,|j||s|jStj|||S(N(Rt DEF_BOOLEANRt getboolean(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRscCs,|j||s|jStj|||S(N(Rt DEF_FLOATRtgetfloat(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRscCs,|j||s|jStj|||S(N(RtDEF_INTRtgetint(RRR((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRscCsWd}t}|j||j|j}|rSdj||dg}n|S(Nts (RtwritetflushtgetvalueR>(RtheaderR9t outputstream((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt stringifys    N(R RRRRRR5RRR~RRRRR(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyRs     cCs|S(N((tobject((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pytidentitys($RRR6tsixRtsix.moves.configparserRRRtcloudinit.settingsRRRRt cloudinitR tloggingR R t getLoggerR R2R*R RRRRR&R'R?RNRtRRR(((s5/usr/lib/python2.7/site-packages/cloudinit/helpers.pyt s*  " N-[$X3