Your IP : 172.28.240.42


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


Tc@sddlmZmZddlmZddlmZddlmZddl	m
Z
defdYZde
fd	YZd
e
fdYZdS(
i(tinfot	exception(t
maybeDeferred(t
format_object(tgather_results(tremotetHandlerNotFoundErrorcBseZdZRS(s3A handler for the given message type was not found.(t__name__t
__module__t__doc__(((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR
stBrokerClientPlugincBskeZdZdZeZdZdZdZ	dZ
edZdZ
ddZdZdZRS(	sTA convenience for writing L{BrokerClient} plugins.

    This provides a register method which will set up a bunch of
    reactor handlers in the idiomatic way.

    If C{run} is defined on subclasses, it will be called every C{run_interval}
    +seconds after being registered.

    @cvar run_interval: The interval, in seconds, to execute the C{run} method.
        If set to C{None}, then C{run} will not be scheduled.
    @cvar run_immediately: If C{True} the plugin will be run immediately after
        it is registered.
    @ivar _session_id: the session id to be passed when sending messages via
        the broker.  This variable is set by the C{register} method and
        should only need to be renewed when a re-synchronisation request is
        sent. See L{landscape.broker.server.BrokerServer.send_message} for
        more details.
    icCsQ||_|jjjd|j|jjjd|j}|j|jdS(Nt
resynchronizetscope(	tclienttreactortcall_ont_resynchronizetbrokertget_session_idRtaddCallbackt_got_session_id(tselfR
tdeferred((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytregister's	cCs|jS(s%An alias for the C{client} attribute.(R
(R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytregistry-scs5fd}|jjjd|f|dS(sV
        Register a callback fired upon a C{message-type-acceptance-changed}.
        cs|rSdS(N((t
acceptance(tcallabletargstkwargs(s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytacceptance_changed7ssmessage-type-acceptance-changedN(R
RR(RttypeRRRR((RRRs;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytcall_on_accepted2scCs|dkp|j|ksdS|jdk	rG|jjj|jn|j|jjjd|j}|j	|j
|S(s
        Handle the 'resynchronize' event.  Subclasses should do any clear-down
        operations specific to their state within an implementation of the
        L{_reset} method.
        NR(tNoneRt_loopR
Rtcancel_callt_resetRRRR(RtscopesR((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR>s
cCsdS(s
        Reset plugin specific state.

        Sub-classes should override this method to clear down data for
        resynchronisation.  Sub-classes with no state can simply ignore this.
        N((R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR#WscCsq||_t|dddk	rm|jr7|jn|jdk	rm|jjj|j|j|_	qmndS(sSave the session ID and invoke the C{run} method.

        We set the C{_session_id} attribute on the instance because it's
        required in order to send messages.  See
        L{BrokerService.get_session_id}.
        trunN(
t_session_idtgetattrR trun_immediatelyR%trun_intervalR
Rt
call_everyR!(Rt
session_id((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR_s		
N(RRR	R)tFalseR(R RR&R!RtpropertyRRRR#R(((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR
s			tBrokerClientcBseZdZdZdZedZdZdZdZ	dZ
dZed	Zd
Z
dZedZd
ZedZRS(sBasic plugin registry for clients that have to deal with the broker.

    This knows about the needs of a client when dealing with the Landscape
    broker, including interest in messages of a particular type delivered
    by the broker to the client.

    @cvar name: The name used when registering to the broker, it must be
        defined by sub-classes.
    @ivar broker: A reference to a connected L{RemoteBroker}, it must be set
        by the connecting machinery at service startup.

    @param reactor: A L{LandscapeReactor}.
    R
cCsptt|j||_d|_i|_g|_i|_|jj	d|j
|jj	d|jdS(Nsimpending-exchangesbroker-reconnect(tsuperR.t__init__RR Rt_registered_messagest_pluginst
_plugin_namesRtnotify_exchangethandle_reconnect(RR((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR0s					cCstS(sReturn C{True}(tTrue(R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytpingscCsVtdt||jj|t|drE||j|j<n|j|dS(sAdd a plugin.

        The plugin's C{register} method will be called with this broker client
        as its argument.

        If the plugin has a C{plugin_name} attribute, it will be possible to
        look up the plugin later with L{get_plugin}.
        sRegistering plugin %s.tplugin_nameN(RRR2tappendthasattrR3R8R(Rtplugin((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytadds
	cCs|jS(sGet the list of plugins.(R2(R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytget_pluginsscCs|j|S(s Get a particular plugin by name.(R3(Rtname((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyt
get_pluginscCs||j|<|jj|S(st
        Register interest in a particular type of Landscape server->client
        message.

        @param type: The type of message to register C{handler} for.
        @param handler: A callable taking a message as a parameter, called
            when messages of C{type} are received.
        @return: A C{Deferred} that will fire when registration completes.
        (R1Rt%register_client_accepted_message_type(RRthandler((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytregister_messages

cCsg|d}|jj|}|dkr7t|ny||SWntd||fnXdS(sRun the handler registered for the type of the given message.

        @return: The return value of the handler, if found.
        @raises: HandlerNotFoundError if the handler was not found
        Rs-Error running message handler for type %r: %rN(R1tgetR RR(RtmessageRRA((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytdispatch_messages
cCs.y|j|tSWntk
r)tSXdS(sCall C{dispatch_message} for the given C{message}.

        @return: A boolean indicating if a handler for the message was found.
        N(RER6RR,(RRD((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyRDs


cCsOxH|jD]:}t|dr
y|jWqGtdqGXq
q
WdS(s Call C{exchange} on all plugins.texchangesError during plugin exchangeN(R=R:RFR(RR;((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyRFscCstd|jdS(s/Notify all plugins about an impending exchange.s>Got notification of impending exchange. Notifying all plugins.N(RRF(R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR4s
cOs|dkr>|d}|d}|jj||f|}n|jj|||}tg|D]}td|^q`S(sFire an event of a given type.

        @return: A L{Deferred} resulting in a list of returns values of
            the fired event handlers, in the order they were fired.
        smessage-type-acceptance-changediicSs|S(N((tx((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyt<lambda>s(RtfireRR(Rt
event_typeRRtmessage_typeRtresultstresult((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyt
fire_events

cCs;x!|jD]}|jj|q
W|jj|jdS(sCalled when the connection with the broker is established again.

        The following needs to be done:

          - Re-register any previously registered message types, so the broker
            knows we have interest on them.

          - Re-register ourselves as client, so the broker knows we exist and
            will talk to us firing events and dispatching messages.
        N(R1RR@tregister_clientR>(RR((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR5scCs|jjd|jjdS(s&Stop the reactor and exit the process.g?N(Rt
call_latertstop(R((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pytexits(RRR	R>R0RR7R<R=R?RBRERDRFR4RNR5RR(((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyR.os
					
					N(tloggingRRttwisted.internet.deferRt
landscape.logRtlandscape.lib.twisted_utilRt
landscape.ampRt	ExceptionRtobjectR
R.(((s;/usr/lib/python2.7/dist-packages/landscape/broker/client.pyt<module>sa