|
1 In-house patch for the temporary removal of Paramiko dependency in |
|
2 Cinder. This patch is Solaris-specific and not suitable for upstream |
|
3 |
|
4 --- cinder-2013.1.4/cinder/utils.py.orig 2013-10-17 11:21:37.000000000 -0700 |
|
5 +++ cinder-2013.1.4/cinder/utils.py 2014-03-08 11:55:09.044072461 -0800 |
|
6 @@ -27,7 +27,6 @@ |
|
7 import inspect |
|
8 import itertools |
|
9 import os |
|
10 -import paramiko |
|
11 import pyclbr |
|
12 import random |
|
13 import re |
|
14 @@ -233,135 +232,6 @@ |
|
15 return out, err |
|
16 |
|
17 |
|
18 -def ssh_execute(ssh, cmd, process_input=None, |
|
19 - addl_env=None, check_exit_code=True): |
|
20 - LOG.debug(_('Running cmd (SSH): %s'), cmd) |
|
21 - if addl_env: |
|
22 - raise exception.Error(_('Environment not supported over SSH')) |
|
23 - |
|
24 - if process_input: |
|
25 - # This is (probably) fixable if we need it... |
|
26 - raise exception.Error(_('process_input not supported over SSH')) |
|
27 - |
|
28 - stdin_stream, stdout_stream, stderr_stream = ssh.exec_command(cmd) |
|
29 - channel = stdout_stream.channel |
|
30 - |
|
31 - #stdin.write('process_input would go here') |
|
32 - #stdin.flush() |
|
33 - |
|
34 - # NOTE(justinsb): This seems suspicious... |
|
35 - # ...other SSH clients have buffering issues with this approach |
|
36 - stdout = stdout_stream.read() |
|
37 - stderr = stderr_stream.read() |
|
38 - stdin_stream.close() |
|
39 - stdout_stream.close() |
|
40 - stderr_stream.close() |
|
41 - |
|
42 - exit_status = channel.recv_exit_status() |
|
43 - |
|
44 - # exit_status == -1 if no exit code was returned |
|
45 - if exit_status != -1: |
|
46 - LOG.debug(_('Result was %s') % exit_status) |
|
47 - if check_exit_code and exit_status != 0: |
|
48 - raise exception.ProcessExecutionError(exit_code=exit_status, |
|
49 - stdout=stdout, |
|
50 - stderr=stderr, |
|
51 - cmd=cmd) |
|
52 - channel.close() |
|
53 - return (stdout, stderr) |
|
54 - |
|
55 - |
|
56 -def create_channel(client, width, height): |
|
57 - """Invoke an interactive shell session on server.""" |
|
58 - channel = client.invoke_shell() |
|
59 - channel.resize_pty(width, height) |
|
60 - return channel |
|
61 - |
|
62 - |
|
63 -class SSHPool(pools.Pool): |
|
64 - """A simple eventlet pool to hold ssh connections.""" |
|
65 - |
|
66 - def __init__(self, ip, port, conn_timeout, login, password=None, |
|
67 - privatekey=None, *args, **kwargs): |
|
68 - self.ip = ip |
|
69 - self.port = port |
|
70 - self.login = login |
|
71 - self.password = password |
|
72 - self.conn_timeout = conn_timeout if conn_timeout else None |
|
73 - self.privatekey = privatekey |
|
74 - super(SSHPool, self).__init__(*args, **kwargs) |
|
75 - |
|
76 - def create(self): |
|
77 - try: |
|
78 - ssh = paramiko.SSHClient() |
|
79 - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
|
80 - if self.password: |
|
81 - ssh.connect(self.ip, |
|
82 - port=self.port, |
|
83 - username=self.login, |
|
84 - password=self.password, |
|
85 - timeout=self.conn_timeout) |
|
86 - elif self.privatekey: |
|
87 - pkfile = os.path.expanduser(self.privatekey) |
|
88 - privatekey = paramiko.RSAKey.from_private_key_file(pkfile) |
|
89 - ssh.connect(self.ip, |
|
90 - port=self.port, |
|
91 - username=self.login, |
|
92 - pkey=privatekey, |
|
93 - timeout=self.conn_timeout) |
|
94 - else: |
|
95 - msg = _("Specify a password or private_key") |
|
96 - raise exception.CinderException(msg) |
|
97 - |
|
98 - # Paramiko by default sets the socket timeout to 0.1 seconds, |
|
99 - # ignoring what we set thru the sshclient. This doesn't help for |
|
100 - # keeping long lived connections. Hence we have to bypass it, by |
|
101 - # overriding it after the transport is initialized. We are setting |
|
102 - # the sockettimeout to None and setting a keepalive packet so that, |
|
103 - # the server will keep the connection open. All that does is send |
|
104 - # a keepalive packet every ssh_conn_timeout seconds. |
|
105 - if self.conn_timeout: |
|
106 - transport = ssh.get_transport() |
|
107 - transport.sock.settimeout(None) |
|
108 - transport.set_keepalive(self.conn_timeout) |
|
109 - return ssh |
|
110 - except Exception as e: |
|
111 - msg = _("Error connecting via ssh: %s") % e |
|
112 - LOG.error(msg) |
|
113 - raise paramiko.SSHException(msg) |
|
114 - |
|
115 - def get(self): |
|
116 - """ |
|
117 - Return an item from the pool, when one is available. This may |
|
118 - cause the calling greenthread to block. Check if a connection is active |
|
119 - before returning it. For dead connections create and return a new |
|
120 - connection. |
|
121 - """ |
|
122 - if self.free_items: |
|
123 - conn = self.free_items.popleft() |
|
124 - if conn: |
|
125 - if conn.get_transport().is_active(): |
|
126 - return conn |
|
127 - else: |
|
128 - conn.close() |
|
129 - return self.create() |
|
130 - if self.current_size < self.max_size: |
|
131 - created = self.create() |
|
132 - self.current_size += 1 |
|
133 - return created |
|
134 - return self.channel.get() |
|
135 - |
|
136 - def remove(self, ssh): |
|
137 - """Close an ssh client and remove it if in free_items.""" |
|
138 - ssh.close() |
|
139 - if ssh in self.free_items: |
|
140 - self.free_items.pop(ssh) |
|
141 - ssh = None |
|
142 - |
|
143 - if self.current_size > 0: |
|
144 - self.current_size -= 1 |
|
145 - |
|
146 - |
|
147 def cinderdir(): |
|
148 import cinder |
|
149 return os.path.abspath(cinder.__file__).split('cinder/__init__.py')[0] |
|
150 --- cinder-2013.1.4/cinder.egg-info/requires.txt.orig Wed Feb 26 10:56:39 2014 |
|
151 +++ cinder-2013.1.4/cinder.egg-info/requires.txt Wed Feb 26 10:58:01 2014 |
|
152 @@ -14,7 +14,6 @@ |
|
153 sqlalchemy-migrate>=0.7.2 |
|
154 stevedore>=0.8.0 |
|
155 suds>=0.4 |
|
156 -paramiko |
|
157 Babel>=0.9.6 |
|
158 iso8601>=0.1.4 |
|
159 setuptools_git>=0.4 |
|
160 --- cinder-2013.1.4/tools/pip-requires.orig Wed Feb 26 10:56:38 2014 |
|
161 +++ cinder-2013.1.4/tools/pip-requires Wed Feb 26 10:58:25 2014 |
|
162 @@ -14,7 +14,6 @@ |
|
163 sqlalchemy-migrate>=0.7.2 |
|
164 stevedore>=0.8.0 |
|
165 suds>=0.4 |
|
166 -paramiko |
|
167 Babel>=0.9.6 |
|
168 iso8601>=0.1.4 |
|
169 setuptools_git>=0.4 |