ó ƒjbc @s/ddlZddlZddlmZddlmZddlmZejeƒZ e ej gƒZ de fd„ƒYZde fd„ƒYZd „Zd d dd d dddd „Zd d dd d ddddd„ Zd d dd d ddddd„ Zd d dd d ddddd„ ZdS(iÿÿÿÿN(tlog(t url_helper(tutiltMetadataLeafDecodercBs eZdZd„Zd„ZRS(s.Decodes a leaf blob into something meaningful.cCs<|s tS|jƒ}|jdƒr8|jdƒr8tStS(Nt{t}(tFalsetstript startswithtendswithtTrue(tselfttext((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyt_maybe_json_objects  cCs§|s dSytj|ƒ}Wntk r1|SX|j|ƒr„ytj|ƒSWq„ttfk r€}tj d||ƒq„Xn|j dƒdkr£|j ƒS|S(Nts6Field %s looked like a json object, but it was not: %ss iÿÿÿÿ( Rt decode_binarytUnicodeDecodeErrorR tjsontloadst ValueErrort TypeErrortLOGtwarningtfindt splitlines(R tfieldtblobte((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyt__call__s   (t__name__t __module__t__doc__R R(((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyRs tMetadataMaterializercBs/eZdd„Zd„Zd„Zd„ZRS(cCsL||_d|_||_||_|dkr?tƒ|_n ||_dS(N(t_blobtNonet_mdt _base_urlt_callerRt _leaf_decoder(R Rtbase_urltcallert leaf_decoder((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyt__init__5s     c Cs8i}g}tj|ƒ}|s+||fSd„}d„}xî|jƒD]à}|jƒ}||ƒ}| sJ| r|qJn|dkrŽqJn||ƒr¹||kr*|j|ƒq*qJ|jddƒ}|} t|ƒdkr |\} } tj| ƒ} | dk r d| } | }q n| ||R=(((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyR 4s + cCs |j|kS(s/Returns False if cause.code is in status_codes.(tcode(t status_codest _request_argstcause((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pytskip_retry_on_codes‰stlatestshttp://169.254.169.254ic Csêtj||ƒ}tj|dƒ}d} y[|sHtjttƒ}ntj|d|d|d|d|d|d|ƒ} | j} Wn^tjk rÂ} | j tkræt j t d |ƒqæn$t k råt j t d |ƒnX| S( Ns user-dataRt ssl_detailsttimeouttretriest exception_cbt headers_cbtheaders_redacts$Failed fetching userdata from url %s(RR?t functoolstpartialROtSKIP_USERDATA_CODEStread_file_or_urlR8tUrlErrorRKRtlogexcRt Exception( t api_versiontmetadata_addressRQRRRSRURVRTtud_urlt user_datatresponseR((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pytget_instance_userdataŽs$     c sÜtj|||ƒ} tjtjd|d|d|d|d|d| ƒ‰‡fd†} ySˆ| ƒ} t| j| | d|ƒ} | jƒ}t|t ƒs¨i}n|SWn(t k r×t j t d || ƒiSXdS( NRQRRRSRURVRTcs ˆ|ƒjS(N(R8(turl(R((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pytmcaller·sR)sFailed fetching %s from url %s(RR?RWRXRZR R8R>t isinstancetdictR]RR\R(ttreeR^R_RQRRRSR)RURVRTtmd_urlReRbt materializertmd((R(s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyt_get_instance_metadataªs&        c CsCtddd|d|d|d|d|d|d |d |d |ƒ S( NRhs meta-data/R^R_RQRRRSR)RVRURT(Rl( R^R_RQRRRSR)RURVRT((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pytget_instance_metadataÈs  c CsCtddd|d|d|d|d|d|d |d |d |ƒ S( NRhsdynamic/instance-identityR^R_RQRRRSR)RVRURT(Rl( R^R_RQRRRSR)RURVRT((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pytget_instance_identityÙs   (RWRt cloudinitRtloggingRRt getLoggerRRt frozensett NOT_FOUNDRYtobjectRR ROR"RcRlRmRn(((s7/usr/lib/python2.7/site-packages/cloudinit/ec2_utils.pyt s@   U