
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼me£  ã               @   s„   d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZ ddlmZ dZddd	„Zd
d„ Zdd„ Zedkr€eƒ  dS )zCCommandline utility to list the canonical cloud-id for an instance.é    N)Úread_cfg_paths)ÚUXAppStatusÚget_status_details)ÚMETADATA_UNKNOWNÚcanonical_cloud_id)Úerrorzcloud-idc             C   sd   t ƒ jdƒ}| stjtdd�} | jdddddd	� | jd
ddddd	� | jddt|d|› �d� | S )a*  Build or extend an arg parser for the cloud-id 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.
    Úinstance_dataz/Report the canonical cloud-id for this instance)ÚprogÚdescriptionz-jz--jsonÚ
store_trueFz5Report all standardized cloud-id information as json.)ÚactionÚdefaultÚhelpz-lz--longz=Report extended cloud-id information as tab-delimited string.z-iz--instance-dataz,Path to instance-data.json file. Default is )Útyper   r   )r   Zget_runpathÚargparseÚArgumentParserÚNAMEÚadd_argumentÚstr)ÚparserZdefault_instance_json© r   ú/usr/lib/python3.6/cloud_id.pyÚ
get_parser   s0    	r   c       	      C   sX  t ƒ }|jtjkr,tjjdj|jjƒƒ dS |jtj	krRtjjdj|jjƒƒ dS y$t
|jƒ�}tj|ƒ}W dQ R X W nJ tk
r”   td|j ƒS  tk
rÀ } ztd|j|f ƒS d}~X nX |jdi ƒ}t|jdtƒ|jd	tƒ|jd
tƒƒ}|j�r"tjjdƒ ||d< tj|dddd�}n"|j�r@d||jd	tƒf }n|}tjjd| ƒ dS )z¸Handle calls to 'cloud-id' cli.

    Print the canonical cloud-id on which the instance is running.

    @return: 0 on success, 1 on error, 2 on disabled, 3 on cloud-init not run.
    z{0}
é   é   NzTFile not found '%s'. Provide a path to instance data json file using --instance-datazFile '%s' is not valid json. %sÚv1Z
cloud_nameZregionÚplatformz%DEPRECATED: Use: cloud-init query v1
Úcloud_idé   Tú,ú: )ÚindentZ	sort_keysZ
separatorsz%s	%sz%s
r   )r   r    )r   Zstatusr   ZDISABLEDÚsysÚstdoutÚwriteÚformatÚvalueZNOT_RUNÚopenr   ÚjsonÚloadÚIOErrorr   Ú
ValueErrorÚgetr   r   ÚstderrÚdumpsZlong)	ÚnameÚargsZstatus_detailsÚfiler   Úer   r   Zresponser   r   r   Úhandle_args=   s@    


r3   c              C   s   t ƒ } tjtt| jƒ ƒƒ dS )z,Tool to query specific instance-data values.N)r   r"   Úexitr3   r   Ú
parse_args)r   r   r   r   Úmainl   s    r6   Ú__main__)N)Ú__doc__r   r(   r"   Zcloudinit.cmd.develr   Zcloudinit.cmd.statusr   r   Zcloudinit.sourcesr   r   Zcloudinit.utilr   r   r   r3   r6   Ú__name__r   r   r   r   Ú<module>   s   
*/