Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0eab3c8
authored
Sep 26, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring function names, fixing type and formats, fix snapshot qemu command
parent
1f0f1ade
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
18 deletions
+24
-18
disk.py
+16
-10
storagedriver.py
+8
-8
No files found.
disk.py
View file @
d0eab3c8
...
...
@@ -12,18 +12,20 @@ class Disk(object):
Handle qcow2, raw and iso images.
TYPES, CREATE_TYPES, SNAPSHOT_TYPES are hand managed restrictions.
'''
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
TYPES
=
[
'snapshot'
,
'normal'
]
FORMATS
=
[
'qcow2'
,
'raw'
,
'iso'
]
CREATE_FORMATS
=
[
'qcow2'
,
'raw'
]
CREATE_TYPES
=
[
'qcow2'
,
'raw'
]
def
__init__
(
self
,
dir
,
name
,
format
,
size
,
base_name
):
def
__init__
(
self
,
dir
,
name
,
format
,
type
,
size
,
base_name
):
# TODO: tests
self
.
name
=
name
self
.
dir
=
os
.
path
.
realpath
(
dir
)
if
format
not
in
[
k
[
0
]
for
k
in
self
.
TYPES
]
:
if
format
not
in
self
.
FORMATS
:
raise
Exception
(
'Invalid format:
%
s'
%
format
)
self
.
format
=
format
if
type
not
in
self
.
TYPES
:
raise
Exception
(
'Invalid type:
%
s'
%
format
)
self
.
type
=
type
self
.
size
=
int
(
size
)
self
.
base_name
=
base_name
...
...
@@ -78,8 +80,10 @@ class Disk(object):
self.format van be "qcow2-normal"
'''
# Check if type is avaliable to create
if
self
.
format
not
in
self
.
CREATE_
TYPE
S
:
if
self
.
format
not
in
self
.
CREATE_
FORMAT
S
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
if
self
.
type
!=
'normal'
:
raise
Exception
(
'Invalid type:
%
s'
%
self
.
format
)
# Check for file if already exist
if
os
.
path
.
isfile
(
self
.
get_path
()):
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
...
...
@@ -94,9 +98,11 @@ class Disk(object):
def
snapshot
(
self
):
''' Creating qcow2 snapshot with base image.
'''
# Check if snapshot type match
# Check if snapshot type
and qcow2 format match
match
if
self
.
format
!=
'qcow2'
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
if
self
.
type
!=
'snapshot'
:
raise
Exception
(
'Invalid type:
%
s'
%
self
.
format
)
# Check if file already exists
if
os
.
path
.
isfile
(
self
.
get_path
()):
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
...
...
@@ -106,9 +112,9 @@ class Disk(object):
# Build list of Strings as command parameters
cmdline
=
[
'qemu-img'
,
'create'
,
'-f'
,
self
.
format
,
'-b'
,
self
.
get_base
(),
str
(
self
.
size
)]
'-f'
,
self
.
format
,
self
.
get_path
()]
# Call subprocess
subprocess
.
check_output
(
cmdline
)
...
...
storagedriver.py
View file @
d0eab3c8
...
...
@@ -3,36 +3,36 @@ from storagecelery import celery
@celery.task
()
def
list
_disks
(
dir
):
def
list
(
dir
):
return
[
d
.
get_desc
()
for
d
in
Disk
.
list
(
dir
)]
@celery.task
()
def
create
_disk
(
disk_desc
):
def
create
(
disk_desc
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
create
()
@celery.task
()
def
delete
_disk
(
json_data
):
disk
=
Disk
.
import_from_json
(
json_data
)
def
delete
(
json_data
):
disk
=
Disk
.
deserialize
(
json_data
)
disk
.
delete
()
@celery.task
()
def
snapshot
(
json_data
):
disk
=
Disk
.
import_from_json
(
json_data
)
disk
=
Disk
.
deserialize
(
json_data
)
disk
.
snapshot
()
@celery.task
()
def
merge
(
old_json
,
new_json
):
disk
=
Disk
.
import_from_json
(
old_json
)
new_disk
=
Disk
.
import_from_json
(
new_json
)
disk
=
Disk
.
deserialize
(
old_json
)
new_disk
=
Disk
.
deserialize
(
new_json
)
disk
.
merge
(
new_disk
)
@celery.task
()
def
get
_disk
(
json_data
):
def
get
(
json_data
):
disk
=
Disk
.
get
(
dir
=
json_data
[
'dir'
],
name
=
json_data
[
'name'
])
return
disk
.
get_desc
()
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