How to get size of a vm througt python sdk?
environment : rhev 3.3
plateform : python sdk api
information search : size of the vm
Hi,
I work with the sdk api in python, I want to know the disk size of the vm, someone help me?
I work with this command :
disk = params.Disk(vm)
print "size of the vm" % (disk.get_size)
The result of the print is the value of "params.Disk(vm)" and not the get_size of the vm.
For exemple the result is :
I want to keep the size of all the disks used by the virtual machine.
Thanks for your help
Emeline Vales
Responses
Hi Emeline,
After playing around with the Python SDK for a bit, I have had some success in getting the total size of a virtual machine via the following:
First, get a list of virtual machines in the environment:
virtual_machines = api.vms.list()
for virtual_machine in virtual_machines:
Second, get the list of disks attached to a virtual machine:
disks = virtual_machine.disks.list()
disk_size = 0
For each of the disks, get the disk size and add it to the total:
for disk in disks:
disk_size += disk.get_size()
Print the results:
print("%-30s: %d" % (virtual_machine.get_name(), disk_size))
Hope this does the trick.
Kind regards,
Andrew
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
