Coverage for mlos_bench/mlos_bench/services/types/vm_provisioner_type.py: 100%
10 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 VM provisioning 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 SupportsVMOps(Protocol):
15 """Protocol interface for VM provisioning operations."""
17 def vm_provision(self, params: dict) -> Tuple["Status", dict]:
18 """
19 Check if VM is ready. Deploy a new VM, if necessary.
21 Parameters
22 ----------
23 params : dict
24 Flat dictionary of (key, value) pairs of tunable parameters.
25 VMEnv tunables are variable parameters that, together with the
26 VMEnv configuration, are sufficient to provision a VM.
28 Returns
29 -------
30 result : (Status, dict)
31 A pair of Status and result. The result is always {}.
32 Status is one of {PENDING, SUCCEEDED, FAILED}
33 """
35 def wait_vm_deployment(self, is_setup: bool, params: dict) -> Tuple["Status", dict]:
36 """
37 Waits for a pending operation on an Azure VM to resolve to SUCCEEDED or FAILED.
38 Return TIMED_OUT when timing out.
40 Parameters
41 ----------
42 is_setup : bool
43 If True, wait for VM being deployed; otherwise, wait for successful deprovisioning.
44 params : dict
45 Flat dictionary of (key, value) pairs of tunable parameters.
47 Returns
48 -------
49 result : (Status, dict)
50 A pair of Status and result.
51 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
52 Result is info on the operation runtime if SUCCEEDED, otherwise {}.
53 """
55 def vm_start(self, params: dict) -> Tuple["Status", dict]:
56 """
57 Start a VM.
59 Parameters
60 ----------
61 params : dict
62 Flat dictionary of (key, value) pairs of tunable parameters.
64 Returns
65 -------
66 result : (Status, dict)
67 A pair of Status and result. The result is always {}.
68 Status is one of {PENDING, SUCCEEDED, FAILED}
69 """
71 def vm_stop(self, params: dict) -> Tuple["Status", dict]:
72 """
73 Stops the VM by initiating a graceful shutdown.
75 Parameters
76 ----------
77 params : dict
78 Flat dictionary of (key, value) pairs of tunable parameters.
80 Returns
81 -------
82 result : (Status, dict)
83 A pair of Status and result. The result is always {}.
84 Status is one of {PENDING, SUCCEEDED, FAILED}
85 """
87 def vm_restart(self, params: dict) -> Tuple["Status", dict]:
88 """
89 Restarts the VM by initiating a graceful shutdown.
91 Parameters
92 ----------
93 params : dict
94 Flat dictionary of (key, value) pairs of tunable parameters.
96 Returns
97 -------
98 result : (Status, dict)
99 A pair of Status and result. The result is always {}.
100 Status is one of {PENDING, SUCCEEDED, FAILED}
101 """
103 def vm_deprovision(self, params: dict) -> Tuple["Status", dict]:
104 """
105 Deallocates the VM by shutting it down then releasing the compute resources.
107 Parameters
108 ----------
109 params : dict
110 Flat dictionary of (key, value) pairs of tunable parameters.
112 Returns
113 -------
114 result : (Status, dict)
115 A pair of Status and result. The result is always {}.
116 Status is one of {PENDING, SUCCEEDED, FAILED}
117 """
119 def wait_vm_operation(self, params: dict) -> Tuple["Status", dict]:
120 """
121 Waits for a pending operation on a VM to resolve to SUCCEEDED or FAILED. Return
122 TIMED_OUT when timing out.
124 Parameters
125 ----------
126 params: dict
127 Flat dictionary of (key, value) pairs of tunable parameters.
128 Must have the "asyncResultsUrl" key to get the results.
129 If the key is not present, return Status.PENDING.
131 Returns
132 -------
133 result : (Status, dict)
134 A pair of Status and result.
135 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
136 Result is info on the operation runtime if SUCCEEDED, otherwise {}.
137 """