/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

Implement ParamikoVendor.connect_ssh

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
        raise NotImplementedError(self.connect_sftp)
155
155
 
156
156
    def connect_ssh(self, username, password, host, port, command):
157
 
        """Make an SSH connection, and return a pipe-like object.
 
157
        """Make an SSH connection.
158
158
        
159
 
        (This is currently unused, it's just here to indicate future directions
160
 
        for this code.)
 
159
        :returns: something with a `close` method, and a `get_filelike_channels`
 
160
            method that returns a pair of (read, write) filelike objects.
161
161
        """
162
162
        raise NotImplementedError(self.connect_ssh)
163
163
        
177
177
register_ssh_vendor('loopback', LoopbackVendor())
178
178
 
179
179
 
 
180
class _ParamikoSSHConnection(object):
 
181
    def __init__(self, channel):
 
182
        self.channel = channel
 
183
 
 
184
    def get_filelike_channels(self):
 
185
        return self.channel.makefile('rb'), self.channel.makefile('wb')
 
186
 
 
187
    def close(self):
 
188
        return self.channel.close()
 
189
 
 
190
 
180
191
class ParamikoVendor(SSHVendor):
181
192
    """Vendor that uses paramiko."""
182
193
 
183
 
    def connect_sftp(self, username, password, host, port):
 
194
    def _connect(self, username, password, host, port):
184
195
        global SYSTEM_HOSTKEYS, BZR_HOSTKEYS
185
196
        
186
197
        load_host_keys()
218
229
                ['Try editing %s or %s' % (filename1, filename2)])
219
230
 
220
231
        _paramiko_auth(username, password, host, t)
 
232
        return t
221
233
        
 
234
    def connect_sftp(self, username, password, host, port):
 
235
        t = self._connect(username, password, host, port)
222
236
        try:
223
 
            sftp = t.open_sftp_client()
 
237
            return t.open_sftp_client()
224
238
        except paramiko.SSHException, e:
225
239
            raise ConnectionError('Unable to start sftp client %s:%d' %
226
240
                                  (host, port), e)
227
 
        return sftp
 
241
 
 
242
    def connect_ssh(self, username, password, host, port, command):
 
243
        t = self._connect(username, password, host, port)
 
244
        try:
 
245
            channel = t.open_session()
 
246
            cmdline = ' '.join(command)
 
247
            channel.exec_command(cmdline)
 
248
            return _ParamikoSSHConnection(channel)
 
249
        except paramiko.SSHException, e:
 
250
            raise ConnectionError('Unable to invoke remote bzr %s:%d' %
 
251
                                  (host, port), e)
228
252
 
229
253
register_ssh_vendor('paramiko', ParamikoVendor())
230
254