3 \me @sdZddlZddlZddlZddlmZddlmZmZddl m Z m Z ddl m Z dZddd Zd d Zd d ZedkredS)zCCommandline utility to list the canonical cloud-id for an instance.N)read_cfg_paths) UXAppStatusget_status_details)METADATA_UNKNOWNcanonical_cloud_id)errorzcloud-idcCsdtjd}|stjtdd}|jdddddd |jd d ddd d |jd dt|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.)actiondefaulthelpz-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)rZ get_runpathargparseArgumentParserNAME add_argumentstr)parserZdefault_instance_jsonr/usr/lib/python3.6/cloud_id.py get_parsers0 rc CsXt}|jtjkr,tjjdj|jjdS|jtj krRtjjdj|jjdSy$t |j }t j |}WdQRXWnJtk rtd|j Stk r}ztd|j |fSd}~XnX|jdi}t|jdt|jd t|jd t}|j r"tjjd ||d <t j|d ddd}n"|jr@d||jd tf}n|}tjjd|dS)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-datazFile '%s' is not valid json. %sv1Z cloud_nameZregionplatformz%DEPRECATED: Use: cloud-init query v1 cloud_idT,: )indentZ sort_keysZ separatorsz%s %sz%s r)rr )rZstatusrZDISABLEDsysstdoutwriteformatvalueZNOT_RUNopenrjsonloadIOErrorr ValueErrorgetrrstderrdumpsZlong) nameargsZstatus_detailsfilererrZresponserrr handle_args=s@        r3cCst}tjtt|jdS)z,Tool to query specific instance-data values.N)rr"exitr3r parse_args)rrrrmainlsr6__main__)N)__doc__rr(r"Zcloudinit.cmd.develrZcloudinit.cmd.statusrrZcloudinit.sourcesrrZcloudinit.utilrrrr3r6__name__rrrrs   */