%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/query.cpython-35.pyc



"�T`��@sdZddlZddlmZddlZddlZddlmZmZddl	m
Z
mZddlm
Z
ddlmZmZmZddlmZd	Ze
je�Zdd
d�Zdd
�Zdd�Zdd�Zedkr�e�dS)aTQuery standardized instance metadata provided to machine, returning a JSON
structure.

Some instance-data values may be binary on some platforms, such as userdata and
vendordata. Attempt to decompress and decode UTF-8 any binary values.

Any binary values in the instance metadata will be base64-encoded and prefixed
with "ci-b64:" in the output. userdata and, where applicable, vendordata may
be provided to the machine gzip-compressed (and therefore as binary data).
query will attempt to decompress these to a string before emitting the JSON
output; if this fails, they are treated as binary.
�N)�EACCES)�convert_jinja_instance_data�render_jinja_payload)�addLogHandlerCLI�read_cfg_paths)�log)�INSTANCE_JSON_FILE�INSTANCE_JSON_SENSITIVE_FILE�REDACT_SENSITIVE_VALUE)�utilZquerycCs'|stjdtdt�}|jddddddd	d
�|jddd
td	dt�|jddddddd	d�|jddd
td	d�|jddd
td	d�|jdd
tddd	d�|jddddddddd	d �|jd!d"d
tdd#d	d$�|S)%a#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.
    �progZdescriptionz-dz--debug�action�
store_true�defaultF�helpz+Add verbose messages during template renderz-iz--instance-data�typez>Path to instance-data.json file. Default is /run/cloud-init/%sz-lz--list-keyszBList query keys available at the provided instance-data <varname>.z-uz--user-datazHPath to user-data file. Default is /var/lib/cloud/instance/user-data.txtz-vz
--vendor-datazLPath to vendor-data file. Default is /var/lib/cloud/instance/vendor-data.txt�varname�nargs�?z�A dot-delimited specific variable to query from instance-data. For example: v1.local_hostname. If the value is not JSON serializable, it will be base64-encoded and will contain the prefix "ci-b64:". z-az--all�dest�dump_allz Dump all available instance-dataz-fz--format�formatz�Optionally specify a custom output format string. Any instance-data variable can be specified between double-curly braces. For example -f "{{ v2.cloud_name }}")�argparse�ArgumentParser�NAME�__doc__�add_argument�strr)�parser�r�5/usr/lib/python3/dist-packages/cloudinit/cmd/query.py�
get_parser!s:		r!cCsXtj|dd�}y|jd�SWn+tk
rStj|dddd�SYnXdS)z�Attempt to return a string of user-data from ud_file_path

    Attempt to decode or decompress if needed.
    If unable to decode the content, raw bytes will be returned.

    @returns: String of uncompressed userdata if possible, otherwise bytes.
    �decodeFzutf-8�quietTN)r�	load_filer"�UnicodeDecodeErrorZdecomp_gzip)Zud_file_pathZbdatarrr �
load_userdataQs

r&cCs�d}tt|jrtjntj�t|j|j|j	|j
g�sjtjd�t�j
�dStj�}t|j|j|jg�s�t�}|jr�|j}nytjj|jt�}|dkr%tjj|jt�}tjj|�r	|}q+tjd||�|}n|}|jr@|j}ntjj|jd�}|jrm|j}ntjj|jd�}ytj|�}	Wnatt fk
r�}
z;|
j!t"kr�tjd|�ntjd	|�dSWYdd}
~
XnXtj#|	�}|dkrBd
t$|f|d<d
t$|f|d<n t%|�|d<t%|�|d<|j	r�d
j	d|j	�}t&d|ddd|d|jr�dnd�}
|
r�t'|
�dSdSt(|�}|jr~y+x$|jj)d�D]}||}q�WWn)t*k
r3tjd|j�dSYnX|jr�t+|t,�s`tjd|�dSdjt-|j.���}n$|jr�djt-|j.���}t+|t/�s�tj0|�}t'|�dS)z3Handle calls to 'cloud-init query' as a subcommand.NzDExpected one of the options: --all, --format, --list-keys or varname�rz4Missing root-readable %s. Using redacted %s instead.z
user-data.txtzvendor-data.txtz$No read permission on '%s'. Try sudozMissing instance-data file: %sz<%s> file:%sZuserdataZ
vendordataz## template: jinja
{fmt}Zfmt�payloadZ
payload_fnzquery commandline�
instance_data�debugTF�.zUndefined instance-data key %sz+--list-keys provided but '%s' is not a dict�
)1r�LOGr*r�DEBUGZWARNING�anyZ	list_keysrrr�errorr!Z
print_help�os�getuid�allr)Z	user_dataZvendor_datar�path�joinZrun_dirrr	�existsZwarningZ
instance_linkrr$�IOError�OSError�errnorZ	load_jsonr
r&r�printr�split�KeyError�
isinstance�dict�sorted�keysrZ
json_dumps)�name�args�pathsZuidZinstance_data_fnZredacted_data_fnZsensitive_data_fnZuser_data_fnZvendor_data_fnZ
instance_json�er)r(Zrendered_payloadZresponse�varrrr �handle_args`s�"$
				
				
	
			
rFcCs)t�}tjtt|j���dS)z,Tool to query specific instance-data values.N)r!�sys�exitrFr�
parse_args)rrrr �main�s	rJ�__main__)rrr9rr1rGZ!cloudinit.handlers.jinja_templaterrZcloudinit.cmd.develrrZ	cloudinitrZcloudinit.sourcesrr	r
rrZ	getLoggerr-r!r&rFrJ�__name__rrrr �<module>s"0Z

Zerion Mini Shell 1.0