3.7. 列出虚拟机和总磁盘大小
vms
集合包含一个 磁盘
集合,用于描述附加到虚拟机的每个磁盘的详细信息。
例 3.5. 列出虚拟机以及总磁盘大小
这个示例打印虚拟机列表及其总磁盘大小(以字节为单位):
V4
import ovirtsdk4 as sdk import ovirtsdk4.types as types connection = sdk.Connection( url='https://engine.example.com/ovirt-engine/api', username='admin@internal', password='password', ca_file='ca.pem', ) vms_service = connection.system_service().vms_service() virtual_machines = vms_service.list() if len(virtual_machines) > 0: print("%-30s %s" % ("Name", "Disk Size")) print("==================================================") for virtual_machine in virtual_machines: vm_service = vms_service.vm_service(virtual_machine.id) disk_attachments = vm_service.disk_attachments_service().list() disk_size = 0 for disk_attachment in disk_attachments: disk = connection.follow_link(disk_attachment.disk) disk_size += disk.provisioned_size print("%-30s: %d" % (virtual_machine.name, disk_size))
示例输出虚拟机名称及其磁盘大小:
Name Disk Size ================================================== vm1 50000000000