Coverage for mlos_bench/mlos_bench/services/types/host_ops_type.py: 100%
7 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Protocol interface for Host/VM boot operations."""
7from typing import TYPE_CHECKING, Protocol, Tuple, runtime_checkable
9if TYPE_CHECKING:
10 from mlos_bench.environments.status import Status
13@runtime_checkable
14class SupportsHostOps(Protocol):
15 """Protocol interface for Host/VM boot operations."""
17 def start_host(self, params: dict) -> Tuple["Status", dict]:
18 """
19 Start a Host/VM.
21 Parameters
22 ----------
23 params : dict
24 Flat dictionary of (key, value) pairs of tunable parameters.
26 Returns
27 -------
28 result : (Status, dict)
29 A pair of Status and result. The result is always {}.
30 Status is one of {PENDING, SUCCEEDED, FAILED}
31 """
33 def stop_host(self, params: dict, force: bool = False) -> Tuple["Status", dict]:
34 """
35 Stops the Host/VM by initiating a (graceful) shutdown.
37 Parameters
38 ----------
39 params : dict
40 Flat dictionary of (key, value) pairs of tunable parameters.
41 force : bool
42 If True, force stop the Host/VM.
44 Returns
45 -------
46 result : (Status, dict)
47 A pair of Status and result. The result is always {}.
48 Status is one of {PENDING, SUCCEEDED, FAILED}
49 """
51 def restart_host(self, params: dict, force: bool = False) -> Tuple["Status", dict]:
52 """
53 Restarts the host by initiating a (graceful) shutdown.
55 Parameters
56 ----------
57 params : dict
58 Flat dictionary of (key, value) pairs of tunable parameters.
59 force : bool
60 If True, force restart the Host/VM.
62 Returns
63 -------
64 result : (Status, dict)
65 A pair of Status and result. The result is always {}.
66 Status is one of {PENDING, SUCCEEDED, FAILED}
67 """
69 def wait_host_operation(self, params: dict) -> Tuple["Status", dict]:
70 """
71 Waits for a pending operation on a Host/VM to resolve to SUCCEEDED or FAILED.
72 Return TIMED_OUT when timing out.
74 Parameters
75 ----------
76 params: dict
77 Flat dictionary of (key, value) pairs of tunable parameters.
78 Must have the "asyncResultsUrl" key to get the results.
79 If the key is not present, return Status.PENDING.
81 Returns
82 -------
83 result : (Status, dict)
84 A pair of Status and result.
85 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
86 Result is info on the operation runtime if SUCCEEDED, otherwise {}.
87 """