Current File : //lib/python2.7/site-packages/cloudinit/util.pyc
�
�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
rd�Z/nXda2e%j3e4�Z5ide
j66Z7dej8ej9Z:d�Z;d�Z<dddgdgdgfZ=e/�dd��Z>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@dA6dBdC6dDdE6dFdG6dHdI6dJdK6ZHdLeIfdM��YZJdNeKfdO��YZLdPeMfdQ��YZNdReMfdS��YZOdT�ZPddU�ZQddV�ZRddW�ZSdXddY�ZTddZ�ZUd[�ZVd\�ZWd]�ZXd^�ZYeZeZd_�Z[d`�Z\da�Z]eZeZde%j^db�Z_dc�Z`e/�dd��Zaebde�Zcddf�Zddgdh�Zeddi�Zfe/�dj��Zge/�dk��Zhddl�Ziddm�Zjdn�Zkdddo�Zlddpdpdpdpdq�Zmebdr�Znejods��Zpejodt��Zqdu�Zrdv�ZseZddw�Ztdpdpdxdy�Zuddz�Zvdewfd{�Zxdpdpdxd|dgd}�Zyd~�Zzd�Z{dd��Z|dd��Z}d��Z~ebd��Zd�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�dd�debdd��Z�debd��Z�d��Z�d��Z�debeZd��Z�e/�d���Z�d��Z�d�dd��Z�ddd��Z�ddd��Z�d��Z�d��Z�d��Z�dd��Z�d��Z�d��Z�d��Z�d�d��Z�ewfd��Z�d��Z�d��Z�d��Z�dd��Z�ejod���Z�d��Z�dddd��Z�d��Z�d��Z�ebd��Z�d��Z�d��Zd��Z�d��Z�d��Z�d�d��Z�d��Z�d��Z�d�d�ebd��Z�d��Z�d��Z�dddeZebebebd�dddd��Z�d�d�d��Z�d��Z�eZd��Z�ddd��Z�d��Z�d��Z�d#d�d��Z�d��Z�d��Z�d��Z�e5ebd��Z�d��Z�d��Z�d��Z�d��Z�d��Z�d��Z�e5ebd��Z�d��Z�ddd��Z�ddebd��Z�d��Z�dde
j�j6d��Z�d�ebd��Z�d��Z�d��Z�d��Z�dd��Z�d��Z�d��Z�dd��Z�d��Z�d��Z�d��Z�ebdd��Z�d�dpd��Z�d��Z�ddd��Z�d��Z�dS(�i����N(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|�\}}|j�S(Ntdpkgs--print-architecturetcapturettarget(tsubptTruetstrip(RtoutR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_architectureRscCs;idd6dd6dd6dd6}i}y�td	d
gdtd|�\}}xO|j�D]A}|jd
�\}}}||kr\|j�|||<q\q\Wg|j�D]}||kr�|^q�}	t|	�r�tjddj	|	��nWn?t
k
r6}
tjd|
�td�|j�D��}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|�St�S(Nt/(ttarget_pathR@(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR)qs
cCs�|dkrd}nSt|tj�s:td|��n.tjj|�}|jd�rh|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|tj�r|S|j|�S(N(RERFRGtdecode(tblobtencoding((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
decode_binary�scCs#t|tj�r|S|j|�S(N(RERFtbinary_typetencode(ttextRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytencode_text�scCs6t|�}y|jd�SWntk
r1|SXdS(Nsutf-8(RRMtUnicodeDecodeError(tsourcetdecoded((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytb64d�s

cCs4t|t�s!|jd�}nt|�jd�S(Nsutf-8(REtbytesRRRRM(RV((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytb64e�scCs}|jdt�}tjry|j�dkryt|t�ry|j�}|rc|jrc|j}nd}|j	|d�S|S(NRMRSsutf-8tsurrogateescape(
tget_payloadRRFtPY3tget_content_maintypeRERYtget_charsettinput_codecRM(tparttcte_payloadtcharsetRO((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfully_decoded_payload�s	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-versionR6cBsGeZdZdZdddddddd�Zd�Zdd�ZRS(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|tj�sy|j|_n	||_|s�|dkr�|j|_	q�||_	n|j
|�|_	|s�|dkr�|j|_q||_n|j
|�|_|r||_n|j|_||_
|ji|j|j�d6|j|j�d6|j|j�d6|j|j�d6|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.pyR��sB					cCs t|tj�r|j�S|S(s1
        if data is bytes object, decode
        (RERFRQRM(R�RS((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�sicCsZd}d|}t|tj�r=|j�}|j�}n|j|�j|||�S(sY
        indent text on all but the first line, allowing for easy to read output
        s
t (RERFRQRRtrstriptreplace(R�RStindent_leveltcrtindent((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR~"s
N(t__name__t
__module__R�R|RDR�R�R~(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR6�s3	tSeLinuxGuardcBs&eZed�Zd�Zd�ZRS(cCsIytjd�|_Wntk
r2d|_nX||_||_dS(Ntselinux(Rt
import_moduleR�tImportErrorRDRJt	recursive(R�RJR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�2s

	cCs$|jr|jj�rtStSdS(N(R�tis_selinux_enabledRtFalse(R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	__enter__<scCs|js|jj�rdStjj|j�s7dStjj|j�}tjrdt|�}ny-tj	|�}|jj
||tj�Wnt
k
r�dSXtjd||j�y|jj|d|j�Wn,t
k
r}tjd||j|�nXdS(Ns,Restoring selinux mode for %s (recursive=%s)R�s,restorecon failed on %s,%s maybe badness? %s(R�R�RIRJtlexiststrealpathRFtPY2tstrtlstattmatchpathcontstattST_MODEtOSErrorR3tdebugR�t
restoreconR4(R�t	excp_typet
excp_valuetexcp_tracebackRJtstatste((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt__exit__Bs&	
	
	(R�R�R�R�R�R�(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�1s
	tMountFailedErrorcBseZRS((R�R�(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�[stDecompressionErrorcBseZRS((R�R�(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�_scOs�tj�}|dkrsy|||�tjd�Wq�tk
rottdtj|��tjd�q�Xntjd|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|t�r|tkSt}|r8t|�|}ntj|�j�j�|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|t�r|tkSt}|r8t|�|}ntj|�j�j�|kr]t	StS(N(
RER�R�t
FALSE_STRINGSR�RFR�R�RR(R<R�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_false}s
!cCs*|s
tSt|t�r|St||�S(N(R�RER�R�(R<R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyttranslate_bool�s
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_str�scCsG|sd}nx1trBtdd�d|}||krPqqW|S(NRCR�iR(RR�(t
dictionarytpostfixtnewkey((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
rand_dict_key�s		cCsJytt|�di�SWn)tk
rE}|jtkr?iS�nXdS(Ntdefault(t	load_yamlt	load_fileR�RR(R;R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	read_conf�scGstt|��S(N(tsortedt
uniq_merge(tlists((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytuniq_merge_sorted�scGs}g}xj|D]b}t|tj�rb|j�jd�}g|D]}t|�rA|^qA}n|j|�q
Wt|�S(NR+(RERFRGRtsplitR2textendt	uniq_list(R�t
combined_listta_listta((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��s
(cCs�x,tj�D]\}}|j||�}q
Wg}x*|D]"}|tkr<|j|�q<q<Wx |D]}|j|d�}qiW|j�}|S(NRC(tFN_REPLACEMENTStitemsR�t
FN_ALLOWEDtappendR(tfnR=R.tremovals((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytclean_filename�s

cCs�yctjt|��}tjtjddd|���'}|rRt|j	��S|j	�SWdQXWn2t
k
r�}|r|Sttj|���nXdS(Ntrbi(
RFtBytesIORTt
contextlibtclosingtgziptGzipFileRDRPtreadR�R�R�(R9tquietRMtbuftghR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdecomp_gzip�s$cCs�|s
dS|jdd�}|dj�}t|�dkrQ|dj�}nd}|s||dks||j�dkr�d}n|s�|dks�|j�dkr�d}n||fS(NR*iiis-1tnone(NN(RDR�RR2R�(tug_pairt	ug_partedtutg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytextract_usergroup�s%	%	cCs�t�}x�tjtjj|d��D]k}tjj|�sFq(ntjj|�dd!}|j�}|r(|jd�dkr(|||<q(q(W|S(Ns*.pyii����t.i����(	R7tglobRIRJR5tisfiletbasenameRtfind(troot_dirtentriesR;tmodname((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_modules�s	%cCs�|rtjj|�n|r|d}tjj|�rit|d��}|j|�|j�WdQXq|tjj|�n|r�|ddkr�|j	||d �q�|j	||�ndS(Ns/dev/consoletwi����s
(
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.R�iii(R�R2R�tintR�(tinstrttokstx((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_ipv4s?
cCst�ddkS(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|tj�s;t|�}n|S(N(RERFRGR�(RRR�R<((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�}|dj�jd�d|d<|ddkr�d|d<ni|dd6|d	d
6|dd6SiS(
s�Return 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(	RIRJRR�tretmatcht	groupdictR�R0(trelease_filetredhat_releasetredhat_regexRtgroup((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_parse_redhat_releaseBs	!
c	Cs�d}d}d}i}tjjd�r?ttd��}n|sQt�}n|r|jdd�}|jdd�}d|ks�d|kr�tj�}nR|jdd�}|s�t	j
d|jd	d��}|r�|j�d
}q�n|dkr�d}q�n�tjjd
�rKd}tddg�\}}|j
�}nrd}z(ytj�}Wntk
rwnXWdd}x|D]}|r�d}q�q�W|s�tjd�nX|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_contentR�R"tgettplatformtmachineRRRRRtdistR�RDR3R4(	tdistro_nametdistro_versiontflavort
os_releaseRRR,tfoundtentry((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_linux_distro\sN	


cCsitj�d6tj�d6tj�d6tj�d6tj�d6t�d6}|dj�}d}|dkr�|dd	j�}|dkr�|}q�|dkr�d}q�|dkr�d}q�|dkr�d}q�d}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.pyR�s4





								
cCs�||kr|S||dkr$gS||}t|t�rZg|D]}|^qD}|St|tj�s{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(RDRER�RFRGR�(RRR�R<R.tcval((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_option_list�s
cCsYt|tj�r$|jd�}n|}x(|D] }||krG|S||}q1W|S(s�Return 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�(RtkeypR�tcurttok((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_cfg_by_path�s
cCs,t||�\}}t||�||fS(N(tget_output_cfgtredirect_output(tcfgtmodetoutfmtterrfmt((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfixup_output�s
c	CsXttjjd��r)tjd�dS|s;tj}n|sMtj}n|rptjd||�|j	dd�\}}|dks�|dkr�d}|dkr�d	}nt
||�}nF|d
kr�tj|dt
dtj�}|j}ntd
|��|r.tj|j�|j��n||krptjd||�tj|j�|j��dSn|rTtjd||�|j	dd�\}}|dks�|dkr�d}|dkr�d	}nt
||�}nF|d
krtj|dt
dtj�}|j}ntd|��|rTtj|j�|j��qTndS(Nt_CLOUD_INIT_SAVE_STDOUTs5Not redirecting output due to _CLOUD_INIT_SAVE_STDOUTsRedirecting %s to %sR�it>s>>tabtwbt|tshelltstdins"Invalid type for output format: %ss!Invalid type for error format: %s(R�RItenvironR)R3R�R�RyRzR�Rt
subprocesstPopenRtPIPERYt	TypeErrortdup2tfileno(	RPRQto_outto_errROtargtowithtnew_fptproc((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRM�sN
		RCc	Cs�|p	dg}d}|r*t|�}n|dk	rK|dd|7}n|j|pZd�|j|pmd�|j|p�d�|j|p�d�|j|p�d�tj|�S(NRCR*s%s(R�RDR�turlparset
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.pyR�Ys	cCsdj|d|ddd|�S(Ns{0:{fill}{align}{size}}tfilltalignt^tsize(tformat(RSR�tmax_len((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytcenterbscCs!tjd|�tj|�dS(NsRecursively deleting %s(R3R�tshutiltrmtree(RJ((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdel_dirgsc	Csx|rtjj|�rdSg}g}|dkr>g}nEt|t�r_t|�g}n$t|t�rw|}ntd��x�ttj	|��D]�}tjj
||�}tjj|�r�tj|tj
�r�|j|�yt||gdt�Wq?tk
r;}ttd||j�|j|�q?Xq�q�W|rt|rttdt|�t|�f��ndS(Ns%exe_prefix must be None, str, or listRsFailed running %s [%s]s.Runparts: %s failures in %s attempted commands(RIRJtisdirRDRER�R�R^R�tlistdirR5R�taccesstX_OKR�RR�R6R�R3Rxt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_tS�nXdS(Ns	user-datas	meta-data(tread_seededRRtUrlErrortcodet	NOT_FOUNDR�(R�tbasetextttimeouttmdtudR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_optional_seed�s

cCswi}ddg}|r^|jtjj|jd�d�tjj|jd�d�g�nt|�}g|D]$}|rqtjj|�rq|^qq}d}xH|D]@}tjj	tjj|d��r�tjj|d�}Pq�q�Wd}xH|D]@}tjj	tjj|d��r�tjj|d�}Pq�q�W|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(
R�RIRJR5t
get_ipath_curt	get_cpathR�R�RDR�(tpathstssl_detailstssl_cert_pathstdR�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfetch_ssl_details�s2	%1
!
!


c
Cs�|}t|�}y�tjdt|�|�tj|�}|dkr_tjd�|}n1t||�s�td|t	j
|�f��n|}Wn�tjttfk
r�}d}d}t
|d�r�t|d�r�t|d�}n0t
|d�r!t|d�r!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}(RPR3R�R2RtloadRDRER^R
R�t	YAMLErrorRHthasattrtgetattrR�R:tcolumnR4(RNR�tallowedtloadedt	convertedR�tmsgtmark((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��s6	
	
	'i
cCs�|jd�dkr4|d|}|d|}n&d|d|f}d|d|f}tj|d|d|�}d}|j�r�tt|j�di�}ntj|d|d|�}	d}
|	j�r�|	j}
n||
fS(	Ns%sis	user-datas	meta-datas%s%s%sR�tretriesR�(R�Rtread_file_or_urlRDtokR�RPtcontents(R�R�R�R�tfile_retriestud_urltmd_urltmd_respR�tud_respR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��s 		cCs�ttj|�dt�}g|D]}|jd�r"|^q"}g|D]-}tjjtjj||��rJ|^qJ}g}x0|D](}|jt	tjj||���q�Wt
|�S(NRxs.cfg(R�RIR�RtendswithRJR�R5R�R�R|(tconfdtconfsRtcfgsR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_conf_d�s(
-
&cCs�t|�}t}d|krz|d}|r�t|tj�sbtd|tj|�f��qwt|�j	�}q�n#t
jjd|�r�d|}n|s�t
jj|�r�|St
|�}t||g�S(Ntconf_ds8Config file %s contains 'conf_d' with non-string type %ss%s.d(R�R�RERFRGR^R
R�R�RRIRJR�R�R|(tcfgfileRNR�t	confd_cfg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_conf_with_confds

cCsttd|��S(Ntcmdline(R�tread_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||||!j�jdd��|j|||�}q`Wdj|�S(Nscc:tend_ccis\ns
(RDtget_cmdlineR2R�R�tlstripR�R5(	R�t	tag_beginttag_endtbegin_ltend_ltclenttokenstbegintend((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�$s"		 
cCsC|jd�}|dks/||ddkr3|S|jdd�S(Ns
iis
s
(R�R�(R�tpos((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdos2unixCs cCs�d|kr8|d}t|d|jd�d�}n�d|kr�|djd�dkr�|d}|d|jd� }nC|jdtd|�}d|kr�|d}n|jd|�}||fS(s�Get 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.
    tfqdnthostnameR�it
metadata_only(RR�R�tget_hostnameR(RNtcloudR�R�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_hostname_fqdnKs

"%

s
/etc/hostscCs�d}y�x�t|�j�D]�}|jd�}|dkrM|d|!}n|j�}|seqn|j�}t|�dkr�qn||dkr|d}PqqWWntk
r�nX|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(RDR�R/R�RR�R2R�(R�tfilenameR�R:thashposR
((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_fqdn_from_hostsjs$

cCsWtdkr�t�}d	}i}x�|D]�}y�tj|dddtjtj�}g||<xM|D]E\}}}}	}
||jd|	|
df�|j|
d�qfWWq(tj	tj
fk
r�q(Xq(W|a|r�tjd|�q�ny<tj|d�}|ddd}|tkr-t
StSWntj	tj
fk
rRt
SXdS(
s�determine 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_CANONNAMER�taddtgaierrorterrorR3R�R�R(Rtbadipstbadnamest
badresultstinametresultt_famt_stypet_prototcnametsockaddrtaddr((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
is_resolvable�s6
	

cCstj�}|S(N(R�tgethostname(R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��scCs1ytj|�dSWntjk
r,dSXdS(Ni(R�t
gethostbyaddrtherrorRD(tip((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�sc
Cs5tdtjdd|dtdtj|�jf�S(s5determine if this url is resolvable (existing or ip).tlogfuncR�sResolving URL: tfuncR�(tlog_timeR3R�R�RgR�(turl((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_resolvable_url�scCs=x6|D].}yt|�r |SWqtk
r4qXqWdS(sc
    Search through a list of mirror urls for one that works
    This needs to return quickly.
    N(RR�RD(t
candidatestcand((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsearch_for_mirror�s

cCsWttjjd��rdSttj��&}tj|j�tj	j��WdQXdS(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(
R�RIRZR)RtdevnullR_R`R�RY(tfp((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytclose_stdin�stdevicec
Cs/dg}g}|r)|jd|�n|rC|jd|�n|r_|jddg�n|ry|jd|�n|r�|j|�n||}y"t|ddd	g�\}}	Wn.tk
r�}
|
jtkr�d
}q��nXg}x6|j�D](}|j�}|r�|j|�q�q�W|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(R�R�RR6RRR/R(
tcriteriatoformatttagtno_cacheRJt
blk_id_cmdtoptionsRwR t_errR�R�R:((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_devs_with�s2		
"	c	Cs�|dkrg}nt|�}dddg}|rL|jddg�n|j|�t|dtdd�\}}i}xJ|j�D]<}|jd	�\}}}t|�||<|||d
<q�W|S(s�Get 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/nullRRMR�R*tDEVNAMEN(RDR�R�RRR/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�(R3R�RR�(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.pyR�Fs
c	Cs�tjd||�tj�}y/t|d��}t||d|�WdQXWn4tk
r�}|sl�n|jtkr��q�nX|j	�}tjdt
|�|�|r�t|�S|SdS(NsReading from %s (quiet=%s)R�tchunk_cbsRead %s bytes from %s(R3R�RFR�Rtpipe_in_outR�RRtgetvalueR2RP(R;tread_cbR�RMtofhR!R�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�Ps

cCs�t�r^y&td�}|jdd�d }Wq�tk
rZ}tjd|�d}q�Xn0ytd�j�}Wntk
r�d}nX|S(Ns/proc/1/cmdlinetR�i����s"failed reading /proc/1/cmdline: %sRCs
/proc/cmdline(tis_containerR�R�R�R3R4R(R�R�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_get_cmdlinecs	


cCs!dtjkrtjdSt�S(NtDEBUG_PROC_CMDLINE(RIRZR-(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�vsicCsvd}x_trg|j|�}t|�dkr4Pq	|j|�|t|�7}|r	||�q	q	W|j�|S(Ni(RR�R2R�R(tin_fhtout_fht
chunk_sizeR&tbytes_pipedR9((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR'}s	

cCsI|dkr|dkrdStjd|||�tj|||�dS(Ni����s%Changing the ownership of %s to %s:%s(Ni����(Ni����(RDR3R�RItchown(R;tuidtgid((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt	chownbyid�scCs�d}d}y:|r*tj|�j}n|rEtj|�j}nWn#tk
rk}td|��nXt|||�dS(Ni����sUnknown user or group: %s(	tpwdtgetpwnamtpw_uidtgrptgetgrnamtgr_gidtKeyErrorR�R6(R;tuserR!R4R5R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytchownbyname�sc
Csddg}|sd|kr#|S|d}||krF||}nd|krV|S|d}t|t�r~||g}nt|t�r�t|�dkr�|d|d<nt|�dkr�|d|d<q�nt|t�r"d|kr|d|d<nd|kr"|d|d<q"n|ddkrC|d|d<nddd	g}x�tt|��D]�}||s{qen||j�}t}xG|D]?}	|j	|	�r�d
|	|t|	�j
�f}t}Pq�q�W|s�d
d|j
�f}n|||<qeW|S(NtoutputtalliiR�s&1s>>RTRWs%s %s(RDRER�R�R2R7R�R�R�RLRR(
RNRORtoutcfgtmodecfgtswlistR%R<R1ts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRL�sL




 cCsg}|st|t�r!|S|jd�}|rF|j|�nx�t|d�D]�}|shqVntjd|�}|s�qVn|jd�}|j	�}t
|�dkr�|j|�qVddg|d krV|j|d�qVqVWtt|��S(	s�Return 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)R�RLRDRRR!R�R2R�R�(RNtlogstdefault_logtfmtRRtparts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_config_logfiles�s&cGsT|r|j||�ntj�}|dkr:d}n|j|d||�dS(Ntexc_info(NNN(R4R�RMRDR�(RR�R�RM((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��s	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(R3R�RItrename(tsrctdest((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRY+si�cCs"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|�f��n|S(Ns, s((%s) root types expected, got %s instead(	tjsontloadsRPREttupleR5R�R^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(R�RZtAttributeErrorRb(t_obj((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytjson_serialize_default?s
cCs}tj|�}xg|j�D]Y\}}t|t�rJt|�||<nt|t�rdjt|��||<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_copytdeepcopyR�RER7tjson_preserialize_binaryRYR�RZ(R9Rtvalue((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRlGs c
Cspy)tj|dddtdddt�SWn@tk
rktjd dkret|�}tj|�S�nXd
S(
s%Return data in nicely formatted json.R�it	sort_keyst
separatorsR+s: R�iiN(R+s: (ii(R_tdumpsRRiRUR�tversion_infoRl(R9((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
json_dumpsWs

cCsetjj|�sTttjj|�dt��tj|�WdQXt||�n
t||�dS(NR�(RIRJR�R�tdirnameRtmakedirstchmod(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}yFtjjd�r6td�j�}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d�nX|S(Ns/proc/mountsRftmounts*^(/dev/[\S]+) on (/.*) \((.+), .+, (.+)\)$iiiis\040R�tfstypet
mountpointtoptssFetched %s mounts from %ssFailed fetching mount points(RIRJRR�R/RR�RtsearchR!R�R�R3R�R�R�R�(tmountedt
mount_locstmethodtmountoutputRtmountretmplineRtmpRzR|t_freqt_passnotm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmountsys:	
!
cCs�t|t�r|g}nWt|ttf�r?t|�}n3|dkrTd}ntdjdt|����tj	�j
�}|dkr�|dkrdg}qno|jd�r|dkr�dddg}nx?t|�D]%\}}|d	kr�d||<q�q�Wn	d
g}t
�}tj��|}	t}
tjj|�|krm|tjj|�d}n�d}x�|D]�}d}yfdd
dg}
|r�|
jd|g�n|
j|�|
j|	�t|
d|�|	}
|	}PWqzttfk
r#}tjd|||�|}qzXqzW|sJtd||	|f��n|jd�sf|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(RER�R�RaRDR^R�RbR*R4R�R�t	enumerateR�R	ttempdirR�RIRJR�R�R�RR�R�R3R�R�Rx(RtcallbackR9tmtypetupdate_env_for_mounttmtypestplatsystindexR~ttmpdRvR{tfailure_reasontmountcmdtexcR((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmount_cb�sh				


	


cCs
tjt�S(N(RjRkR
(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_builtin_cfg�scCs tjd|�tjj|�S(NsTesting if a link exists for %s(R3R�RIRJtislink(RJ((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_link�scCsLtjd||�|r8tjj|�r8t|�ntj||�dS(Ns$Creating symbolic link from %r => %r(R3R�RIRJRtdel_filetsymlink(RVtlinktforce((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsym_link�s
cCsStjd|�ytj|�Wn+tk
rN}|jtkrO|�qOnXdS(NsAttempting to remove %s(R3R�RItunlinkR�RR(RJR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��scCs'tjd||�tj||�dS(NsCopying %s to %s(R3R�R�tcopy(RZR[((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�scCs: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}y�tjjd�rOd}td�}|r�|j�d}q�n�d}tjd�}tj�}tj�}tj	|�|_
|jdtj|�tj|�dd�tj�}|j
}||}Wn"tk
r�ttd|�nX|S(	Ns??R6s/proc/uptimeitctypess/lib/libc.so.7s
kern.boottimes&Unable to read uptime using method: %s(RIRJRR�R�R�tCDLLtc_size_ttc_inttsizeofRmtsysctlbynametbyrefRDR�R�R�R3(t
uptime_strR�R�tlibcR�R�tnowtbootup((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytuptimes*	
cCst||dddd�dS(NtomodeRURO(t
write_fileRD(RJtcontent((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytappend_file-si�cCs t|ddddd|�dS(NR�RCR�RURO(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(R�R�RIRu(RJROt	real_mode((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRu<s
RVc	
Cs5|rBy%tj|�}tj|j�}WqBtk
r>qBXnttjj|��d|j�krt	|�}d}nt
|�}d}yd|}Wntk
r�d|}nXtj
d|||t|�|�td|��4t||��}|j|�|j�WdQXWdQXt||�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(RIR�tS_IMODEtst_modeR�R\RJRsR�RTRPR^R3R�R2R�RR�RRu(	R�R�ROR�t	copy_modet	file_statt
write_typetmode_rtfh((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�Cs.
	
	
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(RIR�RJR5R�R�R�(Rstnodet
node_fullpath((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytdelete_dir_contentsis

c
Os�|jdd�}t|�dkr?d|kr?t�g}ntjdt���}tjj||�}d|kr�|gt	|d�|d<n!t	|�}|g|d|d<t
||dd�t||�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.
    R�t	subp_blobiR�t	needs_exeROi�N(tpopR2RaR	R�RRIRJR5R�R�R(RNR�R�R�R�ttmpf((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsubp_blob_in_tempfilewsR�cs�|	dk	rtd��n|dkr3dg}nd}|
rs|dkrWtj}n|j�}|j|
�nt|	�dkr�d|	gt|�}n|r�t|t�r�dj	|�n|}
|dj
d|
��n|stjd||||rd	n|�ntjd
|�d}d}d}|rLt
j}t
j}n|rgt
j}t
j}n|dkr�ttj�}|}n't
j}t|t�s�|j�}nt|tj�r�|}n^t|tj�r�|jd�}n:g|D]-}t|tj�r|n|jd�^q�}z�yFt
j|d|d
|d|d|d|�}|j|�\}}Wnhtk
r�}|r�|d�ntd|d|d|jd�r�dndd
�r�dnd��nXWd|r�|j�nX|s|r$|sd}n|s$d}q$n�rWd�fd�}||�}||�}n|j}||kr�|r�|dj
d|��ntd|d
|d|d|��n|r�|dj
d|��n||fS(s�Run 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-initiRAtchrootR�sBegin 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|t�s|S|j|��S(N(RERYRM(R9R�(RM(s2/usr/lib/python2.7/site-packages/cloudinit/util.pytldecodess%ERROR: End run command: exit({code})
R�RxsEnd run command: exit({code})
(RDRHRIRZR�RPRBR�RER5R�R3R�R[R]tSTDOUTRRRYRRRFRQRGR\tcommunicateR�R6Rtcloset
returncode(R�R9RR�Rtcombine_captureRXt	logstringRMRR�t	status_cbt
devnull_fpR�RYRyRzt
bytes_argsRtspR R?R�R�trc((RMs2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�s�4$							7
		R�tcreatedcCsGtj�}t|�}|d|j�|f7}|dt�7}|S(Ns %s by cloud-init v. %ss on %s(Rtversion_stringR�ttitleR�(tcomment_charR�tci_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|ttf�s1tdtj|���nd}|rJ|d7}ndd}d}x�|D]�}t|ttf�r�g}x4|D],}|jdtj|�j	d|��q�Wd	|d
j
|�f}|d7}qat|tj�rd	||f}|d7}qatdtj|�|f��qaWt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
R�isCUnable to shellify type '%s'. Expected list, string, tuple. Got: %ssShellified %s commands.(R�s\R�R�(RERaR�R^R
R�R�RFR�R�R5RGR3R�(tcmdlistt
add_headerR�tescapedt	cmds_madeR�tfixedR((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:R�tsuffix((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytstrip_prefix_suffixZs
cCs5x:tD]2}yt|�tSWqttfk
r8qXqWy0td�}d|kr\tSd|krltSWnttfk
r�nXtjjd�r�tjjd�r�tSygt	d�j
�}xN|D]F}|jd�r�|j�j
dd�\}}|d	krtSq�q�WWnttfk
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_TESTSRRR�R�tget_proc_envRIRJR�R�R/RLRR�R�(thelpertpid1envtlinesR:t_keyR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR,bs4

%
cCstjjd�S(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_lxd�scCs�tjjdt|�d�}yt|dt�}Wnttfk
rNiSXi}d\}}|r�d\}}|j||�}nxN|j	|�D]=}|s�q�n|j	|d�\}	}
|	r�|
||	<q�q�W|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�(
RIRJR5R�R�R�R�R�RMR�(tpidROterrorsR�R�R�tnulltequalRJRR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��s"cCsgi}xZ|j�D]L}y|jdd�\}}Wntk
rT|}t}nX|||<qW|S(NR�i(R�RHR(tkvstringRRJRR<((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytkeyval_str_to_dict�s

cCs0|jd�r|d}ntjjd|�S(Ns/dev/is/sys/class/block/%s/partition(RLRIRJR�(R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_partition�s
cCs�t|t�s|g}ng}x�|D]�}t|tj�rS|j|�q(nt|ttf�r�t|�dks�t|�dkr�td��nt|�dkr�|dr�|j|t|��q(n|j|d�q(td��q(W|S(Niis Invalid package & version tuple.isInvalid package type.(RER�RFRGR�RaR2R�(tversion_fmttpkgstpkglisttpkg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytexpand_package_list�s 

$cCsIg|jd�D]}|r|^q}d}d}d}d}	x�t|�D]�\}
}|j�}t|�dkr�|jd|
dt|�|�dS|d}
g|
jd�D]}|r�|^q�}t|�t|�kr�qMntt|�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(	R�RDR�R2R�tminR�RHt
IndexError(RJtmountinfo_linesRtget_mnt_optsR�t
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_info�sV(	
(
	
	
cCsSxLtd�j�D]8}|j�d \}}}||kr|||fSqWdS(s<On older kernels there's no /proc/$$/mountinfo, so use mtab.s	/etc/mtabiN(R�R/R�RD(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|jd�D]B}|j�}t|�dkrn|d|krn|d}PqnqnWt|�Stjd
|�dS(NRAiitlabeltgptR�itglabeltstatuss-ss
is)Unexpected input in find_freebsd_part: %s(RRsufs(R�R2RR�R3R4(tfstsplittedttarget_labelRaRtlabelsR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytfind_freebsd_part3	s
"

cCsfd}xY|jd�D]H}|j�}t|�dkrtjj|d|�r|}PqqW|S(Ns
ii(RDR�R2RIRJR(RJtmnt_listt
path_foundR:R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_path_dev_freebsdD	s,cCs�tdd|gdddg�\}}t|�rstddg�\}}t||�}|dkrjdS|}n|j�}t|d�}d||d|dfS(NRys-pRiis/dev/i(RR2R#RDR�R (RJR�R?R!R"Rt
label_part((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_mount_info_freebsdN	s'	cCs�tjjd�s#tjd�dSytdd|g�\}}Wn'tk
rk}tjd||�dSXt	|�r|dSd}xh|j
d�D]W}tj||�r�||kr�d|kr�|j
�d	}tjd
||�|Sq�WdS(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(
RIRJRR3R�RDRR6R4R2R�RR}(R&tzpoolstatusR?R�R: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|�}
|
r�t�r�|	d	kr�t	|�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!RDR3R�RR%(RJR�RRtregexR:R�RRRtdevm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytparse_mountp	s(
	

cCsqdtj�}tjj|�rGt|�j�}t||||�Stjjd�rct|�St|�SdS(Ns/proc/%s/mountinfos	/etc/mtab(	RItgetpidRJRR�R/RRR.(RJRR
tmountinfo_pathR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_mount_info�	s
cCs%tjj|�o$tj|tj�S(N(RIRJR�R�R�(tfpath((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytis_exe�	scCs1t|�}tjj|kr:tt||��r:|Sn|dkr�gtjjdd�jtj	�D]}|j
d�^qh}|dkr�|}q�g|D]}|jd�r�|^q�}ng|D]}tjj|�^q�}xB|D]:}tjjj
||f�}tt||��r�|Sq�WdS(NtPATHRCt"RA(RBRIRJtsepR3RDRZR)R�tpathsepRRLRKR5(tprogramR}RtpR�RJtppath((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	r�ytt��|}
Wq�tk
r�q�Xnd|	}|rt|
t�r|d|
7}q|d7}ny|||�Wntk
r4nXX|S(Ns took %0.3f secondss (%0.2f)s (N/A)(RDR�tfloatR�RHRER�(RR�RR�R�t
get_uptimetstarttustartRtdeltatudeltattmsg((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR�	s<		




cCs6|jdd�}t|�dkr(|S|dfSdS(NR�i(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�}|jtkr��n||kr�|j|�q�qAXqAWt|�r�tdj	ddj
|����n|S(NR�RMsMissing required files: {files}tfilesR+(RDR�R�R�RRR�R2RHR�R5(R�trequiredtoptionaltdelimR>RRR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytpathprefix2dict
s$		(!s
/proc/meminfoc	Cs�idd6dd6dd6dd	6}id
d6dd
6dd6}i}x�t|�j�D]�}y|j�\}}}Wn)tk
r�|j�\}}d}nX|r�t|�||||<qV||krVt|�|||||<qVqVW|S(Nii
tkBitmBitBitgBttotals	MemTotal:tfreesMemFree:t	availables
MemAvailable:iii@(R�R/R�RHR(	tmeminfotrawtmplierstkmapRR:RRmtunit((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytread_meminfo%
s"


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

cCs|tkrd
St|}djt|�}tjd|�y�tjj|�setjd|�d
St	|dt
�}|s�tjd|�d
S|dt|�ddkr�d	}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 datas�is
RCtutf8sdmi data %s returned %ssfailed read of %sN(tDMIDECODE_TO_DMI_SYS_MAPPINGRDR�tDMI_SYS_PATHR3R�RIRJRR�R�R2RMRR�R�(Rt
mapped_keytdmi_key_pathtkey_datatstr_data((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_read_dmi_syspathW
s*
	
cCs�yd|d|g}t|�\}}|j�}tjd||�|jdd�dkr_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'R�RCsfailed dmidecode cmd: %s
%sN(RRR3R�R�R�R�RD(Rtdmidecode_pathRwR�RR�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_call_dmidecodex
scCsO|dkrtj�d}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
 cCs�t�r
dSt|�}|dk	r)|Stj�d}t|�pZ|dkpZ|dksqtjd|�dStd�}|r�t	||�Stj
dt�dS(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'RnR3R�R;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(R�Rqtemailtmessage_from_fileRFtStringIOtmessage_from_string(R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyRw�
scCs�tddgd|dt�\}}t�}x�|j�D]y}y|jdd�\}}}Wntk
ruq:nX|jd�s�|jd�r:|jt	j
dd	|��q:q:W|S(
Ns
dpkg-querys--listRRithitiis:.*RC(RRR�R/R�RDRHRLR�Rtsub(RR Rt	pkgs_instR:R'R((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytget_installed_packages�
s$	
#cCs�d}y>tt|dt��}|jdd�j�dkrCtSWn&tk
rl}tjd||�nXt�}d|kr�tStddt�}d|j�kr�tSt	j
jd	�r�tStS(
Ns/etc/os-releaseR�RRCsubuntu-cores!Unexpected error loading '%s': %ss
snap_core=s/etc/system-image/channel.inis/etc/system-image/config.d/(
R(R�RR)R�RHR3R4R�RIRJR�R�(torpathtorinfoR�R�R�((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytsystem_is_snappy�
s 	cCs>g}x(|jt�D]}|j||�qWdj|�S(sBreplacement for indent from textwrap that is not available in 2.7.RC(R/RR�R5(RSR�R�R:((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR��
scCs
d}x1|j�D]#}|jd�r|d}PqqW|dkrJdS|jd�r]|S|jd�r~d|td�S|jd�r�d|td�j�S|jd�rd	|td�j�}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(	RDR�RLR2R�RIRJRR(R�R1RJt
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(s�Given 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|dt�S(Ntcomments(tshlexR�R(RN((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt_shlex_splitsR�i(R�(R�t	add_emptyt	empty_valR�R9R:RRm((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyR(s		g�?cCs�t|�}d}x�tr�|tg|D]}tjj|�r(|^q(�8}t|�dkr|tjd|||�gS|dkr�tjd|||�n|||kr�Pntj	|�||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(
R�RRIRJRR2R3R�R�tsleep(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
i����R+itrw(R1RR�(RR�t
mount_opts((s2/usr/lib/python2.7/site-packages/cloudinit/util.pytmount_is_read_write;scCsfddg}|r?tjj|�r(dS|jd|g�n|r\|jd|g�nt|�S(sAInvoke udevadm settle with optional exists and timeout parameterstudevadmtsettleNs--exit-if-exists=%ss--timeout=%s(RIRJRR�R(RR�t
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/statR�s Failed to load /proc/%s/stat. %sR�ii(R�RR�R3R4R�R(R�tppidR�R�RK((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt
get_proc_ppidPs(RRRsyes(RRRR(�R�R�RjR�RtR�R:R�RNR_RItos.pathR*R7R�RR�R�R�R�R�R[R�R�RRRtbase64RRtsix.moves.urllibRRgRFt	cloudinitRRtloggingRRR	R
RRtcloudinit.settingsR
t	functoolsRR�RDR�t	getLoggerR�R3R6R�R�R�R�R�R�R�R!R@R)RBRPRTRXRZRdRbRaR�R6tobjectR�R�R�R�R�R�R�R�R�R�R�R�R�R�RR�R�R�tDEBUGRRRR�RRRR"R3RRGRKRRRMRqR|tcontextmanagerR~R�R�R�R�R�R�R7R�R�R�R�R�R�R�R�R�R�R�RRR
RRRR"R�R�R-R�R'R6R?RLRLR�RVRWRXRYR^RfRiRlRrR\RxR�R�R�R�R�R�R�R�R�R�R�RuR�R�R�RR�R�R�R�R,R�R�RRR	RRR R#R%R*R.R1R3R;RRERJRJRWR_RgRiRnRsRwR|RR�R�R(R�R�R�R�(((s2/usr/lib/python2.7/site-packages/cloudinit/util.pyt<module>s�


	
		
U*	
	
			
				4"	3
			# "			(	,					3		
		:									

	(J										&		�	 	-				J				
			#'	'			!	
	*