Commit ca4ffe04 by Guba Sándor

fixing TYPES

parent abda6f85
...@@ -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()):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment