o
    f                     @   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rBe  dS dS )zCCommandline utility to list the canonical cloud-id for an instance.    N)read_cfg_paths)RunningStatusget_status_details)METADATA_UNKNOWNcanonical_cloud_id)errorz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   sr  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yU   td|j  Y S  tyo } ztd|j|f W  Y d}~S d}~ww |di }t|dt|d	t|d
t}|jrtjd ||d< tj|dddd}n|jrd||d	tf }n|}tjd|  dS )zHandle 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   
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   rA   __main__)N)__doc__r   r0   r)   cloudinit.cmd.develr   cloudinit.cmd.statusr   r   cloudinit.sourcesr   r   cloudinit.utilr   r   r   r>   rA   __name__r   r   r   r   <module>   s   
*/
