Skip to content

Commit

Permalink
Merge pull request #16 from EGI-Federation/show-images
Browse files Browse the repository at this point in the history
Add image name to output
  • Loading branch information
enolfc authored Jul 16, 2024
2 parents 60841d8 + 5bb6752 commit a2cd4cf
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion fedcloud_vm_monitoring/site_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,54 @@ def get_flavor(self, flavor_name):
return {}
return self.flavors[flavor_name]

def get_vm_image_volume_show(self, volume_id):
try:
cmd = ("volume", "show", volume_id, "--format", "json")
result = self._run_command(cmd)
if ("volume_image_metadata" in result) and (
"sl:osname" and "sl:osversion" in result["volume_image_metadata"]
):
return (
result["volume_image_metadata"]["sl:osname"]
+ result["volume_image_metadata"]["sl:osversion"]
)
else:
return "image name not found"
except SiteMonitorException:
return "image name not found"

def get_vm_image_server_show(self, vm_id):
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"]
)
else:
return "image name not found"
except SiteMonitorException:
return "image name not found"

def get_vm_image(self, vm_id, image_name, image_id):
if len(image_name) > 0:
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)

def get_vms(self):
command = ("server", "list")
command = ("server", "list", "--long")
return self._run_command(command)

def get_vm(self, vm):
Expand Down Expand Up @@ -173,6 +219,9 @@ def process_vm(self, vm):
f"GB of RAM and {flv['Disk']} GB of local disk",
)
)
output.append(
("VM image", self.get_vm_image(vm["ID"], vm["Image Name"], vm["Image ID"]))
)
output.append(("created at", vm_info["created_at"]))
output.append(("elapsed time", elapsed))
user_id = vm_info["user_id"]
Expand Down

0 comments on commit a2cd4cf

Please sign in to comment.