oB]c@sdZddlZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z mZmZdZdZd Zd Zd Zd Zdd ZdZdZdZdZedkrendS(sFDefine 'status' utility and handler as part of cloud-init commandline.iN(tgmtimetstrftimetsleep(t uses_systemd(tInit(t get_cmdlinet load_filet load_jsons/etc/cloud/cloud-init.disabledsnot runtrunningtdoneterrortdisabledc Csi|s!tjdddd}n|jddddd td d |jd d ddd td d|S(s%Build or extend an arg parser for status utility. @param parser: Optional existing ArgumentParser instance representing the status subcommand which will be extended to support the args of this utility. @returns: ArgumentParser with proper argument configuration. tprogtstatust descriptionsReport run status of cloud inits-ls--longtactiont store_truetdefaultthelpsJReport long format of statuses including run stage name and error messagess-ws--waits'Block waiting on cloud-init to complete(targparsetArgumentParsert add_argumenttFalse(tparser((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pyt get_parsers   cCstdg}|jt|j\}}}|jrxU|ttfkrtjj dtjj t|j\}}}t dq=Wtjj dn|j rdj |GH|rdj |GHndj |GHndj |GH|tkrdSd S( s4Handle calls to 'cloud-init status' as a subcommand.tds_depst.g?s s status: {0}s time: {0}s detail: {0}ii(Rtread_cfgt_get_status_detailstpathstwaittSTATUS_ENABLED_NOT_RUNtSTATUS_RUNNINGtsyststdouttwritetflushRtlongtformatt STATUS_ERROR(tnametargstinitR t status_detailttime((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pythandle_status_args1s"    cCst}tj}ts'd}nd|kr<d}n~tjj|rft}dj|}nTd|krt}d}n9tjjtjj |j dst}d}nd }||fS( sReport whether cloud-init is disabled. @param disable_file: The path to the cloud-init disable file. @param paths: An initialized cloudinit.helpers.Paths object. @returns: A tuple containing (bool, reason) about cloud-init's status and why. sCloud-init enabled on sysvinitscloud-init=enableds<Cloud-init enabled by kernel command line cloud-init=enabledsCloud-init disabled by {0}scloud-init=disableds;Cloud-init disabled by kernel parameter cloud-init=disabledtenableds+Cloud-init disabled by cloud-init-generators2Cloud-init enabled by systemd cloud-init-generator( RRtsplitRtostpathtexiststTrueR&tjointrun_dir(t disable_fileRt is_disabledt cmdline_partstreason((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pyt_is_cloudinit_disabledIs"      $ cCs5t}d}i}tjj|jd}tjj|jd}tt|\}}|rlt}|}ntjj|rtjj|st }nt t |j di}ng}d} xt |jD]\} } | dkr| rt }dj| }qq| dkr'| }qt| tr|j| j d g| j d pad} | j d pvd} | dkr| dkrt }nt| | }|| kr|} qqqW|rt}d j|}n!|tkr| dkrt}n| r"td t| }nd}|||fS(sReturn a 3-tuple of status, status_details and time of last event. @param paths: An initialized cloudinit.helpers.paths object. Values are obtained from parsing paths.run_dir/status.json. ts status.jsons result.jsontv1itstagesRunning in stage: {0}t datasourceterrorststarttfinisheds s%a, %d %b %Y %H:%M:%S %z(RR0R1R4R5R:tCLOUDINIT_DISABLED_FILEtSTATUS_DISABLEDR2R RRtgettsortedtitemsR&t isinstancetdicttextendtmaxR't STATUS_DONERR(RR R+t status_v1t status_filet result_fileR7R9R?t latest_eventtkeytvalueR@RAt event_timeR,((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pyResR  !      cCs)t}tjtd|jdS(s$Tool to report status of cloud-init.R N(RR!texitR-t parse_args(R((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pytmains t__main__(t__doc__RR0R!R,RRRtcloudinit.distrosRtcloudinit.stagesRtcloudinit.utilRRRRBRR RKR'RCtNoneRR-R:RRUt__name__(((s8/usr/lib/python2.7/site-packages/cloudinit/cmd/status.pyts(       5