ó oBú]c@sûdZddlZddlmZddlZddlZddlZddlmZm Z ddl m Z m Z ddl mZddlmZmZmZddl mZd ZejeƒZdd „Zd „Zd „Zed kr÷eƒndS(s;Query standardized instance metadata from the command line.iÿÿÿÿN(tEACCES(tconvert_jinja_instance_datatrender_jinja_payload(taddLogHandlerCLItread_cfg_paths(tlog(tINSTANCE_JSON_FILEtINSTANCE_JSON_SENSITIVE_FILEtREDACT_SENSITIVE_VALUE(tutiltqueryc Cs*|s!tjdtddƒ}n|jdddddtd d ƒ|jd d d td dtƒ|jdddddtd dƒ|jddd td dƒ|jddd td dƒ|jdd tddd dƒ|jdddddtddd d ƒ|jd!d"d tdd#d d$ƒ|S(%s#Build or extend an arg parser for query utility. @param parser: Optional existing ArgumentParser instance representing the query subcommand which will be extended to support the args of this utility. @returns: ArgumentParser with proper argument configuration. tprogt descriptionsQuery cloud-init instance datas-ds--debugtactiont store_truetdefaultthelps+Add verbose messages during template renders-is--instance-datattypes>Path to instance-data.json file. Default is /run/cloud-init/%ss-ls --list-keyssBList query keys available at the provided instance-data .s-us --user-datasHPath to user-data file. Default is /var/lib/cloud/instance/user-data.txts-vs --vendor-datasLPath to vendor-data file. Default is /var/lib/cloud/instance/vendor-data.txttvarnametnargst?shA dot-delimited instance data variable to query from instance-data query. For example: v2.local_hostnames-as--alltdesttdump_alls Dump all available instance-datas-fs--formattformatsŸOptionally specify a custom output format string. Any instance-data variable can be specified between double-curly braces. For example -f "{{ v2.cloud_name }}"(targparsetArgumentParsertNAMEt add_argumenttFalsetstrR(tparser((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/query.pyt get_parsers:  c CsÀd}tt|jrtjntjƒt|j|j |j |j gƒsjtj dƒt ƒjƒdStjƒ}t|j|j|jgƒs tƒ}n|jrµ|j}nytjj|jtƒ}|dkr(tjj|jtƒ}tjj|ƒr |}q.tjd||ƒ|}n|}|jrC|j}ntjj|jdƒ}|jrp|j}ntjj|jdƒ}ytj|ƒ} WnLt t!fk ré} | j"t#krÕtj d|ƒntj d|ƒdSXtj$| ƒ} |dkr0d t%|f| d file:%stuserdatat vendordatas## template: jinja {fmt}tfmttpayloadt payload_fnsquery commandlinet instance_datatdebugt.sUndefined instance-data key %ss+--list-keys provided but '%s' is not a dicts N(3tNoneRtLOGR&RtDEBUGtWARNINGtanyt list_keysRRRterrorRt print_helptostgetuidtallR%t user_datat vendor_dataRtpathtjointrun_dirRRtexiststwarningt instance_linkR t load_filetIOErrortOSErrorterrnoRt load_jsonRRtTrueRRtsplittKeyErrort isinstancetdicttsortedtkeystsixt string_typest json_dumps(tnametargstpathstuidtinstance_data_fntredacted_data_fntsensitive_data_fnt user_data_fntvendor_data_fnt instance_jsonteR%R#trendered_payloadtresponsetvar((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/query.pyt handle_argsEsŽ"$                     ! cCs)tƒ}tjtt|jƒƒƒdS(s,Tool to query specific instance-data values.N(RtsystexitRXRt parse_args(R((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/query.pytmainžs t__main__(t__doc__RR>RR0RGRYt!cloudinit.handlers.jinja_templateRRtcloudinit.cmd.develRRt cloudinitRtcloudinit.sourcesRRRR Rt getLoggerR)R(RRXR\t__name__(((s7/usr/lib/python2.7/site-packages/cloudinit/cmd/query.pyts"     . Y