Show Table of Contents
2.8. Example: Listing the Size of a Virtual Machine
The
API class provides access to a virtual machine collection, named vms. This collection in turn contains a disks collection that describes the details of each disk attached to a virtual machine.
Example 2.7. Listing the Size of a Virtual Machine
This Python example prints a list of the virtual machines in the Red Hat Enterprise Virtualization environment along with their total disk size in bytes:
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
virtual_machines = api.vms.list()
if len(virtual_machines) > 0:
print("%-30s %s" % ("Name","Disk Size"))
print("==================================================")
for virtual_machine in virtual_machines:
disks = virtual_machine.disks.list()
disk_size = 0
for disk in disks:
disk_size += disk.get_size()
print("%-30s: %d" % (virtual_machine.get_name(), disk_size))
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.