You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
9 years ago
|
#!/usr/bin/python
|
||
9 years ago
|
# Check if all libvirt domains are prepared for TRIM/fstrim
|
||
|
|
||
|
from __future__ import division, print_function
|
||
|
|
||
|
from lxml import objectify
|
||
|
import libvirt
|
||
|
import sys
|
||
|
|
||
|
|
||
9 years ago
|
conn = libvirt.openReadOnly('qemu:///system')
|
||
9 years ago
|
if not conn:
|
||
|
print('Failed to open connection to the hypervisor!')
|
||
|
sys.exit(1)
|
||
|
|
||
9 years ago
|
if not hasattr(conn, "listAllDomains"):
|
||
|
print('connection does not have listAllDomains(), is python-libvirt too old?')
|
||
|
sys.exit(1)
|
||
|
|
||
9 years ago
|
for domain in conn.listAllDomains():
|
||
|
print('== {}'.format(domain.name()))
|
||
|
|
||
|
xml = domain.XMLDesc()
|
||
|
tree = objectify.fromstring(xml)
|
||
|
|
||
9 years ago
|
machine = tree.os.type.get('machine')
|
||
|
if machine < 'pc-i440fx-2.1':
|
||
|
print('machine should be at least pc-i440fx-2.1')
|
||
|
# Might want to check qemu-system-x86_64 -M help for supported
|
||
|
# machines.
|
||
|
|
||
|
if not hasattr(tree.devices, 'disk'):
|
||
|
print('(has no disks)')
|
||
|
continue
|
||
|
|
||
9 years ago
|
# every disk should be scsi + discard=unmap
|
||
|
for disk in tree.devices.disk:
|
||
|
if disk.get('device') != 'disk':
|
||
|
continue
|
||
|
|
||
|
disk_desc = disk.target.get('dev')
|
||
|
|
||
|
if disk.target.get('bus') != 'scsi':
|
||
|
print('{} target should be scsi'.format(disk_desc))
|
||
|
if disk.driver.get('discard') != 'unmap':
|
||
|
print('{} driver should have discard=unmap'.format(disk_desc))
|
||
|
|
||
|
# every scsi controller should be model='virtio-scsi'
|
||
|
for controller in tree.devices.controller:
|
||
|
if controller.get('type') != 'scsi':
|
||
|
continue
|
||
|
|
||
|
if controller.get('model') != 'virtio-scsi':
|
||
|
print('scsi controller should be a virtio model')
|