-
Notifications
You must be signed in to change notification settings - Fork 1
/
total_storage_size_calc.py
41 lines (32 loc) · 1.48 KB
/
total_storage_size_calc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import ovirtsdk4 as sdk
# Create a connection to the oVirt Engine
connection = sdk.Connection(
url='<URL>',
username='<User>',
password='<Pass>',
ca_file='ca.pem',
)
vms_service = connection.system_service().vms_service()
vms = vms_service.list()
# Calculate the total size of disks for all the VMs
total_size_provisioned = 0
total_size_actual = 0
for vm in vms:
vm_service = vms_service.vm_service(vm.id)
disk_attachments_service = vm_service.disk_attachments_service()
disk_attachments = disk_attachments_service.list()
# Calculate the total provisioned size of disks for the VM
for disk_attachment in disk_attachments:
disk_service = connection.system_service().disks_service().disk_service(disk_attachment.disk.id)
disk = disk_service.get()
total_size_provisioned += disk.provisioned_size
# Calculate the total actual size of disks for the VM
for disk_attachment in disk_attachments:
disk_service = connection.system_service().disks_service().disk_service(disk_attachment.disk.id)
disk = disk_service.get()
total_size_actual += disk.actual_size
total_size_gb_actual = total_size_actual / 1073741824
total_size_gb_provisioned = total_size_provisioned / 1073741824
print(f'Total provisioned size of disks for all the VMs: {total_size_provisioned} bytes, {total_size_gb_provisioned} GB')
print(f'Total actual size of disks for all the VMs: {total_size_actual} bytes, {total_size_gb_actual} GB')
connection.close()