fUddlZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZddlmZmZmZmZdd lmZmZeeed < dd lmZdd lm Z ejFe$Z%GddeZ&GddeZ'Gdde jPZ) ddZ*ddZ+de,dee,fdZ- ddZ.y#e!$reZejDd Z YrwxYw)N)EACCES)OptionalType)handlers)b64d json_dumps)Paths) PER_ALWAYS)MISSING_JINJA_PREFIXJinjaSyntaxParsingExceptiondetect_template render_string) load_jsonload_text_fileJUndefinedError)UndefinedError) operator_rez[-.]c eZdZy)JinjaLoadErrorN__name__ __module__ __qualname__C/usr/lib/python3/dist-packages/cloudinit/handlers/jinja_template.pyrr"rrc eZdZy) NotJinjaErrorNrrrrrr&rrrc$eZdZdgZdefdZdZy)JinjaTemplatePartHandlerz## template: jinjapathsc tjj|td||_i|_|j dgD]&}|jD]}||j |<(y)N)version sub_handlers)rHandler__init__r r"r&get list_types)selfr"_kwargshandlerctypes rr(z!JinjaTemplatePartHandler.__init__.sn!!$ A!> {{>26 3G ++- 3+2!!%( 3 3rc|tjvry|jjd} t |||}|sytj|} |jj| } | st jd|| y| jdk(r| j||||||y| jdk(r| j|||||yy#t $r*} t jd|t| Yd} ~ yd} ~ wwxYw)Ninstance_data_sensitivez=Ignoring jinja template for %s. Failed to render template. %szPIgnoring jinja template for %s. Could not find supported sub-handler for type %sr$)rCONTENT_SIGNALSr" get_runpathrender_jinja_payload_from_filer LOGwarningstrtype_from_starts_withr&r)handler_version handle_part) r+datar.filenamepayload frequencyheadersjinja_json_filerendered_payloadesubtype sub_handlers rr:z$JinjaTemplatePartHandler.handle_part6s H,, , **001JK =?   001AB''++G4  KK+     & &! +  # #eX'7G  ( (A -  # #eX'7 .3+  KK0A    s C D  DD N)rrrprefixesr r(r:rrrr!r!*s$%H3e3$rr!ct|ddk7r tdi}d}tjj |st d|z t t|}t||||}|sy|S#t$rA}d}t|ttfr|jtk(rd|z}t ||d}~wwxYw)aRRender a jinja template payload sourcing variables from jinja_vars_path. @param payload: String of jinja template content. Should begin with ## template: jinja . @param payload_fn: String representing the filename from which the payload was read used in error reporting. Generally in part-handling this is 'part-##'. @param instance_data_file: A path to a json file containing variables that will be used as jinja template variables. @return: A string of jinja-rendered content with the jinja header removed. Returns None on error. rjinjazPayload is not a jinja templateNzFCannot render jinja template vars. Instance data not yet present at %sz"Loading Jinja instance data failedzGCannot render jinja template vars. No read permission on '%s'. Try sudo)r rospathexistsrrr Exception isinstanceIOErrorOSErrorerrnorrender_jinja_payload)r= payload_fninstance_data_filedebug instance_datarArBmsgs rr4r4]s w"g-=>>M 77>>, - 1 2   )!.1C"DE ,]E   )2 a'7+ ,ww& &(:;S!q()sA66 C?rs  !4#) 5i &C( g! Y  I 0x//0h49*Z< ,DI G&O"**W%K&s B::CC