bundles/backup-server: support raid0-ing multiple raidz
This commit is contained in:
parent
59596c08ae
commit
18b8c963ab
1 changed files with 45 additions and 18 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
from bundlewrap.exceptions import BundleError
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'backup-server': {
|
'backup-server': {
|
||||||
'my_ssh_port': 22,
|
'my_ssh_port': 22,
|
||||||
|
@ -69,25 +71,51 @@ def zfs_pool(metadata):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
crypt_devices = {}
|
crypt_devices = {}
|
||||||
pool_devices = set()
|
|
||||||
unlock_actions = set()
|
unlock_actions = set()
|
||||||
|
|
||||||
for number, (device, passphrase) in enumerate(sorted(metadata.get('backup-server/encrypted-devices', {}).items())):
|
devices = metadata.get('backup-server/encrypted-devices')
|
||||||
crypt_devices[device] = {
|
|
||||||
'dm-name': f'backup{number}',
|
|
||||||
'passphrase': passphrase,
|
|
||||||
}
|
|
||||||
pool_devices.add(f'/dev/mapper/backup{number}')
|
|
||||||
unlock_actions.add(f'action:dm-crypt_open_backup{number}')
|
|
||||||
|
|
||||||
pool_opts = {
|
# TODO remove this once we have migrated all systems
|
||||||
'devices': pool_devices,
|
if isinstance(devices, dict):
|
||||||
}
|
pool_devices = set()
|
||||||
|
|
||||||
if len(pool_devices) > 2:
|
for number, (device, passphrase) in enumerate(sorted(devices.items())):
|
||||||
pool_opts['type'] = 'raidz'
|
crypt_devices[device] = {
|
||||||
elif len(pool_devices) > 1:
|
'dm-name': f'backup{number}',
|
||||||
pool_opts['type'] = 'mirror'
|
'passphrase': passphrase,
|
||||||
|
}
|
||||||
|
pool_devices.add(f'/dev/mapper/backup{number}')
|
||||||
|
unlock_actions.add(f'action:dm-crypt_open_backup{number}')
|
||||||
|
|
||||||
|
pool_config = [{
|
||||||
|
'devices': pool_devices,
|
||||||
|
}]
|
||||||
|
|
||||||
|
if len(pool_devices) > 2:
|
||||||
|
pool_config[0]['type'] = 'raidz'
|
||||||
|
elif len(pool_devices) > 1:
|
||||||
|
pool_config[0]['type'] = 'mirror'
|
||||||
|
|
||||||
|
elif isinstance(devices, list):
|
||||||
|
pool_config = []
|
||||||
|
|
||||||
|
for idx, intended_pool in enumerate(devices):
|
||||||
|
pool_devices = set()
|
||||||
|
|
||||||
|
for number, (device, passphrase) in enumerate(sorted(intended_pool.items())):
|
||||||
|
crypt_devices[device] = {
|
||||||
|
'dm-name': f'backup{idx}-{number}',
|
||||||
|
'passphrase': passphrase,
|
||||||
|
}
|
||||||
|
pool_devices.add(f'/dev/mapper/backup{idx}-{number}')
|
||||||
|
unlock_actions.add(f'action:dm-crypt_open_backup{idx}-{number}')
|
||||||
|
|
||||||
|
pool_config.append({
|
||||||
|
'devices': pool_devices,
|
||||||
|
'type': 'raidz',
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
raise BundleError(f'{node.name}: unsupported configuration for backup-server/encrypted-devices')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'backup-server': {
|
'backup-server': {
|
||||||
|
@ -100,9 +128,8 @@ def zfs_pool(metadata):
|
||||||
'pools': {
|
'pools': {
|
||||||
'backups': {
|
'backups': {
|
||||||
'when_creating': {
|
'when_creating': {
|
||||||
'config': [
|
'config': pool_config,
|
||||||
pool_opts,
|
**metadata.get('backup-server/zpool_create_options', {}),
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'needs': unlock_actions,
|
'needs': unlock_actions,
|
||||||
# That's a bit hacky. We do it this way to auto-import
|
# That's a bit hacky. We do it this way to auto-import
|
||||||
|
|
Loading…
Add table
Reference in a new issue