add untested code to allow resuming of a hibernated VM

This commit is contained in:
Markus Hauschild
2013-12-15 16:38:55 +01:00
parent 680c56eebd
commit eb356897bb
2 changed files with 16 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ class VMHelper:
else: else:
raise Exception("Missing VMs config section!") raise Exception("Missing VMs config section!")
def startVM(self, vmid, managerpath): def startVM(self, vmid, managerpath, hibernate_ignore=False):
self.setupNetwork(vmid) self.setupNetwork(vmid)
cmd = [] cmd = []
@@ -95,6 +95,13 @@ class VMHelper:
cmd.append("-qmp") cmd.append("-qmp")
cmd.append("unix:" + self.config['kvm']['qmpsocket'].replace("$VMID", vmid) + ",server,nowait") cmd.append("unix:" + self.config['kvm']['qmpsocket'].replace("$VMID", vmid) + ",server,nowait")
hibernate_file = self.config['kvm']['hibernatefile'].replace("$VMID", vmid)
# check if ignore hibernate file flag is set
if (not hibernate_ignore):
if (os.path.isfile(hibernate_file)):
cmd.append("-incoming")
cmd.append("\"exec: cat " + hibernate_file + "\"")
if "runas" in self.config["kvm"]: if "runas" in self.config["kvm"]:
cmd.append("-runas") cmd.append("-runas")
cmd.append(self.config["kvm"]["runas"]) cmd.append(self.config["kvm"]["runas"])

View File

@@ -39,19 +39,24 @@ def vmm_start(args):
print("VM {0} is already running!".format(args.vmid)) print("VM {0} is already running!".format(args.vmid))
return return
#TODO: pass ignore hibernation file flag
print('Starting VM {0.vmid}.'.format(args)) print('Starting VM {0.vmid}.'.format(args))
fullpath_manager = os.path.realpath(sys.argv[0]) fullpath_manager = os.path.realpath(sys.argv[0])
if (args.i is not None and args.i >= 1):
helper.startVM(args.vmid, fullpath_manager, True)
else:
helper.startVM(args.vmid, fullpath_manager) helper.startVM(args.vmid, fullpath_manager)
#print("Successfully started: " + ("yes" if helper.process_running(args.vmid) else "no")) #print("Successfully started: " + ("yes" if helper.process_running(args.vmid) else "no"))
def vmm_shutdown(args): def vmm_shutdown(args):
print('Shutting down all VMs.')
timeout = SHUTDOWN_TIMEOUT if args.t is None or args.t < 0 else args.t timeout = SHUTDOWN_TIMEOUT if args.t is None or args.t < 0 else args.t
stCallback = lambda vmid, st : print("VM {0}: {1}".format(vmid, stopStatusToMessage[st])) stCallback = lambda vmid, st : print("VM {0}: {1}".format(vmid, stopStatusToMessage[st]))
helper.shutdownVMs(timeout, args.s is None or args.s < 1, statusCallback=stCallback) helper.shutdownVMs(timeout, args.s is None or args.s < 1, statusCallback=stCallback)
def vmm_hibernate(args): def vmm_hibernate(args):
print('Hibernating all VMs.')
#TODO: implement ;) #TODO: implement ;)
def vmm_stop(args): def vmm_stop(args):