Your IP : 172.28.240.42


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


Tc@sdZddlZddlZddlmZmZmZdefdYZdZ	dZ
defd	YZd
ZdS(shCommunication between components in different services via twisted AMP.

The Landscape client is composed by several processes that need to talk to
each other. For example the monitor and manager processes need to talk to
the broker in order to ask it to add new messages to the outgoing queue, and
the broker needs to talk to them in order to dispatch them incoming messages
from the server.

This module implements a few conveniences built around L{landscape.lib.amp} to
let the various services connect to each other in an easy and idiomatic way,
and have them respond to standard requests like "ping" or "exit".
iN(tMethodCallClientFactorytMethodCallServerFactorytRemoteObjecttComponentPublishercBs/eZdZeZdZdZdZRS(sPublish a Landscape client component using a UNIX socket.

    Other Landscape client processes can then connect to the socket and invoke
    methods on the component remotely, using L{MethodCall} commands.

    @param component: The component to publish. It can be any Python object
        implementing the methods listed in the C{methods} class variable.
    @param reactor: The L{LandscapeReactor} used to listen to the socket.
    @param config: The L{Configuration} object used to build the socket path.
    cCsC||_||_||_d|_tt|j|_dS(N(	t_reactort_configt
_componenttNonet_porttget_remote_methodsttypetkeystmethods(tselft	componenttreactortconfig((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyt__init__"s
				cCsFt|j|j}t|j|j}|jj|||_dS(sStart accepting connections.N(RRRt_get_socket_pathRRtlisten_unixR(R
tfactorytsocket_path((s1/usr/lib/python2.7/dist-packages/landscape/amp.pytstart)scCs
|jjS(sStop accepting connections.(Rt
stopListening(R
((s1/usr/lib/python2.7/dist-packages/landscape/amp.pytstop/s(t__name__t
__module__t__doc__RRRRR(((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyRs

		cCs[i}xNt|D]@}t||}t|dd}|dk	r|||<qqW|S(srGet all the remote methods declared on a class.

    @param klass: A class to search for AMP-exposed methods.
    tamp_exposedN(tdirtgetattrR(tklasstremote_methodstattribute_nametpotential_methodtname((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyR	4scCs|j|_|S(sa
    A decorator for marking a method as remotely accessible as a method on a
    component.
    (RR(tmethod((s1/usr/lib/python2.7/dist-packages/landscape/amp.pytremoteBstComponentConnectorcBsGeZdZeZdZeZe	dZ
dde	dZdZRS(sUtility superclass for creating connections with a Landscape component.

    @cvar component: The class of the component to connect to, it is expected
        to define a C{name} class attribute, which will be used to find out
        the socket to use. It must be defined by sub-classes.
    @cvar factory: The factory class to use for building protocols.
    @cvar remote: The L{RemoteObject} class or sub-class used for building
        remote objects.

    @param reactor: A L{LandscapeReactor} object.
    @param config: A L{LandscapeConfiguration}.
    @param retry_on_reconnect: If C{True} the remote object built by this
        connector will retry L{MethodCall}s that failed due to lost
        connections.

    @see: L{MethodCallClientFactory}.
    cCs(||_||_||_d|_dS(N(RRt_retry_on_reconnectRt
_connector(R
RRtretry_on_reconnect((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyRas			csjjjd__j_j_|_|rX|_nfdfd}fd}t	j
j}j}jj
|_|s|j|n|j|S(sConnect to the remote Landscape component.

        If the connection is lost after having been established, and then
        it is established again by the reconnect mechanism, an event will
        be fired.

        @param max_retries: If given, the connector will keep trying to connect
            up to that number of times, if the first connection attempt fails.
        @param factor: Optionally a float indicating by which factor the
            delay between subsequent retries should increase. Smaller values
            result in a faster reconnection attempts pace.
        @param quiet: A boolean indicating whether to log errors.
        g?csjjdjjdS(Ns%s-reconnect(RtfireRR#(tignored(R
(s1/usr/lib/python2.7/dist-packages/landscape/amp.pytfire_reconnect}scsj|S(N(tnotifyOnConnect(R%(R,R(s1/usr/lib/python2.7/dist-packages/landscape/amp.pyt	connecteds
cstjdjj|S(NsError while connecting to %s(tloggingterrorRR#(tfailure(R
(s1/usr/lib/python2.7/dist-packages/landscape/amp.pyt	log_errors(RRtinitialDelaytdelayR'tretryOnReconnectR%t
maxRetriestfactorRRRtgetRemoteObjecttconnect_unixR(t
addErrbacktaddCallback(R
tmax_retriesR7tquietR.R2Rtdeferred((R
RR,s1/usr/lib/python2.7/dist-packages/landscape/amp.pytconnectgs 	cCsB|jdk	r>|jj}|j|jjd|_ndS(s4Disconnect the L{RemoteObject} that we have created.N(R(RRt
stopTryingt
disconnect(R
R((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyRAs


N(
RRRRRRRRR%tFalseRR?RA(((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyR&Ks*cCstjj|j|jdS(Ns.sock(tostpathtjointsockets_pathR#(RR((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyRs(
RRCR/tlandscape.lib.ampRRRtobjectRR	R%R&R(((s1/usr/lib/python2.7/dist-packages/landscape/amp.pyt<module>s 			O