Disable Linux swap and return list of devices
()
| 73 | |
| 74 | |
| 75 | def disable_swap_linux(): |
| 76 | """Disable Linux swap and return list of devices""" |
| 77 | if 0 == count_swap_linux(): |
| 78 | return |
| 79 | logger.debug(_("Disabling swap.")) |
| 80 | args = ["swapoff", "-a", "-v"] |
| 81 | (rc, stdout, stderr) = General.run_external(args) |
| 82 | if 0 != rc: |
| 83 | raise RuntimeError(stderr.replace("\n", "")) |
| 84 | devices = [] |
| 85 | for line in stdout.split('\n'): |
| 86 | line = line.replace('\n', '') |
| 87 | if '' == line: |
| 88 | continue |
| 89 | ret = parse_swapoff(line) |
| 90 | if ret is None: |
| 91 | raise RuntimeError(f"Unexpected output:\nargs='{args}'\n" |
| 92 | f"stdout='{stdout}'\nstderr='{stderr}'") |
| 93 | devices.append(ret) |
| 94 | return devices |
| 95 | |
| 96 | |
| 97 | def enable_swap_linux(): |