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

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Protocol interface for VM provisioning operations.""" 

6 

7from typing import TYPE_CHECKING, Protocol, Tuple, runtime_checkable 

8 

9if TYPE_CHECKING: 

10 from mlos_bench.environments.status import Status 

11 

12 

13@runtime_checkable 

14class SupportsVMOps(Protocol): 

15 """Protocol interface for VM provisioning operations.""" 

16 

17 def vm_provision(self, params: dict) -> Tuple["Status", dict]: 

18 """ 

19 Check if VM is ready. Deploy a new VM, if necessary. 

20 

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. 

27 

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 """ 

34 

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. 

39 

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. 

46 

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 """ 

54 

55 def vm_start(self, params: dict) -> Tuple["Status", dict]: 

56 """ 

57 Start a VM. 

58 

59 Parameters 

60 ---------- 

61 params : dict 

62 Flat dictionary of (key, value) pairs of tunable parameters. 

63 

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 """ 

70 

71 def vm_stop(self, params: dict) -> Tuple["Status", dict]: 

72 """ 

73 Stops the VM by initiating a graceful shutdown. 

74 

75 Parameters 

76 ---------- 

77 params : dict 

78 Flat dictionary of (key, value) pairs of tunable parameters. 

79 

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 """ 

86 

87 def vm_restart(self, params: dict) -> Tuple["Status", dict]: 

88 """ 

89 Restarts the VM by initiating a graceful shutdown. 

90 

91 Parameters 

92 ---------- 

93 params : dict 

94 Flat dictionary of (key, value) pairs of tunable parameters. 

95 

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 """ 

102 

103 def vm_deprovision(self, params: dict) -> Tuple["Status", dict]: 

104 """ 

105 Deallocates the VM by shutting it down then releasing the compute resources. 

106 

107 Parameters 

108 ---------- 

109 params : dict 

110 Flat dictionary of (key, value) pairs of tunable parameters. 

111 

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 """ 

118 

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. 

123 

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. 

130 

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 """