Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/manager/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyc


Tc@sddlZddlmZddlmZddlmZddlmZm	Z	m
Z
defdYZdefd	YZ
d
efdYZdS(iN(tDeferred(tProcessProtocol(tProcessDone(t
ManagerPlugint	SUCCEEDEDtFAILEDtShutdownFailedErrorcBseZdZdZRS(svRaised when a call to C{/sbin/shutdown} fails.

    @ivar data: The data that the process printed before failing.
    cCs
||_dS(N(tdata(tselfR((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyt__init__s(t__name__t
__module__t__doc__R	(((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR
stShutdownManagercBsJeZddZdZdZdZdZdZdZ	RS(cCs,|dkrddlm}n||_dS(Ni(treactor(tNonettwisted.internetRt_process_factory(Rtprocess_factory((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR	scCs-tt|j||jd|jdS(sAdd this plugin to C{registry}.

        The shutdown manager handles C{shutdown} activity messages broadcast
        from the server.
        tshutdownN(tsuperR
tregistertregister_messagetperform_shutdown(Rtregistry((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyRscCs|d}|d}t}|j|jj|jj|j||jj|j||j	||\}}|j
j||d|dS(sRequest a system restart or shutdown.

        If the call to C{/sbin/shutdown} runs without errors the activity
        specified in the message will be responded as succeeded.  Otherwise,
        it will be responded as failed.
        soperation-idtreboottargsN(tShutdownProcessProtocoltset_timeoutRRtresulttaddCallbackt_respond_successt
addErrbackt_respond_failuret_get_command_and_argsRtspawnProcess(Rtmessagetoperation_idRtprotocoltcommandR((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR$s

	cs<tjdjt||}|jfd|S(NsShutdown request succeeded.csjjjS(N(Rtbrokertstop_exchanger(t_(R(sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyt<lambda>:s(tloggingtinfot_respondRR(RRR%tdeferred((RsE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR4s

cCs&tjd|jt|jj|S(NsShutdown request failed.(R,R-R.RtvalueR(RtfailureR%((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR!=s
cCs>idd6|d6|d6|d6}|jjj||jtS(Nsoperation-resultttypetstatussresult-textsoperation-id(RR(tsend_messaget_session_idtTrue(RR3RR%R$((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR.As

cCsKd|jdf}|r/dd|dg}ndd|dg}d|fS(ss
        Returns a C{command, args} 2-tuple suitable for use with
        L{IReactorProcess.spawnProcess}.
        s+%di<s/sbin/shutdowns-rs!Landscape is rebooting the systems-hs%Landscape is shutting down the system(tdelay(RR&RtminutesR((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR"Is			N(
R
RRR	RRRR!R.R"(((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR
s							RcBsMeZdZeddZdZddZdZdZdZ	RS(	s~A ProcessProtocol for calling C{/sbin/shutdown}.

    C{shutdown} doesn't return immediately when a time specification is
    provided.  Failures are reported immediately after it starts and return a
    non-zero exit code.  The process protocol calls C{shutdown} and waits for
    failures for C{timeout} seconds.  If no failures are reported it fires
    C{result}'s callback with whatever output was received from the process.
    If failures are reported C{result}'s errback is fired.

    @ivar result: A L{Deferred} fired when C{shutdown} fails or
        succeeds.
    @ivar reboot: A flag indicating whether a shutdown or reboot should be
        performed.  Default is C{False}.
    @ivar delay: The time in seconds from now to schedule the shutdown.
        Default is 240 seconds.  The time will be converted to minutes using
        integer division when passed to C{shutdown}.
    icCs4t|_||_||_g|_t|_dS(N(RRRR7t_dataR6t_waiting(RRR7((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR	ks
			cCsdj|jS(s'Get the data printed by the subprocess.t(tjoinR9(R((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pytget_datarsi
cCs|j||jdS(si
        Set the error checking timeout, after which C{result}'s callback will
        be fired.
        N(t
call_latert_succeed(RRttimeout((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyRvscCs |jr|jj|ndS(ssSome data was received from the child.

        Add it to our buffer to pass to C{result} when it's fired.
        N(R:R9tappend(RtfdR((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pytchildDataReceived}s	cCsQ|jrM|jtr%|jqM|jjt|jt|_ndS(sFire back the C{result} L{Deferred}.

        C{result}'s callback will be fired with the string of data received
        from the subprocess, or if the subprocess failed C{result}'s errback
        will be fired with the string of data received from the subprocess.
        N(	R:tcheckRR?RterrbackRR=tFalse(Rtreason((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pytprocessEndeds
	
cCs/|jr+|jj|jt|_ndS(sAFire C{result}'s callback with data accumulated from the process.N(R:RtcallbackR=RF(R((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyR?s	(
R
RRRFR	R=RRCRHR?(((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyRXs			(R,ttwisted.internet.deferRttwisted.internet.protocolRttwisted.internet.errorRtlandscape.manager.pluginRRRt	ExceptionRR
R(((sE/usr/lib/python2.7/dist-packages/landscape/manager/shutdownmanager.pyt<module>s
D