Qemu QMP client: add driveBackup option.

parent e0785803
...@@ -31,23 +31,20 @@ import os ...@@ -31,23 +31,20 @@ import os
import socket import socket
import time import time
QMP_STOP_ACTION = 'suspend'
QMP_RESUME_ACTION = 'resume'
QMP_CAPABILITIES_ACTION = 'capabilities'
def parseArgument(): def parseArgument():
""" """
Very basic argument parser. Might blow up for anything else than Very basic argument parser. Might blow up for anything else than
"./executable mysocket.sock stop/resume". "./executable mysocket.sock stop/resume".
""" """
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('unix_socket_location') parser.add_argument('--suspend', action='store_const', dest='action', const='suspend')
parser.add_argument( parser.add_argument('--resume', action='store_const', dest='action', const='resume')
'action', parser.add_argument('--drive-backup', action='store_const', dest='action', const='driveBackup')
choices=[QMP_STOP_ACTION, QMP_RESUME_ACTION, QMP_CAPABILITIES_ACTION] parser.add_argument('--socket', dest='unix_socket_location', required=True)
) parser.add_argument('remainding_argument_list', nargs=argparse.REMAINDER)
args = parser.parse_args() args = parser.parse_args()
return args.unix_socket_location, args.action print args
return args.unix_socket_location, args.action, args.remainding_argument_list
class QemuQMPWrapper(object): class QemuQMPWrapper(object):
...@@ -127,17 +124,40 @@ class QemuQMPWrapper(object): ...@@ -127,17 +124,40 @@ class QemuQMPWrapper(object):
self._send({'execute': 'cont'}) self._send({'execute': 'cont'})
self._waitForVMStatus('running') self._waitForVMStatus('running')
def _queryBlockJobs(self, device):
return self._send({'execute': 'query-block-jobs'})
def _getRunningJobList(self, device):
result = self._queryBlockJobs(device)
if result.get('return'):
return result['return']
else:
return
def driveBackup(self, backup_target, source_device='virtio0', sync_type='full'):
print 'Asking Qemu to perform backup to %s' % backup_target
# XXX: check for error
self._send({
'execute': 'drive-backup',
'arguments': {
'device': source_device,
'sync': sync_type,
'target': backup_target,
}
})
while self._getRunningJobList(backup_target):
print 'Job is not finished yet.'
time.sleep(20)
def main(): def main():
unix_socket_location, action = parseArgument() unix_socket_location, action, remainding_argument_list = parseArgument()
qemu_wrapper = QemuQMPWrapper(unix_socket_location) qemu_wrapper = QemuQMPWrapper(unix_socket_location)
if action == QMP_STOP_ACTION: if remainding_argument_list:
qemu_wrapper.suspend() getattr(qemu_wrapper, action)(*remainding_argument_list)
elif action == QMP_RESUME_ACTION: else:
qemu_wrapper.resume() getattr(qemu_wrapper, action)()
elif action == QMP_CAPABILITIES_ACTION:
qemu_wrapper.capabilities()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment