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