Current File : //lib/python2.7/site-packages/cloudinit/cmd/status.pyc
�
oB�]c@s�dZddlZddlZddlZddlmZmZmZddlm	Z	ddl
mZddlm
Z
mZmZdZdZd	Zd
ZdZd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(tget_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.
    tprogtstatustdescriptionsReport 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�\}}}td�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
sstatus: {0}s	time: {0}sdetail:
{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_fileRtis_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.
    tsstatus.jsonsresult.jsontv1itstagesRunning in stage: {0}t
datasourceterrorststarttfinisheds
s%a, %d %b %Y %H:%M:%S %z(RR0R1R4R5R:tCLOUDINIT_DISABLED_FILEtSTATUS_DISABLEDR2R RRtgettsortedtitemsR&t
isinstancetdicttextendtmaxR'tSTATUS_DONERR(RR
R+t	status_v1tstatus_filetresult_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.pyt<module>s(			5