Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display version of SSH #17

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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