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


Tc@s
ddlZddlZddlZddlmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZmZdefdYZd	efd
YZdefdYZd
efdYZdeefdYZdS(iN(tfailtDeferredListtsucceed(tgenerate_script_hash(tAccumulator(t
ManagerPlugin(tProcessFailedErrortScriptRunnerMixintProcessTimeLimitReachedErrort
get_user_infotUnknownUserErrort
StoreProxycBs)eZdZdZdZdZRS(sI
    Persist-like interface to store graph-points into SQLite store.
    cCs
||_dS(N(tstore(tselfR((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyt__init__scCs(|jj|}|r |dS|SdS(Ni(Rtget_graph_accumulate(R
tkeytdefaulttgraph_accumulate((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pytgetscCs"|jj||d|ddS(Nii(Rtset_graph_accumulate(R
Rtvalue((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pytsets(t__name__t
__module__t__doc__RRR(((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyRs		tInvalidFormatErrorcBseZdZdZRS(cCs#||_tj||jdS(N(Rt	ExceptionRt_get_message(R
R((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR$s	cCsd|jS(Nu!Failed to convert to number: '%s'(R(R
((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR(s(RRRR(((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR"s	t
NoOutputErrorcBseZdZRS(cCstj|ddS(NuScript did not output any value(RR(R
((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR.s(RRR(((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR,stProhibitedUserErrorcBs eZdZdZdZRS(s
    Raised when an attempt to run a script as a user that is not allowed.

    @ivar username: The username that was used
    cCs#||_tj||jdS(N(tusernameRRR(R
R((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR9s	cCsd|jS(Nu%Custom graph cannot be run as user %s(R(R
((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR=s(RRRRR(((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR2s	tCustomGraphPlugincBseZdZdZdZdZdZdejdZ	dZ
dZdZd	Z
ed
ZdZdZd
ZdZdZdZRS(s
    Manage adding and deleting custom graph scripts, and then run the scripts
    in a loop.

    @param process_factory: The L{IReactorProcess} provider to run the
        process with.
    i,ii
scustom-graphcCs5tt|j|||_i|_t|_dS(N(tsuperR Rt_create_timet_datatTruetdo_send(R
tprocess_factorytcreate_time((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyRNs		cCsmtt|j||jd|j|jd|jt|jj|_	t
|j	|j|_dS(Nscustom-graph-addscustom-graph-remove(
R!R tregistertregister_messaget_handle_custom_graph_addt_handle_custom_graph_removeRtregistryRt_persistRtrun_intervalt_accumulate(R
R,((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR(Ts

cCsxt|d}|jjj|}|rE|d}tj|n|jjj|||jkrt|j|=ndS(sk
        Handle remove custom-graph operation, deleting the custom graph scripts
        if found.
        sgraph-idiN(tintR,Rt	get_graphtostunlinktremove_graphR#(R
tmessagetgraph_idtgraphtfilename((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR+]s
cCs3|d}|d}|d}t|d}|jjj}tjj|d}tjj|d|f}tjj|rtj|nyt	|d \}	}
Wn"t
k
rtjd|nHXt
|d	}|j|||||	|
||jkr|j|=n|jjj|||d
S(ss
        Handle add custom-graph operation, which can also update an existing
        custom graph script.
        Rtinterpretertcodesgraph-idscustom-graph-scriptssgraph-%diu)Attempt to add graph with unknown user %stwN(R0R,tconfigt	data_pathR2tpathtjointexistsR3R	R
tloggingterrortfiletwrite_script_fileR#Rt	add_graph(R
R5tusertshellR:R6R=tscripts_directoryR8tuidtgidtscript_file((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR*ls*


	
	
cCsd|jj|jdfS(Nu%s: %si(t	__class__Rtargs(R
te((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyt_format_exceptionscCs#|jjj|j|j|dS(N(R,tbrokertcall_if_acceptedtmessage_typetsend_message(R
turgent((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pytexchangesc
Cs5|js
dSt|_t|jjj}xo|D]g\}}}||jkr5tjj	|r|j
|}igd6dd6|d6|j|<qq5q5Wi|jd6|jd6}i}xF|jjD]5\}}	|	d}igd6dd6|d6||<qW||_|jj
j||jd|dS(NtvaluesuRBsscript-hashttypetdataRT(R%tFalsetlistR,Rt
get_graphsR#R2R>tisfilet_get_script_hashRRt	iteritemsRPRSt_session_id(
R
RTtgraphsR6R8RFtscript_hashR5tnew_datatitem((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyRSs&		)
 	cCs||jkrdSyt|}Wn/tk
rT|rHt|qUtnX|j|||}|r|j|dj|ndS(NRV(R#tfloatt
ValueErrorRRR/tappend(R
toutputR6tnowRXt	step_data((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyt_handle_datas

cCs||jkrdS|jtrp|jjjd}|jjr\d||jjf}n||j|d<nJ|jtrd|jf|j|d<n|j	|j|j|d<dS(Nsutf-8s %s (process exited with code %d)RBu%Process exceeded the %d seconds limit(
R#tcheckRRRXtdecodet	exit_codeRt
time_limitRO(R
tfailureR6t
failure_value((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyt
_handle_errorscCs,t|}|j}|jt|S(N(RCtreadtcloseR(R
R8tfile_objecttscript_content((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR]s
cCsPt|_t|jjj}|s1tgS|jjj|j	|j
|S(sr
        Iterate all the custom graphs stored and then execute each script and
        handle the output.
        (R$R%RZR,RR[RRPRQRRt
_continue_run(R
R`((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pytruns	
cCsg}t|j}x|D]\}}}tjj|rR|j|}nd}||jkrigd6dd6|d6|j|<n||j|d<yt|\}}	}
WnBtk
r}t	|}|j
|j||j|qnX|j
|sBt	t|}|j
|j||j|qntjj|sZqn|j|||	|
i|j}
|
j|j|||
j
|j||j|
qWt|S(NtRVuRBsscript-hash(R0R"R2R>R\R]R#R	R
Rt
addErrbackRqRftis_user_allowedRt_run_scriptRntaddCallbackRjR(R
R`t
deferred_listRhR6R8RFRaRIRJR>RNtdtresult((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyRvs<"

N(RRRR.t
size_limitRnRRtNonettimeRR(R+R*RORYRURSRjRqR]RwRv(((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyR As"										(R2RRAttwisted.internet.deferRRRtlandscape.lib.scriptcontentRtlandscape.accumulateRtlandscape.manager.pluginRt!landscape.manager.scriptexecutionRRRR	R
tobjectRRRRRR (((sA/usr/lib/python2.7/dist-packages/landscape/manager/customgraph.pyt<module>s(