Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hardik Juneja
slapos.toolbox
Commits
0afb7d60
Commit
0afb7d60
authored
Oct 14, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qemu QMP client: add driveBackup option.
parent
e0785803
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
17 deletions
+37
-17
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+37
-17
No files found.
slapos/qemuqmpclient/__init__.py
View file @
0afb7d60
...
...
@@ -31,23 +31,20 @@ import os
import
socket
import
time
QMP_STOP_ACTION
=
'suspend'
QMP_RESUME_ACTION
=
'resume'
QMP_CAPABILITIES_ACTION
=
'capabilities'
def
parseArgument
():
"""
Very basic argument parser. Might blow up for anything else than
"./executable mysocket.sock stop/resume".
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
unix_socket_location
'
)
parser
.
add_argument
(
'action'
,
choices
=
[
QMP_STOP_ACTION
,
QMP_RESUME_ACTION
,
QMP_CAPABILITIES_ACTION
]
)
parser
.
add_argument
(
'
--suspend'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'suspend
'
)
parser
.
add_argument
(
'--resume'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'resume'
)
parser
.
add_argument
(
'--drive-backup'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'driveBackup'
)
parser
.
add_argument
(
'--socket'
,
dest
=
'unix_socket_location'
,
required
=
True
)
parser
.
add_argument
(
'remainding_argument_list'
,
nargs
=
argparse
.
REMAINDER
)
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
):
...
...
@@ -127,17 +124,40 @@ class QemuQMPWrapper(object):
self
.
_send
({
'execute'
:
'cont'
})
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
():
unix_socket_location
,
action
=
parseArgument
()
unix_socket_location
,
action
,
remainding_argument_list
=
parseArgument
()
qemu_wrapper
=
QemuQMPWrapper
(
unix_socket_location
)
if
action
==
QMP_STOP_ACTION
:
qemu_wrapper
.
suspend
()
elif
action
==
QMP_RESUME_ACTION
:
qemu_wrapper
.
resume
()
elif
action
==
QMP_CAPABILITIES_ACTION
:
qemu_wrapper
.
capabilities
()
if
remainding_argument_list
:
getattr
(
qemu_wrapper
,
action
)(
*
remainding_argument_list
)
else
:
getattr
(
qemu_wrapper
,
action
)()
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment