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)
|
self.partitions.append(self.grub_boot)
|
||||||
|
|
||||||
if 'boot' in data:
|
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())
|
'boot', last_partition())
|
||||||
self.partitions.append(self.boot)
|
self.partitions.append(self.boot)
|
||||||
if 'swap' in data:
|
if 'swap' in data:
|
||||||
self.swap = GPTSwapPartition(Bytes(data['swap']['size']), last_partition())
|
self.swap = GPTSwapPartition(Bytes(data['swap']['size']), last_partition())
|
||||||
self.partitions.append(self.swap)
|
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())
|
'root', last_partition())
|
||||||
self.partitions.append(self.root)
|
self.partitions.append(self.root)
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,16 @@ class MSDOSPartitionMap(AbstractPartitionMap):
|
||||||
return self.partitions[-1] if len(self.partitions) > 0 else None
|
return self.partitions[-1] if len(self.partitions) > 0 else None
|
||||||
|
|
||||||
if 'boot' in data:
|
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)
|
self.partitions.append(self.boot)
|
||||||
if 'swap' in data:
|
if 'swap' in data:
|
||||||
self.swap = MSDOSSwapPartition(Bytes(data['swap']['size']), last_partition())
|
self.swap = MSDOSSwapPartition(Bytes(data['swap']['size']), last_partition())
|
||||||
self.partitions.append(self.swap)
|
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)
|
self.partitions.append(self.root)
|
||||||
|
|
||||||
getattr(self, 'boot', self.root).flags.append('boot')
|
getattr(self, 'boot', self.root).flags.append('boot')
|
||||||
|
|
|
@ -5,7 +5,8 @@ class NoPartitions(object):
|
||||||
|
|
||||||
def __init__(self, data, bootloader):
|
def __init__(self, data, bootloader):
|
||||||
from common.bytes import Bytes
|
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]
|
self.partitions = [self.root]
|
||||||
|
|
||||||
def is_blocking(self):
|
def is_blocking(self):
|
||||||
|
|
|
@ -36,11 +36,12 @@ class AbstractPartition(FSMProxy):
|
||||||
log_check_call(['/bin/umount', self.mount_dir])
|
log_check_call(['/bin/umount', self.mount_dir])
|
||||||
del self.mount_dir
|
del self.mount_dir
|
||||||
|
|
||||||
def __init__(self, size, filesystem):
|
def __init__(self, size, filesystem, format_command):
|
||||||
self.size = size
|
self.size = size
|
||||||
self.filesystem = filesystem
|
self.filesystem = filesystem
|
||||||
self.device_path = None
|
self.format_command = format_command
|
||||||
self.mounts = {}
|
self.device_path = None
|
||||||
|
self.mounts = {}
|
||||||
|
|
||||||
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
|
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
|
||||||
super(AbstractPartition, self).__init__(cfg)
|
super(AbstractPartition, self).__init__(cfg)
|
||||||
|
@ -57,8 +58,16 @@ class AbstractPartition(FSMProxy):
|
||||||
return self.get_start() + self.size
|
return self.get_start() + self.size
|
||||||
|
|
||||||
def _before_format(self, e):
|
def _before_format(self, e):
|
||||||
mkfs = '/sbin/mkfs.{fs}'.format(fs=self.filesystem)
|
if self.format_command is None:
|
||||||
log_check_call([mkfs, self.device_path])
|
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):
|
def _before_mount(self, e):
|
||||||
log_check_call(['/bin/mount', '--types', self.filesystem, self.device_path, e.destination])
|
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'},
|
{'name': 'unmap', 'src': 'mapped', 'dst': 'unmapped'},
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, size, filesystem, previous):
|
def __init__(self, size, filesystem, format_command, previous):
|
||||||
self.previous = previous
|
self.previous = previous
|
||||||
from common.bytes import Bytes
|
from common.bytes import Bytes
|
||||||
self.offset = Bytes(0)
|
self.offset = Bytes(0)
|
||||||
self.flags = []
|
self.flags = []
|
||||||
super(BasePartition, self).__init__(size, filesystem)
|
super(BasePartition, self).__init__(size, filesystem, format_command)
|
||||||
|
|
||||||
def create(self, volume):
|
def create(self, volume):
|
||||||
self.fsm.create(volume=volume)
|
self.fsm.create(volume=volume)
|
||||||
|
|
|
@ -4,9 +4,9 @@ from base import BasePartition
|
||||||
|
|
||||||
class GPTPartition(BasePartition):
|
class GPTPartition(BasePartition):
|
||||||
|
|
||||||
def __init__(self, size, filesystem, name, previous):
|
def __init__(self, size, filesystem, format_command, name, previous):
|
||||||
self.name = name
|
self.name = name
|
||||||
super(GPTPartition, self).__init__(size, filesystem, previous)
|
super(GPTPartition, self).__init__(size, filesystem, format_command, previous)
|
||||||
|
|
||||||
def _before_create(self, e):
|
def _before_create(self, e):
|
||||||
super(GPTPartition, self)._before_create(e)
|
super(GPTPartition, self)._before_create(e)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from gpt import GPTPartition
|
||||||
class GPTSwapPartition(GPTPartition):
|
class GPTSwapPartition(GPTPartition):
|
||||||
|
|
||||||
def __init__(self, size, previous):
|
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):
|
def _before_format(self, e):
|
||||||
log_check_call(['/sbin/mkswap', self.device_path])
|
log_check_call(['/sbin/mkswap', self.device_path])
|
||||||
|
|
|
@ -5,7 +5,7 @@ from msdos import MSDOSPartition
|
||||||
class MSDOSSwapPartition(MSDOSPartition):
|
class MSDOSSwapPartition(MSDOSPartition):
|
||||||
|
|
||||||
def __init__(self, size, previous):
|
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):
|
def _before_format(self, e):
|
||||||
log_check_call(['/sbin/mkswap', self.device_path])
|
log_check_call(['/sbin/mkswap', self.device_path])
|
||||||
|
|
|
@ -9,4 +9,4 @@ class UnformattedPartition(BasePartition):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, size, previous):
|
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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"size": { "$ref": "#/definitions/bytes" },
|
"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"]
|
"required": ["size", "filesystem"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue