Introduce format_command. Fixes #7

This commit is contained in:
Anders Ingemann 2014-02-23 17:52:05 +01:00
parent 47b12ac807
commit 6e145f6aca
10 changed files with 41 additions and 20 deletions

View file

@ -23,13 +23,15 @@ class GPTPartitionMap(AbstractPartitionMap):
self.partitions.append(self.grub_boot)
if 'boot' in data:
self.boot = GPTPartition(Bytes(data['boot']['size']), data['boot']['filesystem'],
self.boot = GPTPartition(Bytes(data['boot']['size']),
data['boot']['filesystem'], data['boot'].get('format_command', None),
'boot', last_partition())
self.partitions.append(self.boot)
if 'swap' in data:
self.swap = GPTSwapPartition(Bytes(data['swap']['size']), last_partition())
self.partitions.append(self.swap)
self.root = GPTPartition(Bytes(data['root']['size']), data['root']['filesystem'],
self.root = GPTPartition(Bytes(data['root']['size']),
data['root']['filesystem'], data['root'].get('format_command', None),
'root', last_partition())
self.partitions.append(self.root)

View file

@ -14,12 +14,16 @@ class MSDOSPartitionMap(AbstractPartitionMap):
return self.partitions[-1] if len(self.partitions) > 0 else None
if 'boot' in data:
self.boot = MSDOSPartition(Bytes(data['boot']['size']), data['boot']['filesystem'], None)
self.boot = MSDOSPartition(Bytes(data['boot']['size']),
data['boot']['filesystem'], data['boot'].get('format_command', None),
last_partition())
self.partitions.append(self.boot)
if 'swap' in data:
self.swap = MSDOSSwapPartition(Bytes(data['swap']['size']), last_partition())
self.partitions.append(self.swap)
self.root = MSDOSPartition(Bytes(data['root']['size']), data['root']['filesystem'], last_partition())
self.root = MSDOSPartition(Bytes(data['root']['size']),
data['root']['filesystem'], data['root'].get('format_command', None),
last_partition())
self.partitions.append(self.root)
getattr(self, 'boot', self.root).flags.append('boot')

View file

@ -5,7 +5,8 @@ class NoPartitions(object):
def __init__(self, data, bootloader):
from common.bytes import Bytes
self.root = SinglePartition(Bytes(data['root']['size']), data['root']['filesystem'])
self.root = SinglePartition(Bytes(data['root']['size']),
data['root']['filesystem'], data['root'].get('format_command', None))
self.partitions = [self.root]
def is_blocking(self):

View file

@ -36,9 +36,10 @@ class AbstractPartition(FSMProxy):
log_check_call(['/bin/umount', self.mount_dir])
del self.mount_dir
def __init__(self, size, filesystem):
def __init__(self, size, filesystem, format_command):
self.size = size
self.filesystem = filesystem
self.format_command = format_command
self.device_path = None
self.mounts = {}
@ -57,8 +58,16 @@ class AbstractPartition(FSMProxy):
return self.get_start() + self.size
def _before_format(self, e):
mkfs = '/sbin/mkfs.{fs}'.format(fs=self.filesystem)
log_check_call([mkfs, self.device_path])
if self.format_command is None:
format_command = ['/sbin/mkfs.{fs}', '{device_path}']
else:
format_command = self.format_command
variables = {'fs': self.filesystem,
'device_path': self.device_path,
'size': self.size,
}
command = map(lambda part: part.format(**variables), format_command)
log_check_call(command)
def _before_mount(self, e):
log_check_call(['/bin/mount', '--types', self.filesystem, self.device_path, e.destination])

View file

@ -14,12 +14,12 @@ class BasePartition(AbstractPartition):
{'name': 'unmap', 'src': 'mapped', 'dst': 'unmapped'},
]
def __init__(self, size, filesystem, previous):
def __init__(self, size, filesystem, format_command, previous):
self.previous = previous
from common.bytes import Bytes
self.offset = Bytes(0)
self.flags = []
super(BasePartition, self).__init__(size, filesystem)
super(BasePartition, self).__init__(size, filesystem, format_command)
def create(self, volume):
self.fsm.create(volume=volume)

View file

@ -4,9 +4,9 @@ from base import BasePartition
class GPTPartition(BasePartition):
def __init__(self, size, filesystem, name, previous):
def __init__(self, size, filesystem, format_command, name, previous):
self.name = name
super(GPTPartition, self).__init__(size, filesystem, previous)
super(GPTPartition, self).__init__(size, filesystem, format_command, previous)
def _before_create(self, e):
super(GPTPartition, self)._before_create(e)

View file

@ -5,7 +5,7 @@ from gpt import GPTPartition
class GPTSwapPartition(GPTPartition):
def __init__(self, size, previous):
super(GPTSwapPartition, self).__init__(size, 'swap', 'swap', previous)
super(GPTSwapPartition, self).__init__(size, 'swap', None, 'swap', previous)
def _before_format(self, e):
log_check_call(['/sbin/mkswap', self.device_path])

View file

@ -5,7 +5,7 @@ from msdos import MSDOSPartition
class MSDOSSwapPartition(MSDOSPartition):
def __init__(self, size, previous):
super(MSDOSSwapPartition, self).__init__(size, 'swap', previous)
super(MSDOSSwapPartition, self).__init__(size, 'swap', None, previous)
def _before_format(self, e):
log_check_call(['/sbin/mkswap', self.device_path])

View file

@ -9,4 +9,4 @@ class UnformattedPartition(BasePartition):
]
def __init__(self, size, previous):
super(UnformattedPartition, self).__init__(size, None, previous)
super(UnformattedPartition, self).__init__(size, None, None, previous)

View file

@ -141,7 +141,12 @@
"type": "object",
"properties": {
"size": { "$ref": "#/definitions/bytes" },
"filesystem": { "enum": ["ext2", "ext3", "ext4", "xfs"] }
"filesystem": { "enum": ["ext2", "ext3", "ext4", "xfs"] },
"format_command": {
"type": "array",
"items": {"type": "string"},
"minItems": 1
}
},
"required": ["size", "filesystem"]
}