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

Adds allocated resources to vm info #310

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion src/saltext/vmware/modules/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,13 @@ def info(vm_name=None, service_instance=None, profile=None):
datacenter_ref = utils_common.get_parent_type(vm, vim.Datacenter)
mac_address = utils_vm.get_mac_address(vm)
network = utils_vm.get_network(vm)
disk_bytes = utils_vm.get_disk_size(vm)
tags = []
for tag in vm.tag:
tags.append(tag.name)
try:
tags.append(tag.name)
except AttributeError:
pass
folder_path = utils_common.get_path(vm, service_instance)
info[vm.summary.config.name] = {
"guest_name": vm.summary.config.name,
Expand All @@ -313,6 +317,9 @@ def info(vm_name=None, service_instance=None, profile=None):
"tags": tags,
"folder": folder_path,
"moid": vm._moId,
"num_cpu": vm.config.hardware.numCPU,
"memory_mb": vm.config.hardware.memoryMB,
"disk_bytes": disk_bytes,
}
return info

Expand Down
14 changes: 14 additions & 0 deletions src/saltext/vmware/utils/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,20 @@ def read_ovf_from_ova(ova_path):
exit(f"Could not read file: {ova_path}")


def get_disk_size(vm):
"""
Returns total disk size in bytes from the virtual machine object.
vm
Virtual Machine Object from which to obtain disk size.
"""
size = 0.0
for device in vm.config.hardware.device:
if isinstance(device, vim.vm.device.VirtualDisk):
size += device.capacityInBytes

return size


def get_network(vm):
"""
Returns network from a virtual machine object.
Expand Down