From 99255f4aae97750a063d93eedf9ac08ab7ccb38c Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 10:47:54 +0200 Subject: [PATCH 1/6] check image name booted from volume --- fedcloud_vm_monitoring/site_monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index cd89a63..769d723 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -114,7 +114,7 @@ def get_vm_image_server_show(self, vm_id): return "image name not found" def get_vm_image(self, vm_id, image_name, image_id): - if len(image_name) > 0: + if (len(image_name) > 0) and (not 'booted from volume' in image_name): return image_name else: try: From b617c921ce7b688b802344146d4a483bf21012d4 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 11:07:51 +0200 Subject: [PATCH 2/6] update README with new output --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a799f12..1b71aa2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ cloud providers supporting the OIDC protocol. - For getting the EGI user identity, cloud providers have to enable the `"identity:get_user"` API call for the user (see [VO auditing](https://docs.egi.eu/providers/cloud-compute/openstack/aai/#vo-auditing) - for more information + for more information) ## Installation @@ -69,7 +69,9 @@ Getting VMs information [####################################] 100% instance id = 0d9d8c9b-a161-4b59-9ba6-7275e898c7fb status = ACTIVE ip address = 192.168.1.31 + SSH version = No public IP available to check SSH version. flavor = svc1.m with 2 vCPU cores, 4 GB of RAM and 40 GB of local disk + VM image = ubuntu-22.04-amd64-raw created at = 2024-06-24T06:25:30Z elapsed time = 14 days, 3:50:14.385004 user = [REDACTED] @@ -78,7 +80,9 @@ Getting VMs information [####################################] 100% instance id = d6815b91-599d-4c6a-8d55-a38243148838 status = ACTIVE ip address = 192.168.1.250 194.210.120.242 + SSH version = SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6 flavor = svc2.l with 8 vCPU cores, 8 GB of RAM and 40 GB of local disk + VM image = ubuntu-22.04-amd64-raw created at = 2022-08-31T07:17:18Z elapsed time = 677 days, 2:58:26.385004 user = [REDACTED] @@ -88,7 +92,9 @@ Getting VMs information [####################################] 100% instance id = 045ec1e7-b47a-4f18-9c9f-06cb30803955 status = ACTIVE ip address = 192.168.1.71 194.210.120.90 + SSH version = SSHException: could not retrieve SSH version flavor = svc2.m with 4 vCPU cores, 4 GB of RAM and 40 GB of local disk + VM image = image name not found created at = 2020-11-13T09:01:32Z elapsed time = 1333 days, 1:14:12.385004 user = [REDACTED] @@ -110,7 +116,9 @@ Getting VMs information [####################################] 100% instance id = 5d56f0af-05aa-442a-8536-8667e9f81a82 status = ACTIVE ip address = 192.168.10.9 - flavor = m1.large with 4 vCPU cores, 8 GB of RAM and 30 GB of local disk + SSH version = No public IP available to check SSH version. + flavor = m1.medium with 2 vCPU cores, 4 GB of RAM and 20 GB of local disk + VM image = ubuntu-jammy-x86_64 created at = 2024-06-24T15:03:27Z elapsed time = 13 days, 19:12:48.034861 user = [REDACTED] @@ -121,7 +129,9 @@ Getting VMs information [####################################] 100% instance id = 46ec6648-d364-4ca7-9480-5af64cda9e9c status = ACTIVE ip address = 192.168.10.53 + SSH version = No public IP available to check SSH version. flavor = m1.large with 4 vCPU cores, 8 GB of RAM and 30 GB of local disk + VM image = ubuntu-jammy-x86_64 created at = 2024-04-12T06:48:32Z elapsed time = 87 days, 3:27:43.034861 user = [REDACTED] @@ -133,7 +143,9 @@ Getting VMs information [####################################] 100% instance id = 1beb4b53-d6e4-4e30-8046-222b4e82b806 status = ACTIVE ip address = 192.168.10.72 + SSH version = No public IP available to check SSH version. flavor = m1.large with 4 vCPU cores, 8 GB of RAM and 30 GB of local disk + VM image = ubuntu-jammy-x86_64 created at = 2024-04-12T06:48:30Z elapsed time = 87 days, 3:27:45.034861 user = [REDACTED] @@ -145,7 +157,9 @@ Getting VMs information [####################################] 100% instance id = 8e530674-d4a6-482c-974f-376eacbe609a status = ACTIVE ip address = 192.168.10.144 147.213.76.76 + SSH version = SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.10 flavor = m1.large with 4 vCPU cores, 8 GB of RAM and 30 GB of local disk + VM image = ubuntu-jammy-x86_64 created at = 2024-04-12T06:48:18Z elapsed time = 87 days, 3:27:57.034861 user = [REDACTED] @@ -157,7 +171,9 @@ Getting VMs information [####################################] 100% instance id = 8ef9fcce-19e4-41c6-ab03-d1730a924510 status = ACTIVE ip address = 192.168.10.69 147.213.76.217 + SSH version = SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.11 flavor = m1.medium with 2 vCPU cores, 4 GB of RAM and 20 GB of local disk + VM image = Ubuntu-20.04-20211006 created at = 2021-12-02T14:53:32Z elapsed time = 948 days, 19:22:43.034861 user = [REDACTED] From 3c9996fb648041f43968c838562a05e82b915423 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 11:12:32 +0200 Subject: [PATCH 3/6] proper releases should be done --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 78f93ef..f50c2aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fedcloud-vm-monitoring" -version = "0.1.0" +version = "0.2.0" description = "Monitoring fedcloud VMs and sites" authors = ["Giuseppe La Rocca ", "Enol Fernandez "] From c052194fe32229ef00953a47e40b7a82715c36ba Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 11:16:13 +0200 Subject: [PATCH 4/6] linting --- fedcloud_vm_monitoring/site_monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index 769d723..e467912 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -114,7 +114,7 @@ def get_vm_image_server_show(self, vm_id): return "image name not found" def get_vm_image(self, vm_id, image_name, image_id): - if (len(image_name) > 0) and (not 'booted from volume' in image_name): + if (len(image_name) > 0) and ("booted from volume" not in image_name): return image_name else: try: From 5759258141eb9e1251ef7e75248374e31fc47c46 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 14:56:56 +0200 Subject: [PATCH 5/6] image_name as last resort --- fedcloud_vm_monitoring/site_monitor.py | 48 +++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index e467912..d5bda6c 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -84,7 +84,13 @@ def get_flavor(self, flavor_name): return {} return self.flavors[flavor_name] - def get_vm_image_volume_show(self, volume_id): + def get_vm_image_name(self, image_name): + if len(image_name) > 0: + return image_name + else: + return "image name not found" + + def get_vm_image_volume_show(self, volume_id, image_name): try: cmd = ("volume", "show", volume_id, "--format", "json") result = self._run_command(cmd) @@ -95,18 +101,23 @@ def get_vm_image_volume_show(self, volume_id): result["volume_image_metadata"]["sl:osname"] + result["volume_image_metadata"]["sl:osversion"] ) + elif ("volume_image_metadata" in result) and ( + "image_name" in result["volume_image_metadata"] + ): + return result["volume_image_metadata"]["image_name"] else: - return "image name not found" + return self.get_vm_image_name(image_name) except SiteMonitorException: - return "image name not found" + return self.get_vm_image_name(image_name) - def get_vm_image_server_show(self, vm_id): + def get_vm_image_server_show(self, vm_id, image_name): try: cmd = ("server", "show", vm_id, "--format", "json") result = self._run_command(cmd) if len(result["attached_volumes"]) > 0: return self.get_vm_image_volume_show( - result["attached_volumes"][0]["id"] + result["attached_volumes"][0]["id"], + image_name ) else: return "image name not found" @@ -114,21 +125,18 @@ def get_vm_image_server_show(self, vm_id): return "image name not found" def get_vm_image(self, vm_id, image_name, image_id): - if (len(image_name) > 0) and ("booted from volume" not in image_name): - return image_name - else: - try: - cmd = ("image", "show", image_id, "--format", "json") - result = self._run_command(cmd) - if "sl:osname" and "sl:osversion" in result["properties"]: - return ( - result["properties"]["sl:osname"] - + result["properties"]["sl:osversion"] - ) - else: - return self.get_vm_image_server_show(vm_id) - except SiteMonitorException: - return self.get_vm_image_server_show(vm_id) + try: + cmd = ("image", "show", image_id, "--format", "json") + result = self._run_command(cmd) + if "sl:osname" and "sl:osversion" in result["properties"]: + return ( + result["properties"]["sl:osname"] + + result["properties"]["sl:osversion"] + ) + else: + return self.get_vm_image_server_show(vm_id, image_name) + except SiteMonitorException: + return self.get_vm_image_server_show(vm_id, image_name) def get_vms(self): command = ("server", "list", "--long") From c78882987ec7af16d790e2534b8d23defcac6d67 Mon Sep 17 00:00:00 2001 From: Sebastian Luna-Valero Date: Tue, 16 Jul 2024 15:18:39 +0200 Subject: [PATCH 6/6] linting --- fedcloud_vm_monitoring/site_monitor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fedcloud_vm_monitoring/site_monitor.py b/fedcloud_vm_monitoring/site_monitor.py index d5bda6c..cb8640f 100644 --- a/fedcloud_vm_monitoring/site_monitor.py +++ b/fedcloud_vm_monitoring/site_monitor.py @@ -116,8 +116,7 @@ def get_vm_image_server_show(self, vm_id, image_name): result = self._run_command(cmd) if len(result["attached_volumes"]) > 0: return self.get_vm_image_volume_show( - result["attached_volumes"][0]["id"], - image_name + result["attached_volumes"][0]["id"], image_name ) else: return "image name not found"