mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Introduce format_command. Fixes #7
This commit is contained in:
parent
47b12ac807
commit
6e145f6aca
10 changed files with 41 additions and 20 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -36,11 +36,12 @@ class AbstractPartition(FSMProxy):
|
|||
log_check_call(['/bin/umount', self.mount_dir])
|
||||
del self.mount_dir
|
||||
|
||||
def __init__(self, size, filesystem):
|
||||
self.size = size
|
||||
self.filesystem = filesystem
|
||||
self.device_path = None
|
||||
self.mounts = {}
|
||||
def __init__(self, size, filesystem, format_command):
|
||||
self.size = size
|
||||
self.filesystem = filesystem
|
||||
self.format_command = format_command
|
||||
self.device_path = None
|
||||
self.mounts = {}
|
||||
|
||||
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
|
||||
super(AbstractPartition, self).__init__(cfg)
|
||||
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue