Skip to content

Commit

Permalink
adds allocated resources to info saltstack#288
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi1693 committed Oct 20, 2022
1 parent 3044490 commit 81d181f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 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 Expand Up @@ -650,6 +657,7 @@ def relocate(
return {"virtual_machine": "moved"}
return {"virtual_machine": "failed to move"}


def get_mks_ticket(vm_name, ticket_type, service_instance=None, profile=None):
"""
Get ticket of virtual machine of passed object type.
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

0 comments on commit 81d181f

Please sign in to comment.