diff --git a/bundles/hdparm/items.py b/bundles/hdparm/items.py new file mode 100644 index 0000000..c6c4d16 --- /dev/null +++ b/bundles/hdparm/items.py @@ -0,0 +1,18 @@ +previous_action = [] + +for device, options in node.metadata.get('hdparm').items(): + for option, value in options.items(): + if option == 'power_management': + name = f'hdparm_{option}_{device}' + actions[name] = { + 'command': f'hdparm -B {value} "{device}"', + 'unless': f'hdparm -B "{device}" | grep APM_level | cut -d= -f2 | xargs | grep -q "^{value}$"', + 'needs': [ + 'pkg_apt:hdparm', + *previous_action, + ], + } + else: + raise ValueError(f'unsupported hdparm option: {option}') + + previous_action = [f'action:{name}'] diff --git a/bundles/hdparm/metadata.py b/bundles/hdparm/metadata.py new file mode 100644 index 0000000..313cec5 --- /dev/null +++ b/bundles/hdparm/metadata.py @@ -0,0 +1,8 @@ +defaults = { + 'apt': { + 'packages': { + 'hdparm': {}, + }, + }, + 'hdparm': {}, +} diff --git a/nodes/home.backups.py b/nodes/home.backups.py index f442698..cf01408 100644 --- a/nodes/home.backups.py +++ b/nodes/home.backups.py @@ -8,6 +8,7 @@ 'bundles': [ 'zfs', 'zfs-mirror', + 'hdparm', ], 'metadata': { 'id': '9cf52515-63a1-4659-a8ec-6c3c881727e5', @@ -21,6 +22,17 @@ 'backup-server': { 'hostname': 'backups.sublimity.de', }, + 'hdparm': { + '/dev/disk/by-id/ata-HGST_HDN726040ALE614_K3GV6TPL': { + 'power_management': 1, + }, + '/dev/disk/by-id/ata-HGST_HDN726040ALE614_K4KAJXEB': { + 'power_management': 1, + }, + '/dev/disk/by-id/ata-TOSHIBA_HDWQ140_19VZK0EMFAYG': { + 'power_management': 1, + }, + }, 'zfs-mirror': { 'server': 'wb.offsite-backups', },