From 697c7e4fd52389a84427d4d807525e1e41e544d0 Mon Sep 17 00:00:00 2001 From: RageLtMan Date: Sat, 26 Nov 2016 00:52:06 -0500 Subject: [PATCH] LibVirt machinery should create the KVM domain Currently, LibVirt machinery can determine the snapshot and revert the VM state to it, but it jumps straight to waiting for a state change without actually issuing a create call to the domain being used. This is likely due to it expecting a live-state snapshot to be instantiated which automatically starts the instance. Add a conditional call self.vms[label].create() after resolving VM snapshot state and prior to entering the wait state. If the VM power state is still off, try to create the KVM domain with basic error handling. This should not case race conditions as preceeding snapshot operations are serialized and complete prior to returning. --- lib/cuckoo/common/abstracts.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/cuckoo/common/abstracts.py b/lib/cuckoo/common/abstracts.py index e42b42730..b52748be4 100644 --- a/lib/cuckoo/common/abstracts.py +++ b/lib/cuckoo/common/abstracts.py @@ -392,6 +392,16 @@ def start(self, label): self._disconnect(conn) raise CuckooMachineError("No snapshot found for virtual machine " "{0}".format(label)) + # Attempt to boot the VM (create domain) if it's powered off + # This should address use of offline snapshots for fast clones/other uses. + if self._status(label) == self.POWEROFF: + try: + self.vms[label].create() + except libvirt.libvirtError: + raise CuckooMachineError("Unable to create domain for " + "virtual machine {0}".format(label)) + finally: + self._disconnect(conn) # Check state. self._wait_status(label, self.RUNNING)