Package: invirt-remote-host
Architecture: all
Depends: ${misc:Depends}, daemon, remctl-server, invirt-console-host,
- invirt-vnc-server, python-cjson, python-pyinotify, python-yaml,
- util-linux, openbsd-inetd
+ invirt-vnc-server, python-cjson, python-pyinotify, python-sqlalchemy,
+ python-yaml, util-linux, openbsd-inetd
Description: Installs the Invirt host remctl configuration
This is the remctl configuration for an Invirt host. It allows any
commands to be run from the Invirt remote server
--- /dev/null
+#!/usr/bin/env python
+
+from invirt import database as db
+from invirt.config import structs as config
+import sqlalchemy as sa
+from subprocess import Popen, PIPE
+
+prefix = 'd_'
+
+# First figure out what the database thinks our sets of disks and sizes are
+db.connect()
+s = sa.sql.select([db.machine_table.c.name, db.disk_table.c.guest_device_name,
+ db.disk_table.c.size],
+ db.machine_table.c.machine_id == db.disk_table.c.machine_id,
+ [db.machine_table, db.disk_table])
+dbresult = db.session.execute(s)
+db_disks = {}
+for (machine, device, size) in dbresult.fetchall():
+ db_disks['d_' + machine + '_' + device] = int(size)
+
+# Now figure out what the disk images actually in existence look like
+p = Popen(['/sbin/lvs', '--noheadings', '-o', 'lv_name,lv_size', '--units', 'm',
+ '--unbuffered', '--nosuffix', '--separator', ':', config.lvm.vg],
+ stdout=PIPE)
+lvresult = p.communicate()[0]
+lv_disks = {}
+for lv in lvresult.split():
+ (lvname, size) = lv.split(':')
+ if not lvname.startswith(prefix):
+ continue
+ # We only want the whole number of MiB, to match the database
+ lv_disks[lvname] = int(float(size))
+
+missing_disks = []
+orphaned_disks = []
+size_discrepancies = []
+
+for disk in db_disks:
+ if disk not in lv_disks:
+ missing_disks.append(disk)
+ elif db_disks[disk] != lv_disks[disk]:
+ size_discrepancies.append(disk)
+for disk in lv_disks:
+ if disk not in db_disks:
+ orphaned_disks.append(disk)
+
+if missing_disks:
+ print '===== The following disks are in the DB but the LVs do not exist'
+ missing_disks.sort()
+ for disk in missing_disks:
+ print disk.ljust(45) + 'DB: %s' % str(db_disks[disk]).rjust(6)
+ print '\n'
+if orphaned_disks:
+ print '===== The following LVs exist but are not assigned to a VM'
+ orphaned_disks.sort()
+ for disk in orphaned_disks:
+ print disk.ljust(59) + 'LVM: %s' % str(lv_disks[disk]).rjust(6)
+ print '\n'
+if size_discrepancies:
+ print '===== The following disks have different sizes in the DB and LVM'
+ size_discrepancies.sort()
+ for disk in size_discrepancies:
+ print disk.ljust(45) +\
+ 'DB: %s LVM: %s' % (str(db_disks[disk]).rjust(6),
+ str(lv_disks[disk]).rjust(6))
+ print '\n'
+print 'There are %i inconsistencies between the DB and LVM at this time.' %\
+ (missing_disks.__len__() +
+ orphaned_disks.__len__() +
+ size_discrepancies.__len__())
+