1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from twisted.internet.protocol import Protocol, Factory
19 from twisted.internet.tcp import Port, Connection
20 from twisted.internet import reactor, address
21
22 from flumotion.common import medium, log
23 from flumotion.twisted import defer, fdserver
24 from flumotion.twisted import pb as fpb
25
26 import socket
27
28 __version__ = "$Rev$"
29
30
31
32
33
35 """
36 A connection class for use with passed FDs.
37 Similar to tcp.Server, but gets the initial FD from a different source,
38 obviously, and also passes along some data with the original connection.
39 """
40
41 - def __init__(self, sock, protocol, addr, additionalData):
60
64
67
68
70 """
71 A medium we use to talk to the porter.
72 Mostly, we use this to say what mountpoints (or perhaps, later,
73 (hostname, mountpoint) pairs?) we expect to receive requests for.
74 """
75
78
81
84
87
89
90 def handle_error(failure):
91 self.warning('Error getting port from old porter: %r', failure)
92 return 80
93
94 d = self.callRemote("getPort")
95 d.addErrback(handle_error)
96 return d
97
98
100 """
101 A PB client factory that knows how to log into a Porter.
102 Lives in streaming components, and accepts FDs passed over this connection.
103 """
104
117
122
125
128
131
134
137
140
141
143
144 - def __init__(self, childFactory, mountPoints, do_start_deferred,
145 prefixes=None):
146 """
147 @param mountPoints: a list of mountPoint strings that should be
148 registered to the porter
149 """
150 PorterClientFactory.__init__(self, childFactory)
151 self._mountPoints = mountPoints
152 self._prefixes = prefixes or []
153 self._do_start_deferred = do_start_deferred
154 self.remote_port = None
155
157
158
159 if self._do_start_deferred:
160 self.debug("Firing initial deferred: should indicate "
161 "that login is complete")
162 self._do_start_deferred.callback(None)
163 self._do_start_deferred = None
164
166
167
168
169
170 self.debug("Got deferred login, adding callbacks")
171 deferred.addCallback(self.medium.setRemoteReference)
172 deferred.addCallback(lambda r: self.medium.getPort())
173 deferred.addCallback(self._setRemotePort)
174 for mount in self._mountPoints:
175 self.debug("Registering mount point %s with porter", mount)
176 deferred.addCallback(lambda r, m: self.registerPath(m), mount)
177 for mount in self._prefixes:
178 self.debug("Registering mount prefix %s with porter", mount)
179 deferred.addCallback(lambda r, m: self.registerPrefix(m), mount)
180 deferred.addCallback(self._fireDeferred)
181
183 self.remote_port = port
184 return port
185