refactor: ZFS.scrub
This commit is contained in:
+17
-5
@@ -277,16 +277,28 @@ class ZFS:
|
||||
stdin=stream.stdout,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def scrub(pool: Pool, *, wait_for_finish: bool = True) -> None:
|
||||
@classmethod
|
||||
def scrub(cls, pool: Pool, *, wait_for_finish: bool = True) -> None:
|
||||
if not isinstance(pool, Pool):
|
||||
raise TypeError("Can only scrub pools.")
|
||||
# TODO: check if scrub already in progress
|
||||
if not cls._scrub_in_progress(pool):
|
||||
run_command([config.ZPOOL, "scrub", pool.name])
|
||||
if wait_for_finish:
|
||||
# TODO make Ctrl-c interrupt this
|
||||
run_command([config.ZPOOL, "wait", "-t", "scrub", pool.name])
|
||||
# TODO raise error if pool is not healthy
|
||||
if not cls._healthy(pool):
|
||||
raise IOError(f"Pool {pool.name} is not healthy.")
|
||||
|
||||
@classmethod
|
||||
def _scrub_in_progress(cls, pool: Pool) -> bool:
|
||||
return "scrub in progress" in cls._pool_status_output(pool)
|
||||
|
||||
@classmethod
|
||||
def _healthy(cls, pool: Pool) -> bool:
|
||||
return "ONLINE" in cls._pool_status_output(pool)
|
||||
|
||||
@staticmethod
|
||||
def _pool_status_output(pool):
|
||||
return get_output_of_command([config.ZFS, "status", pool.name])
|
||||
|
||||
|
||||
class Disk:
|
||||
|
||||
Reference in New Issue
Block a user