o
    x[há  ã                   @   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
 ddlmZmZ dZddd	„Zd
d„ Zdd„ ZedkrBeƒ  dS dS )zCCommandline utility to list the canonical cloud-id for an instance.é    N)Úread_cfg_paths)ÚRunningStatusÚget_status_details)Úlog_util)ÚMETADATA_UNKNOWNÚcanonical_cloud_idzcloud-idc                 C   sd   t ƒ  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   Úget_runpathÚargparseÚArgumentParserÚNAMEÚadd_argumentÚstr)ÚparserÚdefault_instance_json© r   ú8/usr/lib/python3/dist-packages/cloudinit/cmd/cloud_id.pyÚ
get_parser   s<   	þûûÿú
r   c           	   
   C   sv  t ƒ }|jtjkrtj d |jj¡¡ dS |jtj	kr)tj d |jj¡¡ dS zt
|jƒ�}t |¡}W d  ƒ n1 s?w   Y  W n, tyV   t d|j ¡ Y S  tyq } zt d|j|f ¡W  Y d}~S d}~ww | di ¡}t| dt¡| d	t¡| d
t¡ƒ}|jr¡tj d¡ ||d< tj|dddd�}n|jr¯d|| d	t¡f }n|}t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Úv1Ú
cloud_nameÚregionÚplatformz%DEPRECATED: Use: cloud-init query v1
Úcloud_idé   T)ú,z: )ÚindentÚ	sort_keysÚ
separatorsz%s	%sz%s
r   )r   Úrunning_statusr   ÚDISABLEDÚsysÚstdoutÚwriteÚformatÚvalueÚNOT_STARTEDÚopenr   ÚjsonÚloadÚIOErrorr   ÚerrorÚ
ValueErrorÚgetr   r   ÚstderrÚdumpsÚlong)	ÚnameÚargsÚstatus_detailsÚfiler   Úer   r!   Úresponser   r   r   Úhandle_args=   sR   ÿ€ÿÿÿ€ÿ


ýÿr?   c                  C   s   t ƒ } t tt|  ¡ ƒ¡ dS )z,Tool to query specific instance-data values.N)r   r)   Úexitr?   r   Ú
parse_args)r   r   r   r   Úmainl   s   rB   Ú__main__)N)Ú__doc__r   r0   r)   Úcloudinit.cmd.develr   Úcloudinit.cmd.statusr   r   Úcloudinit.logr   Úcloudinit.sourcesr   r   r   r   r?   rB   Ú__name__r   r   r   r   Ú<module>   s   
*/
ÿ