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
Lu Xu
slapos.toolbox
Commits
95d0c8b9
Commit
95d0c8b9
authored
Oct 14, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qemu: add other useful helpers for QMP.
parent
0afb7d60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
2 deletions
+39
-2
slapos/qemuqmpclient/__init__.py
slapos/qemuqmpclient/__init__.py
+39
-2
No files found.
slapos/qemuqmpclient/__init__.py
View file @
95d0c8b9
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
import
argparse
import
argparse
import
json
import
json
import
os
import
os
import
pprint
import
socket
import
socket
import
time
import
time
...
@@ -39,11 +40,15 @@ def parseArgument():
...
@@ -39,11 +40,15 @@ def parseArgument():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--suspend'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'suspend'
)
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
(
'--resume'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'resume'
)
parser
.
add_argument
(
'--create-snapshot'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'createSnapshot'
)
parser
.
add_argument
(
'--create-internal-snapshot'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'createInternalSnapshot'
)
parser
.
add_argument
(
'--delete-internal-snapshot'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'deleteInternalSnapshot'
)
parser
.
add_argument
(
'--drive-backup'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'driveBackup'
)
parser
.
add_argument
(
'--drive-backup'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'driveBackup'
)
parser
.
add_argument
(
'--query-commands'
,
action
=
'store_const'
,
dest
=
'action'
,
const
=
'queryCommands'
)
parser
.
add_argument
(
'--socket'
,
dest
=
'unix_socket_location'
,
required
=
True
)
parser
.
add_argument
(
'--socket'
,
dest
=
'unix_socket_location'
,
required
=
True
)
parser
.
add_argument
(
'remainding_argument_list'
,
nargs
=
argparse
.
REMAINDER
)
parser
.
add_argument
(
'remainding_argument_list'
,
nargs
=
argparse
.
REMAINDER
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
print
args
return
args
.
unix_socket_location
,
args
.
action
,
args
.
remainding_argument_list
return
args
.
unix_socket_location
,
args
.
action
,
args
.
remainding_argument_list
...
@@ -83,7 +88,7 @@ class QemuQMPWrapper(object):
...
@@ -83,7 +88,7 @@ class QemuQMPWrapper(object):
def
_send
(
self
,
message
):
def
_send
(
self
,
message
):
self
.
socket
.
send
(
json
.
dumps
(
message
))
self
.
socket
.
send
(
json
.
dumps
(
message
))
data
=
self
.
socket
.
recv
(
1024
)
data
=
self
.
socket
.
recv
(
65535
)
try
:
try
:
return
json
.
loads
(
data
)
return
json
.
loads
(
data
)
except
ValueError
:
except
ValueError
:
...
@@ -149,6 +154,38 @@ class QemuQMPWrapper(object):
...
@@ -149,6 +154,38 @@ class QemuQMPWrapper(object):
print
'Job is not finished yet.'
print
'Job is not finished yet.'
time
.
sleep
(
20
)
time
.
sleep
(
20
)
def
createSnapshot
(
self
,
snapshot_file
,
device
=
'virtio0'
):
print
self
.
_send
({
'execute'
:
'blockdev-snapshot-sync'
,
'arguments'
:
{
'device'
:
device
,
'snapshot-file'
:
snapshot_file
,
}
})
def
createInternalSnapshot
(
self
,
name
=
None
,
device
=
'virtio0'
):
if
name
is
None
:
name
=
int
(
time
.
time
())
self
.
_send
({
'execute'
:
'blockdev-snapshot-internal-sync'
,
'arguments'
:
{
'device'
:
device
,
'name'
:
name
,
}
})
def
deleteInternalSnapshot
(
self
,
name
,
device
=
'virtio0'
):
self
.
_send
({
'execute'
:
'blockdev-snapshot-delete-internal-sync'
,
'arguments'
:
{
'device'
:
device
,
'name'
:
name
,
}
})
def
queryCommands
(
self
):
pprint
.
pprint
(
self
.
_send
({
'execute'
:
'query-commands'
})[
'return'
])
def
main
():
def
main
():
unix_socket_location
,
action
,
remainding_argument_list
=
parseArgument
()
unix_socket_location
,
action
,
remainding_argument_list
=
parseArgument
()
qemu_wrapper
=
QemuQMPWrapper
(
unix_socket_location
)
qemu_wrapper
=
QemuQMPWrapper
(
unix_socket_location
)
...
...
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