Current File : //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�|dkr�d}|||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!RR�R/tREQUIRED_FIELDSR[R\RtobjectR	R'R$RHRpRRER@R=R:tDEP_FILESYSTEMtDEP_NETWORKR�R�targparsetsysR�tArgumentParsertparsertadd_argumentt
parse_argstargstendpointR�RWRtUnicodeDecodeErrortstderrtwritetdumps(((sC/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceGCE.pyt<module>sX

<		"H		

!