diff options
Diffstat (limited to 'roles/storage/zfs/syncoid/templates/autosuspend.py.j2')
-rw-r--r-- | roles/storage/zfs/syncoid/templates/autosuspend.py.j2 | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 index 9dc9bc52..39fe0092 100644 --- a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 +++ b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 @@ -109,7 +109,8 @@ class AutoSuspender(object): return result - def suspend(self): + def suspend_system(self): + print("trying to suspend system") manager = self._get_logind_manager_interface() if not manager.CanSuspend(): print("ERR: system can not be suspended") @@ -119,8 +120,31 @@ class AutoSuspender(object): except dbus.exceptions.DBusException as error: print("ERR: %s" % error) + def _reformat_hdparm_output(self, lines): + result = [] + entry = "" + for line in lines: + line = line.decode('utf-8') + if line == '': + if entry != '': + result.append(entry) + entry = "" + continue + if line.strip().startswith("drive state is:"): + line = ' ' + line.split(':', 2)[1].strip() + entry += line + result.append(entry) + return result + def spindown_disks(self, disks): - subprocess.run(["hdparm", "-y"] + disks) + print("current disk power states:") + lines = subprocess.run(["hdparm", "-C"] + disks, check=True, stdout=subprocess.PIPE).stdout.splitlines() + for line in self._reformat_hdparm_output(lines): + print(" %s" % line) + print("issuing standby commands:") + lines = subprocess.run(["hdparm", "-y"] + disks, check=True, stdout=subprocess.PIPE).stdout.splitlines() + for line in self._reformat_hdparm_output(lines): + print(" %s" % line) def print_usage(): @@ -147,10 +171,8 @@ if __name__ == "__main__": print("checking for suspend inhibitors:") if s.check(): if mode == "system": - print("trying to suspend system") - s.suspend() + s.suspend_system() elif mode == "disks": - print("trying to spindown disks") s.spindown_disks(disks) else: print("not suspending because at least one check failed.") |