Viewing File: /usr/lib/python2.7/site-packages/cloudinit/util.pyo


jbc@s
ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZ
ddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZmZddlmZ ddl!Z!ddl"m#Z#ddl"m$Z%ddl"m&Z&ddl"m'Z'dd	l"m(Z(dd
l"m)Z)ddl"m*Z*ddl"m+Z+dd
l,m-Z-yddl.m/Z/Wne0k
rdZ/nXda2e%j3e4Z5ide
j66Z7dej8ej9Z:dZ;dZ<dddgdgdgfZ=e/ddZ>e/dd Z?dd!Z@dd"ZAd#d$ZBd#d%ZCd&ZDd'ZEd(ZFd)ZGid*d+6d,d-6d.d/6d0d16d2d36d4d56d6d76d8d96d:d;6d<d=6d>d?6d@dA6dBdC6dDdE6dFdG6dHdI6dJdK6ZHdLeIfdMYZJdNeKfdOYZLdPeMfdQYZNdReMfdSYZOdTZPddUZQddVZRddWZSdXddYZTddZZUd[ZVd\ZWd]ZXd^ZYeZeZd_Z[d`Z\daZ]eZeZde%j^dbZ_dcZ`e/ddZaebdeZcddfZddgdhZeddiZfe/djZge/dkZhddlZiddmZjdnZkdddoZlddpdpdpdpdqZmebdrZnejodsZpejodtZqduZrdvZseZddwZtdpdpdxdyZuddzZvdewfd{Zxdpdpdxd|dgd}Zyd~ZzdZ{ddZ|ddZ}dZ~ebdZddZdZdZdZdZdZdZdddebddZdebdZdZdZdebeZdZe/dZdZdddZdddZdddZdZdZdZddZdZdZdZddZewfdZdZdZdZddZejodZdZddddZdZdZebdZdZdZdZdZdZddZdZdZddebdZdZdZdddeZebebebdddddZdddZdZeZdZdddZdZdZd#ddZdZdZdZe5ebdZdZdZdZdZdZdZe5ebdZdZdddZddebdZdZdde
jj6dZdebdZdZdZdZddZdZdZddZdZdZdZebddZddpdZdZdddZdZdS(iN(tENOENTtENOEXEC(t	b64decodet	b64encode(tparse(timporter(tlog(tmergers(tsafeyaml(t
temp_utils(t
type_utils(t
url_helper(tversion(tCFG_BUILTIN(t	lru_cachecCs
d}|S(s+pass-thru replace for Python3's lru_cache()cSs|S(N((tf((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytwrapper:s((R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR8s	t_s_-.()ttruet1tontyestofft0tnotfalsessystemd-detect-virts--quiets--containersrunning-in-containerslxc-is-containercCs.tddgdtd|\}}|jS(Ntdpkgs--print-architecturetcapturettarget(tsubptTruetstrip(RtoutR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_architectureRscCs;idd6dd6dd6dd6}i}ytd	d
gdtd|\}}xO|jD]A}|jd
\}}}||kr\|j|||<q\q\Wg|jD]}||kr|^q}	t|	rtjddj	|	nWn?t
k
r6}
tjd|
td|jD}nX|S(NtcodenametCodenametdescriptiontDescriptiontidsDistributor IDtreleasetReleasetlsb_releases--allRRt:s.Missing fields in lsb_release --all output: %st,s#Unable to get lsb_release --all: %scss|]}|dfVqdS(tUNAVAILABLEN((t.0tv((s2/usr/lib/python2.7/site-packages/cloudinit/util.pys	<genexpr>ls(RRt
splitlinest	partitionRtvaluestlentLOGtwarningtjointProcessExecutionErrortdict(RtfmaptdataR Rtlinetfnametvaltktmissingterr((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_lsb_releaseYs"$+	 cCs#t|dkrt|StS(Nt/(ttarget_pathR@(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR)qs
cCs|dkrd}nSt|tjs:td|n.tjj|}|jdrh|d}n|sr|Sx*t	|r|ddkr|d}quWtjj
||S(NtRAsUnexpected input for target: %ss//ii(NRC(tNonet
isinstancetsixtstring_typest
ValueErrortostpathtabspatht
startswithR2R5(RRJ((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRBys	
sutf-8cCs#t|tjr|S|j|S(N(RERFRGtdecode(tblobtencoding((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
decode_binaryscCs#t|tjr|S|j|S(N(RERFtbinary_typetencode(ttextRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytencode_textscCs6t|}y|jdSWntk
r1|SXdS(Nsutf-8(RRMtUnicodeDecodeError(tsourcetdecoded((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytb64ds

cCs4t|ts!|jd}nt|jdS(Nsutf-8(REtbytesRRRRM(RV((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytb64escCs}|jdt}tjry|jdkryt|try|j}|rc|jrc|j}nd}|j	|dS|S(NRMRSsutf-8tsurrogateescape(
tget_payloadRRFtPY3tget_content_maintypeRERYtget_charsettinput_codecRM(tparttcte_payloadtcharsetRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfully_decoded_payloads	s/sys/class/dmi/idtboard_asset_tagsbaseboard-asset-tagtboard_vendorsbaseboard-manufacturert
board_namesbaseboard-product-nametboard_serialsbaseboard-serial-numbert
board_versionsbaseboard-versiont	bios_datesbios-release-datetbios_vendorsbios-vendortbios_versionsbios-versiontchassis_asset_tagschassis-asset-tagtchassis_vendorschassis-manufacturertchassis_serialschassis-serial-numbertchassis_versionschassis-versiont
sys_vendorssystem-manufacturertproduct_namessystem-product-nametproduct_serialssystem-serial-numbertproduct_uuidssystem-uuidtproduct_versionssystem-versionR6cBsGeZdZdZddddddddZdZddZRS(sr%(description)s
Command: %(cmd)s
Exit code: %(exit_code)s
Reason: %(reason)s
Stdout: %(stdout)s
Stderr: %(stderr)st-c	Cs|s|j|_n	||_|sO|rC|tkrCd|_qXd|_n	||_t|tjsy|j|_n	||_|s|dkr|j|_	q||_	n|j
||_	|s|dkr|j|_q||_n|j
||_|r||_n|j|_||_
|ji|j|jd6|j|jd6|j|jd6|j|jd6|j|j	d6|j|jd6}tj||dS(	Ns(Exec format error. Missing #! in script?s'Unexpected error while running command.R$tcmdt	exit_codetstdouttstderrtreason(t
empty_attrRwRR$RERFt
integer_typesRxRDRzt_indent_textRyR{terrnotMESSAGE_TMPLt_ensure_stringtIOErrort__init__(	tselfRyRzRxRwR$R{Rtmessage((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRsB					cCs t|tjr|jS|S(s1
        if data is bytes object, decode
        (RERFRQRM(RRS((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRsicCsZd}d|}t|tjr=|j}|j}n|j|j|||S(sY
        indent text on all but the first line, allowing for easy to read output
        s
t (RERFRQRRtrstriptreplace(RRStindent_leveltcrtindent((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR~"s
N(t__name__t
__module__RR|RDRRR~(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR6s3	tSeLinuxGuardcBs&eZedZdZdZRS(cCsIytjd|_Wntk
r2d|_nX||_||_dS(Ntselinux(Rt
import_moduleRtImportErrorRDRJt	recursive(RRJR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR2s

	cCs$|jr|jjrtStSdS(N(Rtis_selinux_enabledRtFalse(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	__enter__<scCs|js|jjrdStjj|js7dStjj|j}tjrdt|}ny-tj	|}|jj
||tjWnt
k
rdSXtjd||jy|jj|d|jWn,t
k
r}tjd||j|nXdS(Ns,Restoring selinux mode for %s (recursive=%s)Rs,restorecon failed on %s,%s maybe badness? %s(RRRIRJtlexiststrealpathRFtPY2tstrtlstattmatchpathcontstattST_MODEtOSErrorR3tdebugRt
restoreconR4(Rt	excp_typet
excp_valuetexcp_tracebackRJtstatste((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt__exit__Bs&	
	
	(RRRRRR(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR1s
	tMountFailedErrorcBseZRS((RR(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR[stDecompressionErrorcBseZRS((RR(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR_scOstj}|dkrsy|||tjdWqtk
rottdtj|tjdqXntjd|tj|dS(Nis&Failed forking and calling callback %sis(Forked child %s who will run callback %s(	RItforkt_exitt	ExceptiontlogexcR3R
tobj_nameR(tchild_cbtargstkwargstfid((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfork_cbcs

		cCsat|tr|tkSt}|r8t||}ntj|jj|kr]tSt	S(N(
REtboolRtTRUE_STRINGStlistRFt	text_typetlowerRR(R<taddonst	check_set((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_truers
!cCsat|tr|tkSt}|r8t||}ntj|jj|kr]t	StS(N(
RERRt
FALSE_STRINGSRRFRRRR(R<RR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_false}s
!cCs*|s
tSt|tr|St||S(N(RRERR(R<R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyttranslate_bools
i cCsWtj}|s%tjtj}ndjgtd|D]}|j|^q;S(NRCi(trandomtSystemRandomtstringt
ascii_letterstdigitsR5trangetchoice(tstrlentselect_fromtrt_x((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytrand_strscCsG|sd}nx1trBtddd|}||krPqqW|S(NRCRiR(RR(t
dictionarytpostfixtnewkey((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
rand_dict_keys		cCsJytt|diSWn)tk
rE}|jtkr?iSnXdS(Ntdefault(t	load_yamlt	load_fileRRR(R;R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	read_confscGstt|S(N(tsortedt
uniq_merge(tlists((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytuniq_merge_sortedscGs}g}xj|D]b}t|tjrb|jjd}g|D]}t|rA|^qA}n|j|q
Wt|S(NR+(RERFRGRtsplitR2textendt	uniq_list(Rt
combined_listta_listta((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs
(cCsx,tjD]\}}|j||}q
Wg}x*|D]"}|tkr<|j|q<q<Wx |D]}|j|d}qiW|j}|S(NRC(tFN_REPLACEMENTStitemsRt
FN_ALLOWEDtappendR(tfnR=R.tremovals((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytclean_filenames

cCsyctjt|}tjtjddd|'}|rRt|j	S|j	SWdQXWn2t
k
r}|r|Sttj|nXdS(Ntrbi(
RFtBytesIORTt
contextlibtclosingtgziptGzipFileRDRPtreadRRR(R9tquietRMtbuftghR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdecomp_gzips$cCs|s
dS|jdd}|dj}t|dkrQ|dj}nd}|s||dks||jdkrd}n|s|dks|jdkrd}n||fS(NR*iiis-1tnone(NN(RDRRR2R(tug_pairt	ug_partedtutg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytextract_usergroups%	%	cCst}xtjtjj|dD]k}tjj|sFq(ntjj|dd!}|j}|r(|jddkr(|||<q(q(W|S(Ns*.pyiit.i(	R7tglobRIRJR5tisfiletbasenameRtfind(troot_dirtentriesR;tmodname((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_moduless	%cCs|rtjj|n|r|d}tjj|rit|d}|j||jWdQXq|tjj|n|r|ddkr|j	||d q|j	||ndS(Ns/dev/consoletwis
(
tsysRztwriteRIRJtexiststopentflushRyR(RStconsoleRzRt	log_leveltconpathtwfh((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	multi_logs

cCs|jd}t|dkr%tSy?g|D].}dt|koRdknr/|^q/}Wntk
rxtSXt|dkS(s<determine if input string is a ipv4 address. return boolean.Riii(RR2RtintR(tinstrttokstx((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_ipv4s?
cCstddkS(Ntvarianttfreebsd(tsystem_info(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
is_FreeBSD*scCs||kr|St||S(N(R(tyobjtkeyR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_option_bool/scCs?||kr|S||}t|tjs;t|}n|S(N(RERFRGR(RRRR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_option_str5s
icCstt||d|S(NR(RR(RRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_option_int>scCs|sd}ntjj|s%iSt|}d}tj||}|r|j}|djjdd|d<|ddkrd|d<ni|dd6|d	d
6|dd6SiS(
sReturn a dictionary of distro info fields from /etc/redhat-release.

    Dict keys will align with /etc/os-release keys:
        ID, VERSION_ID, VERSION_CODENAME
    s/etc/redhat-releasesA(?P<name>.+) release (?P<version>[\d\.]+) \((?P<codename>[^)]+)\)tnames linuxisred hat enterprisetredhattIDRt
VERSION_IDR"tVERSION_CODENAME(	RIRJRRtretmatcht	groupdictRR0(trelease_filetredhat_releasetredhat_regexRtgroup((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_parse_redhat_releaseBs	!
c	Csd}d}d}i}tjjdr?ttd}n|sQt}n|r|jdd}|jdd}d|ksd|krtj}nR|jdd}|st	j
d|jd	d}|r|jd
}qn|dkrd}qntjjd
rKd}tddg\}}|j
}nrd}z(ytj}Wntk
rwnXWdd}x|D]}|rd}qqW|stjdnX|S|||fS(NRCs/etc/os-releaseRRtslestsuseRs[^ ]+ \((?P<codename>[^)]+)\)tVERSIONR"trhelRs/bin/freebsd-versionRtunames-risPUnable to determine distribution, template expansion may have unexpected results(RCRCRC(RIRJRtload_shell_contentRR"tgettplatformtmachineRRRRRtdistRRDR3R4(	tdistro_nametdistro_versiontflavort
os_releaseRRR,tfoundtentry((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_linux_distro\sN	


cCsitjd6tjd6tjd6tjd6tjd6td6}|dj}d}|dkr|dd	j}|dkr|}q|dkrd}q|dkrd}q|dkrd}qd}n|dkr|}n||d<|S( NR*tsystemR'tpythonR'R,tunknowntlinuxitarchtcentostdebiantfedoraR&R$tubuntut	linuxminttmintRtopensusesopensuse-tumbleweeds
opensuse-leapR#twindowstdarwinRR
(R8R9R:R;srhelssuse(R<R=R>(R?sopensuse-tumbleweeds
opensuse-leapssles(R@sdarwinsfreebsd(R*R4R'tpython_versionR'R3R(tinfoR4tvart
linux_dist((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs4





								
cCs||kr|S||dkr$gS||}t|trZg|D]}|^qD}|St|tjs{t|}n|gS(s
    Gets the C{key} config option from C{yobj} as a list of strings. If the
    key is present as a single string it will be returned as a list with one
    string arg.

    @param yobj: The configuration object.
    @param key: The configuration key to get.
    @param default: The default to return if key is not found.
    @return: The configuration option as a list of strings or default if key
        is not found.
    N(RDRERRFRGR(RRRR<R.tcval((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_option_lists
cCsYt|tjr$|jd}n|}x(|D] }||krG|S||}q1W|S(sReturn the value of the item at path C{keyp} in C{yobj}.

    example:
      get_cfg_by_path({'a': {'b': {'num': 4}}}, 'a/b/num') == 4
      get_cfg_by_path({'a': {'b': {'num': 4}}}, 'c/d') == None

    @param yobj: A dictionary.
    @param keyp: A path inside yobj.  it can be a '/' delimited string,
                 or an iterable.
    @param default: The default to return if the path does not exist.
    @return: The value of the item at keyp."
        is not found.RA(RERFRGR(RtkeypRtcurttok((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_by_paths
cCs,t||\}}t||||fS(N(tget_output_cfgtredirect_output(tcfgtmodetoutfmtterrfmt((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfixup_outputs
c	CsXttjjdr)tjddS|s;tj}n|sMtj}n|rptjd|||j	dd\}}|dks|dkrd}|dkrd	}nt
||}nF|d
krtj|dt
dtj}|j}ntd
||r.tj|j|jn||krptjd||tj|j|jdSn|rTtjd|||j	dd\}}|dks|dkrd}|dkrd	}nt
||}nF|d
krtj|dt
dtj}|j}ntd||rTtj|j|jqTndS(Nt_CLOUD_INIT_SAVE_STDOUTs5Not redirecting output due to _CLOUD_INIT_SAVE_STDOUTsRedirecting %s to %sRit>s>>tabtwbt|tshelltstdins"Invalid type for output format: %ss!Invalid type for error format: %s(RRItenvironR)R3RRRyRzRRt
subprocesstPopenRtPIPERYt	TypeErrortdup2tfileno(	RPRQto_outto_errROtargtowithtnew_fptproc((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRMsN
		RCc	Cs|p	dg}d}|r*t|}n|dk	rK|dd|7}n|j|pZd|j|pmd|j|pd|j|pd|j|pdtj|S(NRCR*s%s(RRDRturlparset
urlunparse(	tschemethosttportRJtparamstquerytfragmenttpiecestnetloc((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmake_url+scCs~|rt|}ni}x\|D]T}|r"tj|}|sRtj}ntj|}|j||}q"q"W|S(N(treversedRtdict_extract_mergerstdefault_mergerst	constructtmerge(tsrcstreverset
merged_cfgRNtmergers_to_applytmerger((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
mergemanydict@s
ccs7tj}ztj||VWdtj|XdS(N(RItgetcwdtchdir(tndirtcurr((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR~Os

	ccs-tj|}z	|VWdtj|XdS(N(RItumask(tn_msktold((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRYs	cCsdj|d|ddd|S(Ns{0:{fill}{align}{size}}tfilltalignt^tsize(tformat(RSRtmax_len((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytcenterbscCs!tjd|tj|dS(NsRecursively deleting %s(R3Rtshutiltrmtree(RJ((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdel_dirgsc	Csx|rtjj|rdSg}g}|dkr>g}nEt|tr_t|g}n$t|trw|}ntdxttj	|D]}tjj
||}tjj|rtj|tj
r|j|yt||gdtWq?tk
r;}ttd||j|j|q?XqqW|rt|rttdt|t|fndS(Ns%exe_prefix must be None, str, or listRsFailed running %s [%s]s.Runparts: %s failures in %s attempted commands(RIRJtisdirRDRERRR^RtlistdirR5RtaccesstX_OKRRRR6RR3RxtRuntimeErrorR2(	tdirpt
skip_no_existt
exe_prefixtfailedt	attemptedtprefixtexe_nametexe_pathR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytrunpartsls.		'
icCsjy4t|||\}}||d<||d<tSWn/tjk
re}|jtjkr_tSnXdS(Ns	user-datas	meta-data(tread_seededRRtUrlErrortcodet	NOT_FOUNDR(RtbasetextttimeouttmdtudR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_optional_seeds

cCswi}ddg}|r^|jtjj|jddtjj|jddgnt|}g|D]$}|rqtjj|rq|^qq}d}xH|D]@}tjj	tjj|drtjj|d}PqqWd}xH|D]@}tjj	tjj|drtjj|d}PqqW|r`|r`||d<||d<n|rs||d<n|S(	Ns/var/lib/cloud/data/ssls /var/lib/cloud/instance/data/sslR9tsslscert.pemskey.pemt	cert_filetkey_file(
RRIRJR5t
get_ipath_curt	get_cpathRRRDR(tpathstssl_detailstssl_cert_pathstdRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfetch_ssl_detailss2	%1
!
!


c
Cs|}t|}ytjdt||tj|}|dkr_tjd|}n1t||std|t	j
|fn|}Wntjttfk
r}d}d}t
|drt|drt|d}n0t
|dr!t|dr!t|d}n|rZ|djd|jd	d
|jd	d|7}n|djd|7}tj|nX|S(
NsKAttempting to load yaml from string of length %s with allowed root types %ss-loaded blob returned None, returning default.s2Yaml load allows %s root types, but got %s insteadsFailed loading yaml blobtcontext_marktproblem_marks5. Invalid format at line {line} column {col}: "{err}"R:itcolR?s. {err}(RPR3RR2RtloadRDRER^R
Rt	YAMLErrorRHthasattrtgetattrRR:tcolumnR4(RNRtallowedtloadedt	convertedRtmsgtmark((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs6	
	
	'i
cCs|jddkr4|d|}|d|}n&d|d|f}d|d|f}tj|d|d|}d}|jrtt|jdi}ntj|d|d|}	d}
|	jr|	j}
n||
fS(	Ns%sis	user-datas	meta-datas%s%s%sRtretriesR(RRtread_file_or_urlRDtokRRPtcontents(RRRRtfile_retriestud_urltmd_urltmd_respRtud_respR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs 		cCsttj|dt}g|D]}|jdr"|^q"}g|D]-}tjjtjj||rJ|^qJ}g}x0|D](}|jt	tjj||qWt
|S(NRxs.cfg(RRIRRtendswithRJRR5RRR|(tconfdtconfsRtcfgsR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_conf_ds(
-
&cCst|}t}d|krz|d}|rt|tjsbtd|tj|fqwt|j	}qn#t
jjd|rd|}n|st
jj|r|St
|}t||gS(Ntconf_ds8Config file %s contains 'conf_d' with non-string type %ss%s.d(RRRERFRGR^R
RRRRIRJRRR|(tcfgfileRNRt	confd_cfg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_conf_with_confds

cCsttd|S(Ntcmdline(Rtread_cc_from_cmdline(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_conf_from_cmdlinesc	Cs|dkrt}nd}d}t|}t|}t|}g}|j|}x{|dkr|j|||}|dkr|}n|j||||!jjdd|j|||}q`Wdj|S(Nscc:tend_ccis\ns
(RDtget_cmdlineR2RRtlstripRR5(	Rt	tag_beginttag_endtbegin_ltend_ltclenttokenstbegintend((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR$s"		 
cCsC|jd}|dks/||ddkr3|S|jddS(Ns
iis
s
(RR(Rtpos((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdos2unixCs cCsd|kr8|d}t|d|jdd}nd|kr|djddkr|d}|d|jd }nC|jdtd|}d|kr|d}n|jd|}||fS(sGet hostname and fqdn from config if present and fallback to cloud.

    @param cfg: Dictionary of merged user-data configuration (from init.cfg).
    @param cloud: Cloud instance from init.cloudify().
    @param metadata_only: Boolean, set True to only query cloud meta-data,
        returning None if not present in meta-data.
    @return: a Tuple of strings <hostname>, <fqdn>. Values can be none when
        metadata_only is True and no cfg or metadata provides hostname info.
    tfqdnthostnameRit
metadata_only(RRRtget_hostnameR(RNtcloudRRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_hostname_fqdnKs

"%

s
/etc/hostscCsd}yxt|jD]}|jd}|dkrM|d|!}n|j}|seqn|j}t|dkrqn||dkr|d}PqqWWntk
rnX|S(s
    For each host a single line should be present with
      the following information:

        IP_address canonical_hostname [aliases...]

      Fields of the entry are separated by any number of  blanks  and/or  tab
      characters.  Text  from a "#" character until the end of the line is a
      comment, and is ignored. Host  names  may  contain  only  alphanumeric
      characters, minus signs ("-"), and periods (".").  They must begin with
      an  alphabetic  character  and  end  with  an  alphanumeric  character.
      Optional aliases provide for name changes, alternate spellings, shorter
      hostnames, or generic hostnames (for example, localhost).
    t#iiiiN(RDRR/RRRR2R(RtfilenameRR:thashposR
((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_fqdn_from_hostsjs$

cCsWtdkrt}d	}i}x|D]}ytj|dddtjtj}g||<xM|D]E\}}}}	}
||jd|	|
df|j|
dqfWWq(tj	tj
fk
rq(Xq(W|a|rtjd|qny<tj|d}|ddd}|tkr-t
StSWntj	tj
fk
rRt
SXdS(
sdetermine if a url is resolvable, return a boolean
    This also attempts to be resilent against dns redirection.

    Note, that normal nsswitch resolution is used here.  So in order
    to avoid any utilization of 'search' entries in /etc/resolv.conf
    we have to append '.'.

    The top level 'invalid' domain is invalid per RFC.  And example.com
    should also not exist.  The '__cloud_init_expected_not_found__' entry will
    be resolved inside the search list.
    sdoes-not-exist.example.com.sexample.invalid.t!__cloud_init_expected_not_found__is%s: %ssdetected dns redirection: %siN(sdoes-not-exist.example.com.sexample.invalid.R(t_DNS_REDIRECT_IPRDtsettsockettgetaddrinfotSOCK_STREAMtAI_CANONNAMERtaddtgaierrorterrorR3RRR(Rtbadipstbadnamest
badresultstinametresultt_famt_stypet_prototcnametsockaddrtaddr((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
is_resolvables6
	

cCstj}|S(N(Rtgethostname(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRscCs1ytj|dSWntjk
r,dSXdS(Ni(Rt
gethostbyaddrtherrorRD(tip((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRsc
Cs5tdtjdd|dtdtj|jfS(s5determine if this url is resolvable (existing or ip).tlogfuncRsResolving URL: tfuncR(tlog_timeR3RRRgR(turl((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_resolvable_urlscCs=x6|D].}yt|r |SWqtk
r4qXqWdS(sc
    Search through a list of mirror urls for one that works
    This needs to return quickly.
    N(RRRD(t
candidatestcand((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsearch_for_mirrors

cCsWttjjdrdSttj&}tj|jtj	jWdQXdS(s
    reopen stdin as /dev/null so even subprocesses or other os level things get
    /dev/null as input.

    if _CLOUD_INIT_SAVE_STDIN is set in environment to a non empty and true
    value then input will not be closed (useful for debugging).
    t_CLOUD_INIT_SAVE_STDINN(
RRIRZR)RtdevnullR_R`RRY(tfp((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytclose_stdinstdevicec
Cs/dg}g}|r)|jd|n|rC|jd|n|r_|jddgn|ry|jd|n|r|j|n||}y"t|ddd	g\}}	Wn.tk
r}
|
jtkrd
}qnXg}x6|jD](}|j}|r|j|qqW|S(s
    find devices matching given criteria (via blkid)
    criteria can be *one* of:
      TYPE=<filesystem>
      LABEL=<label>
      UUID=<uuid>
    tblkids-t%ss-s%ss-cs	/dev/nulls-o%strcsiiRC(RRRR6RRR/R(
tcriteriatoformatttagtno_cacheRJt
blk_id_cmdtoptionsRwR t_errRRR:((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_devs_withs2		
"	c	Cs|dkrg}nt|}dddg}|rL|jddgn|j|t|dtdd\}}i}xJ|jD]<}|jd	\}}}t|||<|||d
<qW|S(sGet all device tags details from blkid.

    @param devs: Optional list of device paths you wish to query.
    @param disable_cache: Bool, set True to start with clean cache.

    @return: Dict of key value pairs of info for the device.
    Rs-otfulls-cs	/dev/nullRRMRR*tDEVNAMEN(RDRRRRR/R0R((	tdevst
disable_cacheRwR RtretR:tdevR9((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR!s	
cCs<tjd||t|d}|j|SWdQXdS(NsPeeking at %s (max_bytes=%s)R(R3RRR(R;t	max_bytestifh((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	peek_file@scCs:g}x-|D]%}||kr%q
q
|j|q
W|S(N(R(tin_listtout_listti((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRFs
c	Cstjd||tj}y/t|d}t||d|WdQXWn4tk
r}|sln|jtkrqnX|j	}tjdt
|||rt|S|SdS(NsReading from %s (quiet=%s)Rtchunk_cbsRead %s bytes from %s(R3RRFRRtpipe_in_outRRRtgetvalueR2RP(R;tread_cbRRMtofhR!RR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRPs

cCstr^y&td}|jddd }Wqtk
rZ}tjd|d}qXn0ytdj}Wntk
rd}nX|S(Ns/proc/1/cmdlinetRis"failed reading /proc/1/cmdline: %sRCs
/proc/cmdline(tis_containerRRRR3R4R(RRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_get_cmdlinecs	


cCs!dtjkrtjdStS(NtDEBUG_PROC_CMDLINE(RIRZR-(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRvsicCsvd}x_trg|j|}t|dkr4Pq	|j||t|7}|r	||q	q	W|j|S(Ni(RRR2RR(tin_fhtout_fht
chunk_sizeR&tbytes_pipedR9((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR'}s	

cCsI|dkr|dkrdStjd|||tj|||dS(Nis%Changing the ownership of %s to %s:%s(Ni(Ni(RDR3RRItchown(R;tuidtgid((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	chownbyidscCsd}d}y:|r*tj|j}n|rEtj|j}nWn#tk
rk}td|nXt|||dS(NisUnknown user or group: %s(	tpwdtgetpwnamtpw_uidtgrptgetgrnamtgr_gidtKeyErrorRR6(R;tuserR!R4R5R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytchownbynamesc
Csddg}|sd|kr#|S|d}||krF||}nd|krV|S|d}t|tr~||g}nt|trt|dkr|d|d<nt|dkr|d|d<qnt|tr"d|kr|d|d<nd|kr"|d|d<q"n|ddkrC|d|d<nddd	g}xtt|D]}||s{qen||j}t}xG|D]?}	|j	|	rd
|	|t|	j
f}t}PqqW|sd
d|j
f}n|||<qeW|S(NtoutputtalliiRs&1s>>RTRWs%s %s(RDRERRR2R7RRRRLRR(
RNRORtoutcfgtmodecfgtswlistR%R<R1ts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRLsL




 cCsg}|st|tr!|S|jd}|rF|j|nxt|dD]}|shqVntjd|}|sqVn|jd}|j	}t
|dkr|j|qVddg|d krV|j|dqVqVWtt|S(	sReturn a list of log file paths from the configuration dictionary.

    @param cfg: The cloud-init merged configuration dictionary.
    tdef_log_files (?P<type>\||>+)\s*(?P<target>.*)Rittees-aiN(
RER7R)RRLRDRRR!RR2RR(RNtlogstdefault_logtfmtRRtparts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_config_logfiless&cGsT|r|j||ntj}|dkr:d}n|j|d||dS(Ntexc_info(NNN(R4RRMRDR(RRRRM((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs	cCsMtj|}|jt||j}|dk	rE|d|!S|SdS(Ni(thashlibtnewtupdateRTt	hexdigestRD(RNtroutinetmlenthashertdigest((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	hash_blobscCs0ytj|rtSWntk
r+tSXdS(N(R7R8RR=R(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_users

cCs0ytj|rtSWntk
r+tSXdS(N(R:R;RR=R(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_group#s

cCs'tjd||tj||dS(NsRenaming %s to %s(R3RRItrename(tsrctdest((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRY+sicCs"x|D]}t||qWdS(N(t
ensure_dir(tdirlistROR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytensure_dirs1s
cCsutjt|}t|t|sqdjg|D]}t|^q7}td|t|fn|S(Ns, s((%s) root types expected, got %s instead(	tjsontloadsRPREttupleR5RR^ttype(RSt
root_typesRWtttexpected_types((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	load_json6s(cCs?ydjt|SWn!tk
r:djt|SXdS(s1Handler for types which aren't json serializable.s
ci-b64:{0}s)Warning: redacted unserializable type {0}N(RRZtAttributeErrorRb(t_obj((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytjson_serialize_default?s
cCs}tj|}xg|jD]Y\}}t|trJt|||<nt|trdjt|||<qqW|S(sPreserialize any discovered binary values to avoid json.dumps issues.

    Used only on python 2.7 where default type handling is not honored for
    failure to encode binary data. LP: #1801364.
    TODO(Drop this function when py2.7 support is dropped from cloud-init)
    s
ci-b64:{0}(	tobj_copytdeepcopyRRER7tjson_preserialize_binaryRYRRZ(R9Rtvalue((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRlGs c
Cspy)tj|dddtdddtSWn@tk
rktjd dkret|}tj|SnXd
S(
s%Return data in nicely formatted json.Rit	sort_keyst
separatorsR+s: RiiN(R+s: (ii(R_tdumpsRRiRURtversion_infoRl(R9((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
json_dumpsWs

cCsetjj|sTttjj|dttj|WdQXt||n
t||dS(NR(RIRJRRtdirnameRtmakedirstchmod(RJRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR\ds
ccs0z	|VWd|r+d|g}t|nXdS(Ntumount(R(Rvt
umount_cmd((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	unmounteros
	cCswi}yFtjjdr6tdj}d}n$td\}}|j}d}d}x|D]}y|dkr|j\}}}	}
}}nNtj||}
|
j	d}|
j	d}|
j	d}	|
j	d}
Wnt
k
rqgnX|jd	d
}i|	d6|d6|
d
6||<qgWtj
d||Wn$ttfk
rrttdnX|S(Ns/proc/mountsRftmounts*^(/dev/[\S]+) on (/.*) \((.+), .+, (.+)\)$iiiis\040Rtfstypet
mountpointtoptssFetched %s mounts from %ssFailed fetching mount points(RIRJRRR/RRRtsearchR!RRR3RRRR(tmountedt
mount_locstmethodtmountoutputRtmountretmplineRtmpRzR|t_freqt_passnotm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmountsys:	
!
cCst|tr|g}nWt|ttfr?t|}n3|dkrTd}ntdjdt|tj	j
}|dkr|dkrdg}qno|jdr|dkrdddg}nx?t|D]%\}}|d	krd||<qqWn	d
g}t
}tj|}	t}
tjj||krm|tjj|d}nd}x|D]}d}yfdd
dg}
|r|
jd|gn|
j||
j|	t|
d||	}
|	}PWqzttfk
r#}tjd||||}qzXqzW|sJtd||	|fn|jdsf|d7}nt|
3|dkr||}n|||}|SWdQXWdQXdS(s2
    Mount the device, call method 'callback' passing the directory
    in which it was mounted, then unmount.  Return whatever 'callback'
    returned.  If data != None, also pass data to callback.

    mtype is a filesystem type.  it may be a list, string (a single fsname)
    or a list of fsnames.
    s6Unsupported type provided for mtype parameter: {_type}t_typeR7tautotbsdtufstcd9660tvfattiso9660RCR{Rys-otros-tt
update_envs Failed mount of '%s' as '%s': %ss#Failed mounting %s to %s due to: %sRAN(RERRRaRDR^RRbR*R4RRt	enumerateRR	ttempdirRRIRJRRRRRRR3RRRx(RtcallbackR9tmtypetupdate_env_for_mounttmtypestplatsystindexR~ttmpdRvR{tfailure_reasontmountcmdtexcR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmount_cbsh				


	


cCs
tjtS(N(RjRkR
(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_builtin_cfgscCs tjd|tjj|S(NsTesting if a link exists for %s(R3RRIRJtislink(RJ((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_linkscCsLtjd|||r8tjj|r8t|ntj||dS(Ns$Creating symbolic link from %r => %r(R3RRIRJRtdel_filetsymlink(RVtlinktforce((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsym_links
cCsStjd|ytj|Wn+tk
rN}|jtkrO|qOnXdS(NsAttempting to remove %s(R3RRItunlinkRRR(RJR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRscCs'tjd||tj||dS(NsCopying %s to %s(R3RRtcopy(RZR[((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRscCs:ytjdtj}Wntk
r5d}nX|S(Ns%a, %d %b %Y %H:%M:%S %zs??(ttimetstrftimetgmtimeR(tts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyttime_rfc2822s


cCsd}d}ytjjdrOd}td}|r|jd}qnd}tjd}tj}tj}tj	||_
|jdtj|tj|ddtj}|j
}||}Wn"tk
rttd|nX|S(	Ns??R6s/proc/uptimeitctypess/lib/libc.so.7s
kern.boottimes&Unable to read uptime using method: %s(RIRJRRRRtCDLLtc_size_ttc_inttsizeofRmtsysctlbynametbyrefRDRRRR3(t
uptime_strRRtlibcRRtnowtbootup((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytuptimes*	
cCst||dddddS(NtomodeRURO(t
write_fileRD(RJtcontent((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytappend_file-sicCs t|ddddd|dS(NRRCRRURO(R(RJRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytensure_file1scCs-yt|SWnttfk
r(dSXdS(N(RRHR^RD(tpossible_int((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsafe_int5scCsBt|}|r>|r>t|tj||WdQXndS(N(RRRIRu(RJROt	real_mode((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRu<s
RVc	
Cs5|rBy%tj|}tj|j}WqBtk
r>qBXnttjj|d|jkrt	|}d}nt
|}d}yd|}Wntk
rd|}nXtj
d|||t||td|4t||}|j||jWdQXWdQXt||dS(	sv
    Writes a file with the given content and sets the file mode as specified.
    Restores the SELinux context if possible.

    @param filename: The full path of the file to write.
    @param content: The content to write to the file.
    @param mode: The filesystem mode to set on the file.
    @param omode: The open mode used when opening the file (w, wb, a, etc.)
    tbRYt
characterss%os%rsWriting to %s - %s: [%s] %s %sRJN(RIRtS_IMODEtst_modeRR\RJRsRRTRPR^R3RR2RRRRRu(	RRRORt	copy_modet	file_statt
write_typetmode_rtfh((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRCs.
	
	
cCs\xUtj|D]D}tjj||}tjj|rJt|qt|qWdS(s
    Deletes all contents of a directory without deleting the directory itself.

    @param dirname: The directory whose contents should be deleted.
    N(RIRRJR5RRR(Rstnodet
node_fullpath((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdelete_dir_contentsis

c
Os|jdd}t|dkr?d|kr?tg}ntjdt}tjj||}d|kr|gt	|d|d<n!t	|}|g|d|d<t
||ddt||SWdQXdS(	sWrite blob to a tempfile, and call subp with args, kwargs. Then cleanup.

    'basename' as a kwarg allows providing the basename for the file.
    The 'args' argument to subp will be updated with the full path to the
    filename as the first argument.
    Rt	subp_blobiRt	needs_exeROiN(tpopR2RaR	RRRIRJR5RRR(RNRRRRttmpf((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsubp_blob_in_tempfilewsRcs|	dk	rtdn|dkr3dg}nd}|
rs|dkrWtj}n|j}|j|
nt|	dkrd|	gt|}n|rt|trdj	|n|}
|dj
d|
n|stjd||||rd	n|ntjd
|d}d}d}|rLt
j}t
j}n|rgt
j}t
j}n|dkrttj}|}n't
j}t|ts|j}nt|tjr|}n^t|tjr|jd}n:g|D]-}t|tjr|n|jd^q}zyFt
j|d|d
|d|d|d|}|j|\}}Wnhtk
r}|r|dntd|d|d|jdrdndd
rdndnXWd|r|jnX|s|r$|sd}n|s$d}q$nrWdfd}||}||}n|j}||kr|r|dj
d|ntd|d
|d|d|n|r|dj
d|n||fS(sRun a subprocess.

    :param args: command to run in a list. [cmd, arg1, arg2...]
    :param data: input to the command, made available on its stdin.
    :param rcs:
        a list of allowed return codes.  If subprocess exits with a value not
        in this list, a ProcessExecutionError will be raised.  By default,
        data is returned as a string.  See 'decode' parameter.
    :param env: a dictionary for the command's environment.
    :param capture:
        boolean indicating if output should be captured.  If True, then stderr
        and stdout will be returned.  If False, they will not be redirected.
    :param combine_capture:
        boolean indicating if stderr should be redirected to stdout. When True,
        interleaved stderr and stdout will be returned as the first element of
        a tuple, the second will be empty string or bytes (per decode).
        if combine_capture is True, then output is captured independent of
        the value of capture.
    :param shell: boolean indicating if this should be run with a shell.
    :param logstring:
        the command will be logged to DEBUG.  If it contains info that should
        not be logged, then logstring will be logged instead.
    :param decode:
        if False, no decoding will be done and returned stdout and stderr will
        be bytes.  Other allowed values are 'strict', 'ignore', and 'replace'.
        These values are passed through to bytes().decode() as the 'errors'
        parameter.  There is no support for decoding to other than utf-8.
    :param target:
        not supported, kwarg present only to make function signature similar
        to curtin's subp.
    :param update_env:
        update the enviornment for this command with this dictionary.
        this will not affect the current processes os.environ.
    :param status_cb:
        call this fuction with a single string argument before starting
        and after finishing.

    :return
        if not capturing, return is (None, None)
        if capturing, stdout and stderr are returned.
            if decode:
                entries in tuple will be python2 unicode or python3 string
            if not decode:
                entries in tuple will be python2 string or python3 bytes
    s&target arg not supported by cloud-initiRAtchrootRsBegin run command: {command}
tcommandsFRunning command %s with allowed return codes %s (shell=%s, capture=%s)tcombinesFRunning hidden command to protect sensitive input/output logstring: %ssutf-8RyRzRYtenvRXs1ERROR: End run command: invalid command provided
RwR{RRvNRCcs#t|ts|S|j|S(N(RERYRM(R9R(RM(s2/usr/lib/python2.7/site-packages/cloudinit/util.pytldecodess%ERROR: End run command: exit({code})
RRxsEnd run command: exit({code})
(RDRHRIRZRRPRBRRER5RR3RR[R]tSTDOUTRRRYRRRFRQRGR\tcommunicateRR6Rtcloset
returncode(RR9RRRtcombine_captureRXt	logstringRMRRt	status_cbt
devnull_fpRRYRyRzt
bytes_argsRtspR R?RRtrc((RMs2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs4$							7
		RtcreatedcCsGtj}t|}|d|j|f7}|dt7}|S(Ns %s by cloud-init v. %ss on %s(Rtversion_stringRttitleR(tcomment_charRtci_vertheader((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmake_header*s
cGstjjtjj|S(N(RIRJRKR5(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytabs_join2scCsEt|ttfs1tdtj|nd}|rJ|d7}ndd}d}x|D]}t|ttfrg}x4|D],}|jdtj|j	d|qWd	|d
j
|f}|d7}qat|tjrd	||f}|d7}qatdtj||fqaWtj
d
||S(Ns8Input to shellify was type '%s'. Expected list or tuple.RCs
#!/bin/sh
s%s%s%s%st's\is'%s's%s%s
RisCUnable to shellify type '%s'. Expected list, string, tuple. Got: %ssShellified %s commands.(Rs\RR(RERaRR^R
RRRFRRR5RGR3R(tcmdlistt
add_headerRtescapedt	cmds_madeRtfixedR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytshellify:s0



*

cCsU|r(|j|r(|t|}n|rQ|j|rQ|t| }n|S(N(RLR2R(R:Rtsuffix((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytstrip_prefix_suffixZs
cCs5x:tD]2}yt|tSWqttfk
r8qXqWy0td}d|kr\tSd|krltSWnttfk
rnXtjjdrtjjdrtSygt	dj
}xN|D]F}|jdr|jj
dd\}}|d	krtSqqWWnttfk
r0nXtS(
sH
    Checks to see if this code running in a container of some sort
    it	containertLIBVIRT_LXC_UUIDs/proc/vzs/proc/bcs/proc/self/statussVxID:R*R(tCONTAINER_TESTSRRRRtget_proc_envRIRJRRR/RLRRR(thelpertpid1envtlinesR:t_keyR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR,bs4

%
cCstjjdS(s2Check to see if we are running in a lxd container.s
/dev/lxd/sock(RIRJR(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_lxdscCstjjdt|d}yt|dt}Wnttfk
rNiSXi}d\}}|rd\}}|j||}nxN|j	|D]=}|sqn|j	|d\}	}
|	r|
||	<qqW|S(	sH
    Return the environment in a dict that a given process id was started with.

    @param encoding: if true, then decoding will be done with
                     .decode(encoding, errors) and text will be returned.
                     if false then binary will be returned.
    @param errors:   only used if encoding is true.s/procRZRMR+t=i(sR(sR(
RIRJR5RRRRRRMR(tpidROterrorsRRRtnulltequalRJRR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRs"cCsgi}xZ|jD]L}y|jdd\}}Wntk
rT|}t}nX|||<qW|S(NRi(RRHR(tkvstringRRJRR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytkeyval_str_to_dicts

cCs0|jdr|d}ntjjd|S(Ns/dev/is/sys/class/block/%s/partition(RLRIRJR(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_partitions
cCst|ts|g}ng}x|D]}t|tjrS|j|q(nt|ttfrt|dkst|dkrtdnt|dkr|dr|j|t|q(n|j|dq(tdq(W|S(Niis Invalid package & version tuple.isInvalid package type.(RERRFRGRRaR2R(tversion_fmttpkgstpkglisttpkg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytexpand_package_lists 

$cCsIg|jdD]}|r|^q}d}d}d}d}	xt|D]\}
}|j}t|dkr|jd|
dt||dS|d}
g|
jdD]}|r|^q}t|t|krqMntt|t|}|d|!|d|!kr&qMn|	dk	rPt|	t|krPqMny|jd}
Wn)tk
r|jd|
d|dSXy ||
d}||
d	}Wn)tk
r|jd
|
d|dSX|
}|}	|d}qMW|r&|rE|rE|rE|rE||||fSn|rE|rE|rE|||fSdS(
sRReturn the mount information for PATH given the lines from
    /proc/$$/mountinfo.RAi
s$Line %d has two few columns (%d): %siiiRvs,Did not find column named '-' in line %d: %sis/Too few columns after '-' column in line %d: %siN(	RRDRR2RtminRRHt
IndexError(RJtmountinfo_linesRtget_mnt_optsRt
path_elementstdevpthtfs_typetmatch_mount_pointtmatch_mount_point_elementsR%R:RKtmount_pointtmount_point_elementsRt
mount_options((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytparse_mount_infosV(	
(
	
	
cCsSxLtdjD]8}|jd \}}}||kr|||fSqWdS(s<On older kernels there's no /proc/$$/mountinfo, so use mtab.s	/etc/mtabiN(RR/RRD(RJR:RRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
parse_mtab*	s
cCs|jd}t|dkr)|dS|ddkr|d}tdd	d
g\}}xS|jdD]B}|j}t|dkrn|d|krn|d}PqnqnWt|Stjd
|dS(NRAiitlabeltgptRitglabeltstatuss-ss
is)Unexpected input in find_freebsd_part: %s(RRsufs(RR2RRR3R4(tfstsplittedttarget_labelRaRtlabelsR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_freebsd_part3	s
"

cCsfd}xY|jdD]H}|j}t|dkrtjj|d|r|}PqqW|S(Ns
ii(RDRR2RIRJR(RJtmnt_listt
path_foundR:R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_path_dev_freebsdD	s,cCstdd|gdddg\}}t|rstddg\}}t||}|dkrjdS|}n|j}t|d}d||d|dfS(NRys-pRiis/dev/i(RR2R#RDRR (RJRR?R!R"Rt
label_part((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_mount_info_freebsdN	s'	cCstjjds#tjddSytdd|g\}}Wn'tk
rk}tjd||dSXt	|r|dSd}xh|j
dD]W}tj||r||krd|kr|j
d	}tjd
|||SqWdS(Ns/dev/zfss"Cannot get zpool info, no /dev/zfstzpoolRs$Unable to get zpool status of %s: %ss.*(ONLINE).*s
tstateisfound zpool "%s" on disk %s(
RIRJRR3RRDRR6R4R2RRR}(R&tzpoolstatusR?RR:tdisk((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_device_info_from_zpool\	s 
*cCstdg\}}|j}d}x|D]}tj||}|sRq.n|jd}|jd}|jd}	|	dkr|jd}	ntjd|||	tjd|}
|
rtr|	d	krt	|S||kr.||	|fSq.WdS(
NRysH^(/dev/[\S]+|.*zroot\S*?) on (/[\S]*) (?=(?:type)[\s]+([\S]+)|\(([^,]*))iiiis?found line in mount -> devpth: %s, mount_point: %s, fs_type: %ss^(/dev/.+)p([0-9])$tzfs(
RR/RR}R!RDR3RRR%(RJRRRtregexR:RRRRtdevm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytparse_mountp	s(
	

cCsqdtj}tjj|rGt|j}t||||Stjjdrct|St|SdS(Ns/proc/%s/mountinfos	/etc/mtab(	RItgetpidRJRRR/RRR.(RJRR
tmountinfo_pathR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_mount_info	s
cCs%tjj|o$tj|tjS(N(RIRJRRR(tfpath((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_exe	scCs1t|}tjj|kr:tt||r:|Sn|dkrgtjjddjtj	D]}|j
d^qh}|dkr|}qg|D]}|jdr|^q}ng|D]}tjj|^q}xB|D]:}tjjj
||f}tt||r|SqWdS(NtPATHRCt"RA(RBRIRJtsepR3RDRZR)RtpathsepRRLRKR5(tprogramR}RtpRRJtppath((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytwhich	s :	+%
cCs:|dkrg}n|dkr*i}ntj}d}|rlytt}Wqltk
rhqlXnz|||}Wdtj|}	d}
|dk	rytt|}
Wqtk
rqXnd|	}|rt|
tr|d|
7}q|d7}ny|||Wntk
r4nXX|S(Ns took %0.3f secondss (%0.2f)s (N/A)(RDRtfloatRRHRER(RRRRRt
get_uptimetstarttustartRtdeltatudeltattmsg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR	s<		




cCs6|jdd}t|dkr(|S|dfSdS(NRi(trsplitR2RD(tdottedR
((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytexpand_dotted_devname
scCs|dkrg}n|dkr*g}ng}i}x||D]u}y(t|||dtdt||<WqAtk
r}|jtkrn||kr|j|qqAXqAWt|rtdj	ddj
|n|S(NRRMsMissing required files: {files}tfilesR+(RDRRRRRRR2RHRR5(RtrequiredtoptionaltdelimR>RRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytpathprefix2dict
s$		(!s
/proc/meminfoc	Csidd6dd6dd6dd	6}id
d6dd
6dd6}i}xt|jD]}y|j\}}}Wn)tk
r|j\}}d}nX|rt|||||<qV||krVt||||||<qVqVW|S(Nii
tkBitmBitBitgBttotals	MemTotal:tfreesMemFree:t	availables
MemAvailable:iii@(RR/RRHR(	tmeminfotrawtmplierstkmapRR:RRmtunit((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_meminfo%
s"


#cCs|}|jdr"|d }nidd6dd6dd6dd
6dd6}|}d}x:|D]2}|j|r^|}|d
t|!}q^q^Wyt|}Wn!tk
rtd|nX|d
krtd|nt|||S(sbConvert human string or integer to size in bytes
      10M => 10485760
      .5G => 536870912
    RMiiii
tKitMitGi(tTis'%s' is not valid input.s'%s': cannot be negativeiii@I(RR2R<RHR(Rtsize_inRTtnumtmplierR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pythuman2bytes:
s"
)

cCs|tkrd
St|}djt|}tjd|ytjj|setjd|d
St	|dt
}|stjd|d
S|dt|ddkrd	}n|jd
j
}tjd|||SWn"tk
r	ttd|d
SXd
S(s4
    Reads dmi data with from /sys/class/dmi/id
    s{0}/{1}squerying dmi data %ssdid not find %sRMs%s did not return any datasis
RCtutf8sdmi data %s returned %ssfailed read of %sN(tDMIDECODE_TO_DMI_SYS_MAPPINGRDRtDMI_SYS_PATHR3RRIRJRRRR2RMRRR(Rt
mapped_keytdmi_key_pathtkey_datatstr_data((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_read_dmi_syspathW
s*
	
cCsyd|d|g}t|\}}|j}tjd|||jdddkr_dS|SWn-ttfk
r}tjd||dSXdS(s
    Calls out to dmidecode to get the data out. This is mostly for supporting
    OS's without /sys/class/dmi/id support.
    s--strings dmidecode returned '%s' for '%s'RRCsfailed dmidecode cmd: %s
%sN(RRR3RRRRRD(Rtdmidecode_pathRwRRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_call_dmidecodex
scCsO|dkrtjd}n|dkpH|ddkoH|ddk}|S(s$Return True if platform is x86-baseditx86_64iR%it86N(RDRIR'(t
uname_archtx86_arch_match((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_x86
s
 cCstr
dSt|}|dk	r)|Stjd}t|pZ|dkpZ|dksqtjd|dStd}|rt	||Stj
dtdS(s
    Wrapper for reading DMI data.

    If running in a container return None.  This is because DMI data is
    assumed to be not useful in a container as it does not represent the
    container but rather the host.

    This will do the following (returning the first that produces a
    result):
        1) Use a mapping to translate `key` from dmidecode naming to
           sysfs naming and look in /sys/class/dmi/... for a value.
        2) Use `key` as a sysfs key directly and look in /sys/class/dmi/...
        3) Fall-back to passing `key` to `dmidecode --string`.

    If all of the above fail to find a value, None will be returned.
    itaarch64tamd64sdmidata is not supported on %st	dmidecodes0did not find either path %s or dmidecode commandN(R,RDRgRIR'RnR3RR;RiR4Rb(Rt
syspath_valueRlRh((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
read_dmi_data
s"	
	cCs6tjd dkr)tjtj|Stj|S(Nii(ii(RRqtemailtmessage_from_fileRFtStringIOtmessage_from_string(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRw
scCstddgd|dt\}}t}x|jD]y}y|jdd\}}}Wntk
ruq:nX|jds|jdr:|jt	j
dd	|q:q:W|S(
Ns
dpkg-querys--listRRithitiis:.*RC(RRRR/RRDRHRLRRtsub(RR Rt	pkgs_instR:R'R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_installed_packages
s$	
#cCsd}y>tt|dt}|jddjdkrCtSWn&tk
rl}tjd||nXt}d|krtStddt}d|jkrtSt	j
jd	rtStS(
Ns/etc/os-releaseRRRCsubuntu-cores!Unexpected error loading '%s': %ss
snap_core=s/etc/system-image/channel.inis/etc/system-image/config.d/(
R(RRR)RRHR3R4RRIRJRR(torpathtorinfoRRR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsystem_is_snappy
s 	cCs>g}x(|jtD]}|j||qWdj|S(sBreplacement for indent from textwrap that is not available in 2.7.RC(R/RRR5(RSRRR:((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR
scCs
d}x1|jD]#}|jdr|d}PqqW|dkrJdS|jdr]|S|jdr~d|tdS|jdrd|tdjS|jdrd	|tdj}tjj|r|St|}|r|d
S|Sd|S(Nsroot=is/dev/sLABEL=s/dev/disk/by-label/sUUID=s/dev/disk/by-uuid/s	PARTUUID=s/dev/disk/by-partuuid/i(	RDRRLR2RRIRJRR(RR1RJt
disks_pathtresults((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytrootdev_from_cmdline
s.
cCsjd}i}xT||D]F}|jdd\}}|sI|}n|sU|r|||<qqW|S(sGiven shell like syntax (key=value
key2=value2
) in content
       return the data in dictionary form.  If 'add_empty' is True
       then add entries in to the returned dictionary for 'VAR='
       variables.  Set their value to empty_val.cSstj|dtS(Ntcomments(tshlexRR(RN((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_shlex_splitsRi(R(Rt	add_emptyt	empty_valRR9R:RRm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR(s		g?cCst|}d}xtr|tg|D]}tjj|r(|^q(8}t|dkr|tjd|||gS|dkrtjd|||n|||krPntj	|||7}qWtjd||||S(Nis)%sAll files appeared after %s seconds: %ss6%sWaiting up to %s seconds for the following files: %ss*%sStill missing files after %s seconds: %s(
RRRIRJRR2R3RRtsleep(tflisttmaxwaittnaplentlog_pretneedtwaitedR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytwait_for_files%s$	5	
	
	
cCs3t|dt}|djd}|ddkS(s1Check whether the given mount point is mounted rwR
iR+itrw(R1RR(RRt
mount_opts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmount_is_read_write;scCsfddg}|r?tjj|r(dS|jd|gn|r\|jd|gnt|S(sAInvoke udevadm settle with optional exists and timeout parameterstudevadmtsettleNs--exit-if-exists=%ss--timeout=%s(RIRJRRR(RRt
settle_cmd((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytudevadm_settleBscCsxd}ytd|dt}Wn&tk
rH}tjd||nX|rt|jdd}t|d}n|S(s-
    Return the parent pid of a process.
    is
/proc/%s/statRs Failed to load /proc/%s/stat. %sRii(RRRR3R4RR(RtppidRRRK((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
get_proc_ppidPs(RRRsyes(RRRR(RRRjRRtRR:RRNR_RItos.pathR*R7RRRRRRRR[RRRRRtbase64RRtsix.moves.urllibRRgRFt	cloudinitRRtloggingRRR	R
RRtcloudinit.settingsR
t	functoolsRRRDRt	getLoggerRR3R6RRRRRRRR!R@R)RBRPRTRXRZRdRbRaRR6tobjectRRRRRRRRRRRRRRRRRRtDEBUGRRRRRRRR"R3RRGRKRRRMRqR|tcontextmanagerR~RRRRRRR7RRRRRRRRRRRRRR
RRRR"RRR-RR'R6R?RLRLRRVRWRXRYR^RfRiRlRrR\RxRRRRRRRRRRRRuRRRRRRRRR,RRRRR	RRR R#R%R*R.R1R3R;RRERJRJRWR_RgRiRnRsRwR|RRRR(RRRR(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt<module>s


	
		
U*	
	
			
				4"	3
			# "			(	,					3		
		:									

	(J										&			 	-				J				
			#'	'			!	
	*					
Back to Directory File Manager