Skip to content
Snippets Groups Projects
Commit 333ff548 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Further development

Make the cow file sparse
Add method in Device to list the partitions
Add a "is bootable" flag in Device constructor
parent d57775d4
No related branches found
Tags 0.7.2
No related merge requests found
......@@ -51,7 +51,8 @@ class Disk(object):
size = blockdev('--getsize', sourcedev)
cowfd, cow = tempfile.mkstemp()
self._add_cleanup(os.unlink, cow)
dd('if=/dev/zero', 'of=%s' % cow, 'count=%d' % (1024*1024))#(int(size)/4))
# Create 1G cow file
dd('if=/dev/null', 'of=%s' % cow, 'bs=1k' ,'seek=%d' % (1024*1024))
cowdev = self._losetup(cow)
snapshot = uuid.uuid4().hex
......@@ -70,19 +71,27 @@ class Disk(object):
class DiskDevice(object):
def __init__(self, disk, device):
def __init__(self, disk, device, bootable = True):
self.disk = disk
self.dev = device
self.device = device
self.is_bootable = bootable
self.partitions_mapped = False
self.magic_number = uuid.uuid4().hex
def list_partitions(self):
if not self.partitions_mapped:
kpartx("-a", "-p", self.magic_number, self.dev)
self.disk._cleanup_jobs.append(kpartx, "-d", "-p",
self.magic_number, self.dev)
self.partitions_mapped = True
output = kpartx("-l", "-p", self.magic_number, self.dev)
return [ "/dev/mapper/%s" % x for x in
re.findall('^\S+', str(output), flags=re.MULTILINE)]
def mount(self, partition):
if not self.partitions_mapped:
self.list_partitions()
kpartx("-a", "-p", self.magic_number, self.dev)
self.disk._cleanup_jobs.append(kpartx, "-d", "-p",
self.magic_number, self.dev)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment