PR 1181 remake

Rebase the relevant parts of PR #1181, so @will-Do needs only make a smaller PR against tp-libvirt.