Skip to content

Commit

Permalink
Merge pull request #17 from EGI-Federation/ssh-info
Browse files Browse the repository at this point in the history
Display version of SSH
  • Loading branch information
enolfc authored Jul 16, 2024
2 parents 5664055 + 4edea37 commit 60841d8
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 105 deletions.
27 changes: 27 additions & 0 deletions fedcloud_vm_monitoring/site_monitor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Monitor VM instances running in the provider"""

import ipaddress
from collections import defaultdict
from datetime import datetime, timezone

import click
import ldap3
import paramiko
from dateutil.parser import parse
from fedcloudclient.openstack import fedcloud_openstack
from fedcloudclient.sites import find_endpoint_and_project_id
from ldap3.core.exceptions import LDAPException
from paramiko import SSHException


class SiteMonitorException(Exception):
Expand Down Expand Up @@ -124,19 +127,43 @@ def get_user_email(self, egi_user):
return f"{egi_user} not found in LDAP, has VO membership expired?"
return self.user_emails[egi_user]

def get_public_ip(self, ip_addresses):
result = ""
for ip in ip_addresses:
if ipaddress.ip_address(ip).is_global:
result = ip
return result

def get_sshd_version(self, ip_addresses):
public_ip = self.get_public_ip(ip_addresses)
if len(public_ip) > 0:
try:
ssh = paramiko.Transport((public_ip, 22))
ssh.start_client()
result = ssh.remote_version
ssh.close()
return result
except SSHException:
return "SSHException: could not retrieve SSH version"
else:
return "No public IP available to check SSH version."

def process_vm(self, vm):
vm_info = self.get_vm(vm)
flv = self.get_flavor(vm["Flavor"])
vm_ips = []
sshd_version = "N/A"
for net, addrs in vm["Networks"].items():
vm_ips.extend(addrs)
sshd_version = self.get_sshd_version(addrs)
created = parse(vm_info["created_at"])
elapsed = self.now - created
output = [
("instance name", vm["Name"]),
("instance id", vm["ID"]),
("status", click.style(vm["Status"], fg=self.color_maps[vm["Status"]])),
("ip address", " ".join(vm_ips)),
("SSH version", sshd_version),
]
if flv:
output.append(
Expand Down
Loading

0 comments on commit 60841d8

Please sign in to comment.