Source code for ducky.devices.snapshot

from . import Device

[docs]class SnapshotStorage(Device): def __init__(self, machine, name, *args, **kwargs): super(SnapshotStorage, self).__init__(machine, 'snapshot', name, *args, **kwargs) @staticmethod
[docs] def create_from_config(machine, config, section): return SnapshotStorage(machine, section)
[docs] def save_snapshot(self, snapshot): pass
[docs] def halt(self): self.machine.capture_state()
[docs]class FileSnapshotStorage(SnapshotStorage): def __init__(self, machine, name, filepath = None, *args, **kwargs): super(FileSnapshotStorage, self).__init__(machine, name, *args, **kwargs) self.filepath = filepath @staticmethod
[docs] def create_from_config(machine, config, section): return FileSnapshotStorage(machine, section, filepath = config.get(section, 'filepath', None))
[docs] def save_snapshot(self, snapshot): snapshot.save(self.filepath) self.machine.tenh('snapshot: saved in file %s', self.filepath)
[docs] def boot(self): self.machine.tenh('snapshot: storage ready, backed by file %s', self.filepath)
[docs] def halt(self): super(FileSnapshotStorage, self).halt() self.save_snapshot(self.machine.last_state)
[docs]class DefaultFileSnapshotStorage(FileSnapshotStorage): @staticmethod
[docs] def create_from_config(machine, config, section): return DefaultFileSnapshotStorage(machine, section, filepath = 'ducky-snapshot.bin')