ó oBú]c@sđdZddlZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z mZmZdZdZd Zd Zd Zd Zdd „Zd„Zd„Zd„Zd„ZedkrěeƒndS(sFDefine 'status' utility and handler as part of cloud-init commandline.i˙˙˙˙N(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ƒ}|jƒt|jƒ\}}}|jrĽxU|ttfkr‘tjj dƒtjj ƒt|jƒ\}}}t dƒq=Wtjj dƒn|j rädj |ƒGH|rÓdj |ƒ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"    cCsÄt}tƒjƒ}tƒs'd}n“d|kr<d}n~tjj|ƒrft}dj|ƒ}nTd|krt}d}n9tjjtjj |j dƒƒs´t}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|ƒrştjj|ƒs™t }nt t |ƒƒj diƒ}ng}d} xüt |jƒƒD]č\} } | dkr| rÁt }dj| ƒ}qÁqŮ| dkr'| }qŮt| tƒrŮ|j| j d gƒƒ| j d ƒpad} | j d ƒpvd} | dkrš| dkršt }nt| | ƒ}|| krÁ|} qÁqŮqŮW|răt}d j|ƒ}n!|tkr| dkrt}n| r"td t| ƒƒ}nd}|||fS(sĘReturn 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|jƒƒƒdS(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.pytmainšs 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