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
ca4ffe04
authored
Sep 26, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing TYPES
parent
abda6f85
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
14 deletions
+4
-14
disk.py
+4
-14
No files found.
disk.py
View file @
ca4ffe04
...
@@ -15,9 +15,7 @@ class Disk(object):
...
@@ -15,9 +15,7 @@ class Disk(object):
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
CREATE_TYPES
=
[(
'qcow2-norm'
,
'qcow2'
),
(
'raw-ro'
,
'raw'
),
CREATE_TYPES
=
[
'qcow2'
,
'raw'
]
(
'raw-rw'
,
'raw'
)]
SNAPSHOT_TYPES
=
[(
'qcow2-snap'
,
'qcow2'
)]
def
__init__
(
self
,
dir
,
name
,
format
,
size
,
base_name
):
def
__init__
(
self
,
dir
,
name
,
format
,
size
,
base_name
):
# TODO: tests
# TODO: tests
...
@@ -42,12 +40,6 @@ class Disk(object):
...
@@ -42,12 +40,6 @@ class Disk(object):
'base_name'
:
self
.
base_name
,
'base_name'
:
self
.
base_name
,
}
}
def
match_types
(
self
,
tupple_list
):
for
k
in
tupple_list
:
if
k
[
0
]
==
self
.
type
[
0
]:
return
k
[
1
]
raise
Exception
(
"Could not match qemu format
%
s"
%
self
.
format
[
0
])
def
get_path
(
self
):
def
get_path
(
self
):
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
...
@@ -86,17 +78,15 @@ class Disk(object):
...
@@ -86,17 +78,15 @@ class Disk(object):
self.format van be "qcow2-normal"
self.format van be "qcow2-normal"
'''
'''
# Check if type is avaliable to create
# Check if type is avaliable to create
if
self
.
format
[
0
]
not
in
[
k
[
0
]
for
k
in
self
.
CREATE_TYPES
]
:
if
self
.
format
not
in
self
.
CREATE_TYPES
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
# Check for file if already exist
# Check for file if already exist
if
os
.
path
.
isfile
(
self
.
get_path
()):
if
os
.
path
.
isfile
(
self
.
get_path
()):
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
# Match model type to qemu type
qemu_format
=
self
.
match_types
(
self
.
CREATE_TYPES
)
# Build list of Strings as command parameters
# Build list of Strings as command parameters
cmdline
=
[
'qemu-img'
,
cmdline
=
[
'qemu-img'
,
'create'
,
'create'
,
'-f'
,
qemu_
format
,
'-f'
,
self
.
format
,
str
(
self
.
size
)]
str
(
self
.
size
)]
# Call subprocess
# Call subprocess
subprocess
.
check_output
(
cmdline
)
subprocess
.
check_output
(
cmdline
)
...
@@ -105,7 +95,7 @@ class Disk(object):
...
@@ -105,7 +95,7 @@ class Disk(object):
''' Creating qcow2 snapshot with base image.
''' Creating qcow2 snapshot with base image.
'''
'''
# Check if snapshot type match
# Check if snapshot type match
if
self
.
format
[
0
]
not
in
[
k
[
0
]
for
k
in
self
.
SNAPSHOT_TYPES
]
:
if
self
.
format
!=
'qcow2'
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
# Check if file already exists
# Check if file already exists
if
os
.
path
.
isfile
(
self
.
get_path
()):
if
os
.
path
.
isfile
(
self
.
get_path
()):
...
...
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