Revision 4403ff8d lib/ssh.py
b/lib/ssh.py | ||
---|---|---|
75 | 75 |
self.cluster_name = cluster_name |
76 | 76 |
|
77 | 77 |
def _BuildSshOptions(self, batch, ask_key, use_cluster_key, |
78 |
strict_host_check): |
|
78 |
strict_host_check, private_key=None):
|
|
79 | 79 |
"""Builds a list with needed SSH options. |
80 | 80 |
|
81 | 81 |
@param batch: same as ssh's batch option |
... | ... | |
84 | 84 |
@param use_cluster_key: if True, use the cluster name as the |
85 | 85 |
HostKeyAlias name |
86 | 86 |
@param strict_host_check: this makes the host key checking strict |
87 |
@param private_key: use this private key instead of the default |
|
87 | 88 |
|
88 | 89 |
@rtype: list |
89 | 90 |
@return: the list of options ready to use in L{utils.RunCmd} |
... | ... | |
99 | 100 |
if use_cluster_key: |
100 | 101 |
options.append("-oHostKeyAlias=%s" % self.cluster_name) |
101 | 102 |
|
103 |
if private_key: |
|
104 |
options.append("-i%s" % private_key) |
|
105 |
|
|
102 | 106 |
# TODO: Too many boolean options, maybe convert them to more descriptive |
103 | 107 |
# constants. |
104 | 108 |
|
... | ... | |
127 | 131 |
return options |
128 | 132 |
|
129 | 133 |
def BuildCmd(self, hostname, user, command, batch=True, ask_key=False, |
130 |
tty=False, use_cluster_key=True, strict_host_check=True): |
|
134 |
tty=False, use_cluster_key=True, strict_host_check=True, |
|
135 |
private_key=None): |
|
131 | 136 |
"""Build an ssh command to execute a command on a remote node. |
132 | 137 |
|
133 | 138 |
@param hostname: the target host, string |
... | ... | |
140 | 145 |
@param use_cluster_key: whether to expect and use the |
141 | 146 |
cluster-global SSH key |
142 | 147 |
@param strict_host_check: whether to check the host's SSH key at all |
148 |
@param private_key: use this private key instead of the default |
|
143 | 149 |
|
144 | 150 |
@return: the ssh call to run 'command' on the remote host. |
145 | 151 |
|
146 | 152 |
""" |
147 | 153 |
argv = [constants.SSH, "-q"] |
148 | 154 |
argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key, |
149 |
strict_host_check)) |
|
155 |
strict_host_check, private_key))
|
|
150 | 156 |
if tty: |
151 | 157 |
argv.append("-t") |
152 | 158 |
argv.extend(["%s@%s" % (user, hostname), command]) |
Also available in: Unified diff