Coverage for mlos_bench/mlos_bench/services/types/vm_provisioner_type.py: 59%
17 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 01:50 +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, 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 # pylint: disable=unnecessary-ellipsis
19 def vm_provision(self, params: dict) -> tuple["Status", dict]:
20 """
21 Check if VM is ready. Deploy a new VM, if necessary.
23 Parameters
24 ----------
25 params : dict
26 Flat dictionary of (key, value) pairs of tunable parameters.
27 VMEnv tunables are variable parameters that, together with the
28 VMEnv configuration, are sufficient to provision a VM.
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 """
36 ...
38 def wait_vm_deployment(self, is_setup: bool, params: dict) -> tuple["Status", dict]:
39 """
40 Waits for a pending operation on an Azure VM to resolve to SUCCEEDED or FAILED.
41 Return TIMED_OUT when timing out.
43 Parameters
44 ----------
45 is_setup : bool
46 If True, wait for VM being deployed; otherwise, wait for successful deprovisioning.
47 params : dict
48 Flat dictionary of (key, value) pairs of tunable parameters.
50 Returns
51 -------
52 result : (Status, dict)
53 A pair of Status and result.
54 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
55 Result is info on the operation runtime if SUCCEEDED, otherwise {}.
56 """
57 ...
59 def vm_start(self, params: dict) -> tuple["Status", dict]:
60 """
61 Start a VM.
63 Parameters
64 ----------
65 params : dict
66 Flat dictionary of (key, value) pairs of tunable parameters.
68 Returns
69 -------
70 result : (Status, dict)
71 A pair of Status and result. The result is always {}.
72 Status is one of {PENDING, SUCCEEDED, FAILED}
73 """
74 ...
76 def vm_stop(self, params: dict) -> tuple["Status", dict]:
77 """
78 Stops the VM by initiating a graceful shutdown.
80 Parameters
81 ----------
82 params : dict
83 Flat dictionary of (key, value) pairs of tunable parameters.
85 Returns
86 -------
87 result : (Status, dict)
88 A pair of Status and result. The result is always {}.
89 Status is one of {PENDING, SUCCEEDED, FAILED}
90 """
91 ...
93 def vm_restart(self, params: dict) -> tuple["Status", dict]:
94 """
95 Restarts the VM by initiating a graceful shutdown.
97 Parameters
98 ----------
99 params : dict
100 Flat dictionary of (key, value) pairs of tunable parameters.
102 Returns
103 -------
104 result : (Status, dict)
105 A pair of Status and result. The result is always {}.
106 Status is one of {PENDING, SUCCEEDED, FAILED}
107 """
108 ...
110 def vm_deprovision(self, params: dict) -> tuple["Status", dict]:
111 """
112 Deallocates the VM by shutting it down then releasing the compute resources.
114 Parameters
115 ----------
116 params : dict
117 Flat dictionary of (key, value) pairs of tunable parameters.
119 Returns
120 -------
121 result : (Status, dict)
122 A pair of Status and result. The result is always {}.
123 Status is one of {PENDING, SUCCEEDED, FAILED}
124 """
125 ...
127 def wait_vm_operation(self, params: dict) -> tuple["Status", dict]:
128 """
129 Waits for a pending operation on a VM to resolve to SUCCEEDED or FAILED. Return
130 TIMED_OUT when timing out.
132 Parameters
133 ----------
134 params: dict
135 Flat dictionary of (key, value) pairs of tunable parameters.
136 Must have the "asyncResultsUrl" key to get the results.
137 If the key is not present, return Status.PENDING.
139 Returns
140 -------
141 result : (Status, dict)
142 A pair of Status and result.
143 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
144 Result is info on the operation runtime if SUCCEEDED, otherwise {}.
145 """
146 ...