Skip to content

Commit

Permalink
Add config option for SSH key file (#30)
Browse files Browse the repository at this point in the history
Add config option for SSH key file
  • Loading branch information
mraspaud committed Jun 17, 2019
2 parents 18d29bc + c3898b9 commit 35db0d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/move_it_server.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ topic = /1b/hrit-segment/0deg
# prog = /local_disk/eumetcast/opt/move_it/bin/xRITDecompress
# Do not delete the compressed file
delete = False
# Path to SSH key _private_ key used for transfers
# ssh_key_filename = /home/user/.ssh/id_rsa
6 changes: 5 additions & 1 deletion trollmoves/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ def read_config(filename):
res[section].setdefault("compression", False)
res[section].setdefault("req_timeout", DEFAULT_REQ_TIMEOUT)
res[section].setdefault("transfer_req_timeout", 10 * DEFAULT_REQ_TIMEOUT)
res[section].setdefault("ssh_key_filename", None)
if ("origin" not in res[section]) and ('listen' not in res[section]):
LOGGER.warning("Incomplete section %s: add an 'origin' or "
"'listen' item.", section)
Expand Down Expand Up @@ -865,14 +866,17 @@ def open_connection(self):
from paramiko import SSHClient, SSHException, AutoAddPolicy

retries = 3
ssh_key_filename = self.attrs.get("ssh_key_filename", None)

while retries > 0:
retries -= 1
try:
ssh_connection = SSHClient()
ssh_connection.set_missing_host_key_policy(AutoAddPolicy())
ssh_connection.load_system_host_keys()
ssh_connection.connect(self.destination.hostname, username = self.destination.username)
ssh_connection.connect(self.destination.hostname,
username=self.destination.username,
key_filename=ssh_key_filename)
LOGGER.debug("Successfully connected to %s as %s",
self.destination.hostname,
self.destination.username)
Expand Down

0 comments on commit 35db0d3

Please sign in to comment.