Merge FilePool._resize_loop_device() with resize()

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-06-21 12:48:57 +02:00
parent 72df863bb9
commit 803efa76ff
No known key found for this signature in database
GPG Key ID: 96ED3C3BA19C3DEE

View File

@ -107,7 +107,18 @@ class FilePool(Pool):
with open(path, 'a+b') as fd:
fd.truncate(size)
self._resize_loop_device(path)
p = subprocess.Popen(
['sudo', 'losetup', '--associated', path],
stdout=subprocess.PIPE)
result = p.communicate()
m = re.match(r'^(/dev/loop\d+):\s', result[0])
if m is not None:
loop_dev = m.group(1)
# resize loop device
subprocess.check_call(['sudo', 'losetup', '--set-capacity', loop_dev
])
def remove(self, volume):
if volume.volume_type in ['read-write', 'volatile']:
@ -128,23 +139,6 @@ class FilePool(Pool):
return volume
@staticmethod
def _resize_loop_device(path):
''' Sets the loop device capacity '''
# find loop device if any
p = subprocess.Popen(
['sudo', 'losetup', '--associated', path],
stdout=subprocess.PIPE)
result = p.communicate()
m = re.match(r'^(/dev/loop\d+):\s', result[0])
if m is not None:
loop_dev = m.group(1)
# resize loop device
subprocess.check_call(['sudo', 'losetup', '--set-capacity',
loop_dev])
def commit_template_changes(self, volume):
if volume.volume_type != 'origin':
return volume