refactor: ZFS.scrub
This commit is contained in:
+18
-6
@@ -277,16 +277,28 @@ class ZFS:
|
|||||||
stdin=stream.stdout,
|
stdin=stream.stdout,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def scrub(pool: Pool, *, wait_for_finish: bool = True) -> None:
|
def scrub(cls, pool: Pool, *, wait_for_finish: bool = True) -> None:
|
||||||
if not isinstance(pool, Pool):
|
if not isinstance(pool, Pool):
|
||||||
raise TypeError("Can only scrub pools.")
|
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])
|
run_command([config.ZPOOL, "scrub", pool.name])
|
||||||
if wait_for_finish:
|
if wait_for_finish:
|
||||||
# TODO make Ctrl-c interrupt this
|
|
||||||
run_command([config.ZPOOL, "wait", "-t", "scrub", pool.name])
|
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:
|
class Disk:
|
||||||
|
|||||||
Reference in New Issue
Block a user