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

ó
oBú]c
@s†ddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZeje
ƒZdZied	6Zd5Zd
ZdZidd6Zdefd„ƒYZde	jfd„ƒYZd„Zd„Zdd„Zded„Zd„Zee	j e	j!ffgZ"d„Z#e
dkr‚ddl$Z$ddl%Z%ddlm&Z&e$j'ddƒZ(e(j)dd d!d"d#d$eƒe(j)d%d&d'd"d(d)d*d$eƒe(j*ƒZ+ed+e+j,d'e+j-ƒZ.d,e.kr_ye.d,j/ƒe.d,<Wq_e0k
r[e%j1j2d-ƒe.d,=e&e.d,ƒj/ƒe.d.<q_Xnej3e.d/d0d1ed2d6ƒGHndS(7iÿÿÿÿN(t	b64decode(tug_util(tlog(tsources(t
url_helper(tutils3http://metadata.google.internal/computeMetadata/v1/tmetadata_urlsinstance-idsavailability-zoneslocal-hostnamesLhttp://metadata.google.internal/computeMetadata/v1/instance/guest-attributesthostkeystGooglesMetadata-FlavortGoogleMetadataFetchercBseZd„Zed„ZRS(cCs
||_dS(N(tmetadata_address(tselfR
((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt__init__sc	CsÍd}y<|j|}|r)|d7}ntjd|dtƒ}Wn/tjk
rs}d}tj|||ƒnVX|jdkr³|ržt	j
|jƒ}qÉ|jjdƒ}ntjd||jƒ|S(Ns/?recursive=Trueturltheaderssurl %s raised exception %siÈsutf-8surl %s returned code %s(
tNoneR
RtreadurltHEADERStUrlErrortLOGtdebugtcodeRt
decode_binarytcontentstdecode(	Rtpathtis_texttis_recursivetvalueR
tresptexctmsg((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt	get_value s

(t__name__t
__module__RtFalseR (((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyR	s	t
DataSourceGCEcBszeZdZd„Zd„Zed„ƒZd„Zd„Zd„Z	e
e
e
d„Zed„ƒZed	„ƒZ
RS(
tGCEcCs¨tjj||||ƒd|_|r[tj||ƒ\}}tj|ƒ\|_}ntƒ|_	t
jt
j|ddgiƒt
gƒ|_|jd|_dS(Nt
datasourceR%R(Rt
DataSourceRRtdefault_userRtnormalize_users_groupstextract_defaulttdicttmetadataRt
mergemanydicttget_cfg_by_pathtBUILTIN_DS_CONFIGtds_cfgR
(Rtsys_cfgtdistrotpathstuserst_groupst_user_config((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyR9s	cCsƒtjtjdtdi|jd6ƒ}|dse|drPtj|dƒntj|dƒtS|d|_|d|_	t
S(	NsCrawl of GCE metadata servicetkwargstaddresstsuccesstplatform_reports_gcetreasons	meta-datas	user-data(Rtlog_timeRRtread_mdR
twarningR#R,tuserdata_rawtTrue(Rtret((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt	_get_dataEs	



cCsdS(N(R(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytlaunch_indexTscCs|jdS(Nsinstance-id(R,(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytget_instance_idYscCs|jd}t||jƒS(Nspublic-keys-data(R,t_parse_public_keysR((Rtpublic_keys_data((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytget_public_ssh_keys\s
cCsx|D]}t|ŒqWdS(N(t#_write_host_key_to_guest_attributes(RRtkey((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytpublish_host_keys`s
cCs|jdjdƒdS(Nslocal-hostnamet.i(R,tsplit(Rtfqdnt
resolve_ipt
metadata_only((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytget_hostnamedscCs|jdS(Nsavailability-zone(R,(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytavailability_zonehscCs|jjddƒdS(Nt-ii(RQtrsplit(R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytregionls(R!R"tdsnameRRBtpropertyRCRDRGRJR#RPRQRT(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyR$5s					cCsdtt|f}|jdƒ}tjd|d|dtdddtƒ}|jƒrktj	d	|ƒntj	d
|ƒdS(Ns%s/%s/%ssutf-8R
tdataRtrequest_methodtPUTtcheck_statuss&Wrote %s host key to guest attributes.s0Unable to write %s host key to guest attributes.(
tGUEST_ATTRIBUTES_URLtHOSTKEY_NAMESPACEtencodeRRRR#tokRR(tkey_typet	key_valueR
R((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyRHqscCsÔy |jddƒd\}}Wnttfk
r:tSX|dkrKtSytj|ƒ}Wntk
rrtSXd|krƒtS|d}d}ytjj||ƒ}Wntk
rÀtSXtjj	ƒ|kS(Niis
google-sshtexpireOns%Y-%m-%dT%H:%M:%S+0000(
RLRt
ValueErrortAttributeErrorR#tjsontloadstdatetimetstrptimetutcnow(t
public_keytschematjson_strtjson_objt
expire_strt
format_strtexpire_time((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt_has_expired|s& 


cCs®g}|s|Sx—|D]}|std„|DƒƒrAqn|jddƒ}t|ƒdkrkqn|\}}|d|fkrt|ƒr|j|ƒqqW|S(Ncss!|]}t|ƒdkVqdS(i€N(tord(t.0tc((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pys	<genexpr>§st:iit	cloudinit(tallRLtlenRptappend(RFR(tpublic_keysRitsplit_public_keytuserRI((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyREžs
c
Cs5|dkrt}nidd6dd6td6dd6}tƒ|d<|rc|drcd|d<|Stj|ƒs”tjd|ƒd||d<|Sd	d"tttfdd#tttfd
d$tttfdd%tttfdd&tttfg}t	|ƒ}i}x’|D]Š\}}}}	}
d}x8|D]0}|j
||	|
ƒ}
|
dk	r/|
}q/q/W|r|dkrd}|||d<|S|||<q
Wtj|dp®dƒ}tj|dpÇdƒ}|j
dƒ|j
dƒg}|j
ddƒjƒ}|dkrN|j
dƒrN|j|j
dƒƒ|j|j
dƒƒndjg|D]}|r[|^q[ƒ}|jƒ|d<|dr®|djdƒd|d<nd|kr|djdƒ}|j
dƒ}|d kr÷t|ƒ}n|rtjd!|ƒn||d<n||d<t|d<|S('Ns	meta-datas	user-dataR9R;R:sNot running on GCE.s%s is not resolvablesaddress "%s" is not resolvablesinstance-idsinstance/idsavailability-zones
instance/zoneslocal-hostnamesinstance/hostnames
instance-datasinstance/attributessproject-datasproject/attributess)required key %s returned nothing. not GCEs{}tsshKeyssssh-keyssblock-project-ssh-keystttrues
spublic-keys-datat/iÿÿÿÿsutf-8suser-data-encodingtbase64s(unknown user-data-encoding: %s, ignoring(sinstance/id(s
instance/zone(sinstance/hostname(sinstance/attributes(sproject/attributes(Rt	MD_V1_URLR#R:Rtis_resolvable_urlRRR@R	R RdRetgettlowerRxtjoint
splitlinesRLR]RR>(R8tplatform_checkRAturl_maptmetadata_fetchertmdtmkeyR3trequiredRRRRt	new_valueRt
instance_datatproject_datat
valid_keyst
block_projectRIRFtudtencoding((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyR=²sh	



(



cCsdtjdƒpd}|dkr%tStjdƒp7d}|jdƒrMtStjd||ƒtS(Nssystem-product-namesN/AsGoogle Compute Enginessystem-serial-numbersGoogleCloud-s6Not running on google cloud. product-name=%s serial=%s(Rt
read_dmi_dataR@t
startswithRRR#(tpnametserial((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyR:ús	
cCstj|tƒS(N(Rtlist_from_dependstdatasources(tdepends((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pytget_datasource_listst__main__(t	b64encodetdescriptionsQuery GCE Metadata Services
--endpointtmetavartURLthelps The url of the metadata service.tdefaults--no-platform-checktdestR‡sIgnore smbios platform checktactiontstore_falseR8s	user-datas/User-data cannot be decoded. Writing as base64
s
user-data-b64tindentit	sort_keyst
separatorst,s: (sinstance-idsavailability-zoneslocal-hostname(R©s: (4RfRdR€Rtcloudinit.distrosRRuRtloggingRRRt	getLoggerR!RRR/tREQUIRED_FIELDSR[R\RtobjectR	R'R$RHRpRRER@R=R:tDEP_FILESYSTEMtDEP_NETWORKR™R›targparsetsysRtArgumentParsertparsertadd_argumentt
parse_argstargstendpointR‡RWRtUnicodeDecodeErrortstderrtwritetdumps(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt<module>sX

<		"H		

!
Back to Directory File Manager