Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2dbb5cd4
authored
8 years ago
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add disk snapshot operations
parent
7b358f8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
3 deletions
+80
-3
disk.py
+54
-1
storagedriver.py
+26
-2
No files found.
disk.py
View file @
2dbb5cd4
...
@@ -284,7 +284,60 @@ class Disk(object):
...
@@ -284,7 +284,60 @@ class Disk(object):
logger
.
info
(
"Extracting
%
s failed, keeping original."
,
logger
.
info
(
"Extracting
%
s failed, keeping original."
,
disk_path
)
disk_path
)
def
snapshot
(
self
):
def
common_snapshot_operation
(
self
,
cmdline
):
# Check if file already exists
if
not
os
.
path
.
isfile
(
self
.
get_path
()):
raise
Exception
(
'Image does not exists:
%
s'
%
self
.
get_path
())
# Build list of Strings as command parameters
if
self
.
format
==
'iso'
or
self
.
format
==
'raw'
:
raise
NotImplemented
()
else
:
# Call subprocess
try
:
return
subprocess
.
check_output
(
cmdline
)
except
subprocess
.
CalledProcessError
as
e
:
logger
.
error
(
e
)
raise
Exception
(
unicode
(
e
))
def
snapshot
(
self
,
snapshot_name
):
''' Creating qcow2 snapshot.
'''
cmdline
=
[
'qemu-img'
,
'snapshot'
,
'-c'
,
snapshot_name
,
self
.
get_path
()]
self
.
common_snapshot_operation
(
cmdline
)
def
list_snapshots
(
self
):
''' List qcow2 snapshot.
'''
cmdline
=
[
'qemu-img'
,
'info'
,
'--output'
,
'json'
,
self
.
get_path
()]
output
=
self
.
common_snapshot_operation
(
cmdline
)
json_data
=
json
.
loads
(
output
)
return
json_data
.
get
(
'snapshots'
,
[])
def
remove_snapshot
(
self
,
id
):
''' Remove qcow2 snapshot.
'''
cmdline
=
[
'qemu-img'
,
'snapshot'
,
'-d'
,
unicode
(
id
),
self
.
get_path
()]
self
.
common_snapshot_operation
(
cmdline
)
def
revert_snapshot
(
self
,
id
):
''' Revert qcow2 snapshot.
'''
cmdline
=
[
'qemu-img'
,
'snapshot'
,
'-a'
,
unicode
(
id
),
self
.
get_path
()]
self
.
common_snapshot_operation
(
cmdline
)
def
snapshot_from_base
(
self
):
''' Creating qcow2 snapshot with base image.
''' Creating qcow2 snapshot with base image.
'''
'''
# Check if snapshot type and qcow2 format matchmatch
# Check if snapshot type and qcow2 format matchmatch
...
...
This diff is collapsed.
Click to expand it.
storagedriver.py
View file @
2dbb5cd4
...
@@ -54,9 +54,33 @@ def delete_dump(disk_path):
...
@@ -54,9 +54,33 @@ def delete_dump(disk_path):
@celery.task
()
@celery.task
()
def
snapshot
(
json_data
):
def
snapshot
_from_base
(
json_data
):
disk
=
Disk
.
deserialize
(
json_data
)
disk
=
Disk
.
deserialize
(
json_data
)
disk
.
snapshot
()
disk
.
snapshot_from_base
()
@celery.task
()
def
snapshot
(
disk_desc
,
snapshot_name
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
snapshot
(
snapshot_name
)
@celery.task
()
def
list_snapshots
(
disk_desc
):
disk
=
Disk
.
deserialize
(
disk_desc
)
return
disk
.
list_snapshots
()
@celery.task
()
def
remove_snapshot
(
disk_desc
,
snapshot_id
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
remove_snapshot
(
snapshot_id
)
@celery.task
()
def
revert_snapshot
(
disk_desc
,
snapshot_id
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
revert_snapshot
(
snapshot_id
)
class
merge
(
AbortableTask
):
class
merge
(
AbortableTask
):
...
...
This diff is collapsed.
Click to expand it.
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