Revision a9f33339 lib/ssh.py
b/lib/ssh.py | ||
---|---|---|
123 | 123 |
self.ipv6 = ipv6 |
124 | 124 |
|
125 | 125 |
def _BuildSshOptions(self, batch, ask_key, use_cluster_key, |
126 |
strict_host_check, private_key=None, quiet=True): |
|
126 |
strict_host_check, private_key=None, quiet=True, |
|
127 |
port=None): |
|
127 | 128 |
"""Builds a list with needed SSH options. |
128 | 129 |
|
129 | 130 |
@param batch: same as ssh's batch option |
... | ... | |
134 | 135 |
@param strict_host_check: this makes the host key checking strict |
135 | 136 |
@param private_key: use this private key instead of the default |
136 | 137 |
@param quiet: whether to enable -q to ssh |
138 |
@param port: the SSH port to use, or None to use the default |
|
137 | 139 |
|
138 | 140 |
@rtype: list |
139 | 141 |
@return: the list of options ready to use in L{utils.process.RunCmd} |
... | ... | |
156 | 158 |
if private_key: |
157 | 159 |
options.append("-i%s" % private_key) |
158 | 160 |
|
161 |
if port: |
|
162 |
options.append("-oPort=%d" % port) |
|
163 |
|
|
159 | 164 |
# TODO: Too many boolean options, maybe convert them to more descriptive |
160 | 165 |
# constants. |
161 | 166 |
|
... | ... | |
190 | 195 |
|
191 | 196 |
def BuildCmd(self, hostname, user, command, batch=True, ask_key=False, |
192 | 197 |
tty=False, use_cluster_key=True, strict_host_check=True, |
193 |
private_key=None, quiet=True): |
|
198 |
private_key=None, quiet=True, port=None):
|
|
194 | 199 |
"""Build an ssh command to execute a command on a remote node. |
195 | 200 |
|
196 | 201 |
@param hostname: the target host, string |
... | ... | |
205 | 210 |
@param strict_host_check: whether to check the host's SSH key at all |
206 | 211 |
@param private_key: use this private key instead of the default |
207 | 212 |
@param quiet: whether to enable -q to ssh |
213 |
@param port: the SSH port on which the node's daemon is running |
|
208 | 214 |
|
209 | 215 |
@return: the ssh call to run 'command' on the remote host. |
210 | 216 |
|
... | ... | |
212 | 218 |
argv = [constants.SSH] |
213 | 219 |
argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key, |
214 | 220 |
strict_host_check, private_key, |
215 |
quiet=quiet)) |
|
221 |
quiet=quiet, port=port))
|
|
216 | 222 |
if tty: |
217 | 223 |
argv.extend(["-t", "-t"]) |
218 | 224 |
|
... | ... | |
277 | 283 |
|
278 | 284 |
return not result.failed |
279 | 285 |
|
280 |
def VerifyNodeHostname(self, node): |
|
286 |
def VerifyNodeHostname(self, node, ssh_port):
|
|
281 | 287 |
"""Verify hostname consistency via SSH. |
282 | 288 |
|
283 | 289 |
This functions connects via ssh to a node and compares the hostname |
... | ... | |
290 | 296 |
|
291 | 297 |
@param node: nodename of a host to check; can be short or |
292 | 298 |
full qualified hostname |
299 |
@param ssh_port: the port of a SSH daemon running on the node |
|
293 | 300 |
|
294 | 301 |
@return: (success, detail), where: |
295 | 302 |
- success: True/False |
... | ... | |
301 | 308 |
"else" |
302 | 309 |
" echo \"$GANETI_HOSTNAME\";" |
303 | 310 |
"fi") |
304 |
retval = self.Run(node, constants.SSH_LOGIN_USER, cmd, quiet=False) |
|
311 |
retval = self.Run(node, constants.SSH_LOGIN_USER, cmd, |
|
312 |
quiet=False, port=ssh_port) |
|
305 | 313 |
|
306 | 314 |
if retval.failed: |
307 | 315 |
msg = "ssh problem" |
Also available in: Unified diff