Coverage for harbor_cli/commands/api/system.py: 55%
29 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
1from __future__ import annotations
3import time
5import typer
7from ...output.render import render_result
8from ...state import state
10# Create a command group
11app = typer.Typer(
12 name="system",
13 help="System information",
14 no_args_is_help=True,
15)
18@app.command("info")
19def info(ctx: typer.Context) -> None:
20 """Get information about the system."""
21 system_info = state.run(state.client.get_system_info(), "Fetching system info...")
22 render_result(system_info, ctx)
25@app.command("volumes")
26def volumeinfo(ctx: typer.Context) -> None:
27 """Get information about the system volumes."""
28 volume_info = state.run(
29 state.client.get_system_volume_info(), "Fetching system volume info..."
30 )
31 render_result(volume_info, ctx)
34@app.command("health")
35def health(ctx: typer.Context) -> None:
36 """Get system health.
38 NOTE: this is under the /health endpoint, not /system/health
39 but it is still a system health check, hence why it is here,
40 and not in its own health.py file.
41 """
42 health_status = state.run(state.client.health_check(), "Fetching health info...")
43 render_result(health_status, ctx)
46@app.command("ping")
47def ping(ctx: typer.Context) -> None:
48 """Ping the harbor server. Returns the time it took to ping the server in milliseconds."""
49 # Use perf_counter with nanosecond resolution to get the most accurate time
50 start = time.perf_counter_ns()
51 state.run(state.client.ping(), "Pinging server...")
52 end = time.perf_counter_ns()
53 duration_ms = (end - start) / 1000000
54 render_result(duration_ms, ctx)
57@app.command("statistics")
58def statistics(ctx: typer.Context) -> None:
59 """Get statistics about the system."""
60 statistics = state.run(state.client.get_statistics(), "Fetching statistics...")
61 render_result(statistics, ctx)