Skip to content

Commit

Permalink
allow ssh key for gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
afourmy committed Sep 30, 2022
1 parent 1158190 commit 1373db2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions eNMS/models/services/file_transfer/generic_file_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def job(self, run, device):
ssh_client.load_system_host_keys()
source = run.sub(run.source_file, locals())
destination = run.sub(run.destination_file, locals())
credentials = run.get_credentials(device)
credentials.pop("secret", None)
credentials = run.get_credentials(device, add_secret=False)
ssh_client.connect(device.ip_address, look_for_keys=False, **credentials)
if run.source_file_includes_globbing:
glob_source_file_list = glob(source, recursive=False)
Expand Down
9 changes: 4 additions & 5 deletions eNMS/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,15 @@ def notify(self, results):
results["notification"] = {"success": True, "result": result}
return results

def get_credentials(self, device):
def get_credentials(self, device, add_secret=True):
result, credential_type = {}, self.main_run.service.credential_type
credential = db.get_credential(
self.creator,
device=device,
credential_type=credential_type,
optional=self.credentials != "device",
)
if device and credential:
if add_secret and device and credential:
log = f"Using '{credential.name}' credential for '{device.name}'"
self.log("info", log)
result["secret"] = env.get_password(credential.enable_password)
Expand Down Expand Up @@ -1014,16 +1014,15 @@ def netmiko_connection(self, device):
gateways = sorted(device.gateways, key=attrgetter("priority"), reverse=True)
for gateway in gateways:
try:
credentials = self.get_credentials(gateway)
credentials = self.get_credentials(gateway, add_secret=False)
connection_log = f"Trying to establish connection to {gateway}"
self.log("info", connection_log, device, logger="security")
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(
hostname=gateway.ip_address,
port=gateway.port,
username=credentials["username"],
password=credentials["password"],
**credentials
)
sock = client.get_transport().open_channel(
"direct-tcpip", (device.ip_address, device.port), ("", 0)
Expand Down

0 comments on commit 1373db2

Please sign in to comment.