Commit 43f6f38a by Dudás Ádám

storage: refactor get_exclusive method

parent 38633b61
...@@ -89,16 +89,20 @@ class Disk(TimeStampedModel): ...@@ -89,16 +89,20 @@ class Disk(TimeStampedModel):
def get_exclusive(self): def get_exclusive(self):
"""Get an instance of the disk for exclusive usage. """Get an instance of the disk for exclusive usage.
"""
if self.type in ['qcow2-snap', 'raw-rw']:
raise self.WrongDiskTypeError(self.type)
filename = self.filename if self.type == 'iso' else str(uuid.uuid4()) This method manipulates the database only.
new_type = { """
type_mapping = {
'qcow2-norm': 'qcow2-snap', 'qcow2-norm': 'qcow2-snap',
'iso': 'iso', 'iso': 'iso',
'raw-ro': 'raw-rw', 'raw-ro': 'raw-rw',
}[self.type] }
if self.type not in type_mapping.keys():
raise self.WrongDiskTypeError(self.type)
filename = self.filename if self.type == 'iso' else str(uuid.uuid4())
new_type = type_mapping[self.type]
return Disk.objects.create(base=self, datastore=self.datastore, return Disk.objects.create(base=self, datastore=self.datastore,
filename=filename, name=self.name, filename=filename, name=self.name,
......
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