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/haservice.pyc


Tc@sddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZm
Z
mZdefdYZd	efd
YZdefdYZdS(
iN(tFailure(tgetProcessValuetgetProcessOutputAndValue(tsucceed(tlog_failure(t
ManagerPlugint	SUCCEEDEDtFAILEDtCharmScriptErrorcBs eZdZdZdZRS(s
    Raised when a charm-provided script fails with a non-zero exit code.

    @ivar script: the name of the failed script
    @ivar code: the exit code of the failed script
    cCs,||_||_tj||jdS(N(tscripttcodet	Exceptiont__init__t_get_message(tselfR	R
((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyRs		cCsd|j|jfS(Ns3Failed charm script: %s exited with return code %d.(R	R
(R((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyR
s(t__name__t
__module__t__doc__RR
(((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyRs	t
RunPartsErrorcBs eZdZdZdZRS(s
    Raised when a charm-provided health script run-parts directory contains
    a health script that fails with a non-zero exit code.

    @ivar stderr: the stderr from the failed run-parts command
    cCs:d|jddj|_tj||jdS(Ns%st:i(tsplittstriptmessageRRR
(Rtstderr((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyR&s cCsd|jS(NsFailed charm script: %s.(R(R((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyR
*s(RRRRR
(((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyRs	t	HAServicecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZRS(s
    Plugin to manage this computer's active participation in a
    high-availability cluster. It depends on charms delivering both health
    scripts and cluster_add cluster_remove scripts to function.
    s/var/lib/juju/agentstadd_to_clustertremove_from_clustershealth_checks.dustandbyuonlinecCs-tt|j||jd|jdS(Nschange-ha-service(tsuperRtregistertregister_messagethandle_change_ha_service(Rtregistry((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyR<s	cCsVidd6|d6|d6}|r:|jdd|d<n|jjj||jtS(Nsoperation-resultttypetstatussoperation-idsutf-8treplacesresult-text(tdecodeRtbrokertsend_messaget_session_idtTrue(RR!tdatatoperation_idR((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_respondAs

cCs tj||jt||S(N(tloggingtinfoR*R(RR(RR)((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_respond_successJs
cCs#t||jt|j|S(sHandle exception failures.(RR*RtgetErrorMessage(RtfailureR)((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_respond_failureNs
cCs tj||jt||S(sOnly handle string failures.(R+terrorR*R(Rtfailure_stringR)((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_respond_failure_stringSs
cCstjj||j}tjj|s;tj|r\d|}tj|t|Sd}t	d|gdtj
}|j|S(so
        Exercise any discovered health check scripts, will return a deferred
        success or fail.
        s4Skipping juju charm health checks. No scripts at %s.cSs2|\}}}|dkr*t|ndSdS(NisAll health checks succeeded.(R(t.0tstdout_datatstderr_dataR!((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pytparse_outputfss	run-partstenv(tostpathtjointHEALTH_SCRIPTS_DIRtexiststlistdirR+R,RRtenvirontaddCallback(Rtscripts_patht
health_dirRR7tresult((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_run_health_checksXs#

	cCs||dkr|j}n	|j}tjj||}tjj|sitjd||ftdSd}||S(s
        Enables or disables a unit's participation in a cluster based on
        running charm-delivered CLUSTER_ONLINE and CLUSTER_STANDBY scripts
        if they exist. If the charm doesn't deliver scripts, return succeed().
        uonlinesTIgnoring juju charm cluster state change to '%s'. Charm script does not exist at %s.snThis computer is always a participant in its high-availabilty cluster. No juju charm cluster settings changed.cSs.t|dtj}d}|j||S(NR8cSs*|dkrt||nd|SdS(Nis
%s succeeded.(R(R
R	((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pytvalidate_exit_codes(RR9R?R@(R	RCRE((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt
run_scripts	(	tCLUSTER_ONLINEtCLUSTER_STANDBYR9R:R;R=R+R,R(Rt_RAt
service_statetscript_nameR	RF((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_change_cluster_participationps			
cCsGtd}||jkr-|j|}n|j|j|||S(s
        Handle specific state change requests through calls to available
        charm scripts like C{CLUSTER_ONLINE}, C{CLUSTER_STANDBY} and any
        health check scripts. Assume success in any case where no scripts
        exist for a given task.
        N(RtNonetSTATE_ONLINERDR@RL(RRARJR)td((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt_perform_state_changescCsd|d}y8d}|d}|d}|d}d||f}||j|jgkrfd|}nd|jd	d
}tjj|j|d}	tjj|jsd}ntjj|	sd
|}n|r|j||Stjj|	d}
|j	|
||}|j
|j|||j|j
||SWn|j
t||SXdS(s)Parse incoming change-ha-service messagessoperation-idusservice-names	unit-names
service-states&%s high-availability service set to %su1Invalid cluster participation state requested %s.sunit-t/t-tcharmuZThis computer is not deployed with juju. Changing high-availability service not supported.uOThis computer is not juju unit %s. Unable to modify high-availability services.tscriptsN(t
STATE_STANDBYRNR"R9R:R;tJUJU_UNITS_BASER=R3RPR@R-t
addErrbackR0R(RRR)t
error_messagetservice_namet	unit_nameRJtchange_messaget	unit_patht
charm_pathRARO((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyRs<





	

(RRRRVRGRHR<RURNRR*R-R0R3RDRLRPR(((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyR.s 								!	(R+R9ttwisted.python.failureRttwisted.internet.utilsRRttwisted.internet.deferRtlandscape.lib.logRtlandscape.manager.pluginRRRRRRR(((s?/usr/lib/python2.7/dist-packages/landscape/manager/haservice.pyt<module>s