a 'Dg}& @sddlZddlZddlZddlmZmZmZddlmZm Z m Z e e Z dZdZdZdZeegZdgZd Zd Zd d d dddddddddd ZeeedddZGdddejdZddZdd Zd!d"Zd#d$Z d%d&Z!d'd(Z"d)d*Z#d+d,Z$e fd-d.Z%d1d/d0Z&dS)2N)importer type_utilsutil) FREQUENCIES PER_ALWAYS PER_INSTANCEztext/x-not-multipartzapplication/octet-streamZ__end__Z __begin__ztext/part-handlerzpart-handler-%03dz part-%03dztext/x-include-urlztext/x-include-once-urlztext/x-shellscriptztext/cloud-configztext/cloud-boothookztext/cloud-config-archiveztext/cloud-config-jsonpz text/jinja2text/x-shellscript-per-boottext/x-shellscript-per-instancetext/x-shellscript-per-once) z#includez #include-oncez#!z #cloud-configz #part-handlerz#cloud-boothookz#cloud-config-archivez#cloud-config-jsonpz## template: jinjarr r cCs dt|S)Nr)len)er ?/usr/lib/python3.9/site-packages/cloudinit/handlers/__init__.py>r)keyc@s4eZdZd ddZddZddZejdd Zd S) HandlercCs||_||_dSN)handler_version frequency)selfrversionr r r__init__CszHandler.__init__cCsdt||fS)Nz%s: [%s])rZobj_name list_typesrr r r__repr__GszHandler.__repr__cCs,t|dstdnddt|dDSdS)Nprefixesz#Missing prefixes subclass attributecSsg|] }t|qSr )INCLUSION_TYPES_MAP).0prefixr r r Osz&Handler.list_types..)hasattrNotImplementedErrorgetattrrr r rrJs   zHandler.list_typescOs tdSr)r#)rargskwargsr r r handle_partTszHandler.handle_partN)r) __name__ __module__ __qualname__rrrabcabstractmethodr'r r r rrBs   r) metaclassc Cs|j}|tks"|tkr|tks"dSz|j}t|}WntttfyPd}Yn0|d}zxt d||||||dkr| ||||||nB|dkr| |||||n&|dkr| ||||n td|Wn(t yt td|||||Yn0dS)N Content-Typez1Calling handler %s (%s, %s, %s) with frequency %srzUnknown module version %sz8Failed calling handler %s (%s, %s, %s) with frequency %s)rrrrint TypeError ValueErrorAttributeErrorLOGdebugr' Exceptionrlogexc) moddatafilenamepayloadrheadersZmod_freqZmod_ver content_typer r rrun_partYsT    r?cCsdti}t||dd||dSNr/) CONTENT_STARTr?r9r:rr=r r r call_beginsrCcCsdti}t||dd||dSr@) CONTENT_ENDr?rBr r rcall_endsrEc Cs|d}t|}|d}tj|dd|}|ds@d|}t||d|d}zrFr[detailsr r rwalker_callbacks@   rgc Csd}|D]t}|dkrq |}|dur2t}|}|sFt|}t|}t|||d<t |}||||||d}q dS)NrZ multipartr/r.) walkZget_content_maintypeZget_content_type OCTET_TYPE get_filename PART_FN_TPLdictr5r6rZfully_decoded_payload) msgcallbackr:ZpartnumpartZctyper;r=r<r r rrhs     rhcCsRt|dst|ddt|ds.t|d|n |j}|rN|tvrNtd|||S)Nrr.rz&Handler %s has an unknown frequency %s)r"setattrrrr5re)r9Zdef_freqZfreqr r rrLs    rLcCsVzt|}Wnty(|YS0|}tD]}||r6t|Sq6|Sr)rZ decode_binarylowerrYlstripINCLUSION_SRCH startswithr)r<defaultZ payload_lcr_r r rtype_from_starts_with#s   rv)N)'r+ZloggingrHZ cloudinitrrrZcloudinit.settingsrrrZ getLoggerr(r5rdrirDrAZCONTENT_SIGNALSrcrGrkrsortedlistkeysrsABCMetarr?rCrErPr\r`rgrhrLrvr r r r sP 0)