Coverage for mlos_bench/mlos_bench/services/types/host_provisioner_type.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-06 00:35 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6Protocol interface for Host/VM provisioning operations. 

7""" 

8 

9from typing import Tuple, Protocol, runtime_checkable, TYPE_CHECKING 

10 

11if TYPE_CHECKING: 

12 from mlos_bench.environments.status import Status 

13 

14 

15@runtime_checkable 

16class SupportsHostProvisioning(Protocol): 

17 """ 

18 Protocol interface for Host/VM provisioning operations. 

19 """ 

20 

21 def provision_host(self, params: dict) -> Tuple["Status", dict]: 

22 """ 

23 Check if Host/VM is ready. Deploy a new Host/VM, if necessary. 

24 

25 Parameters 

26 ---------- 

27 params : dict 

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

29 VMEnv tunables are variable parameters that, together with the 

30 VMEnv configuration, are sufficient to provision a VM. 

31 

32 Returns 

33 ------- 

34 result : (Status, dict={}) 

35 A pair of Status and result. The result is always {}. 

36 Status is one of {PENDING, SUCCEEDED, FAILED} 

37 """ 

38 

39 def wait_host_deployment(self, params: dict, *, is_setup: bool) -> Tuple["Status", dict]: 

40 """ 

41 Waits for a pending operation on a Host/VM to resolve to SUCCEEDED or FAILED. 

42 Return TIMED_OUT when timing out. 

43 

44 Parameters 

45 ---------- 

46 params : dict 

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

48 is_setup : bool 

49 If True, wait for Host/VM being deployed; otherwise, wait for successful deprovisioning. 

50 

51 Returns 

52 ------- 

53 result : (Status, dict) 

54 A pair of Status and result. 

55 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT} 

56 Result is info on the operation runtime if SUCCEEDED, otherwise {}. 

57 """ 

58 

59 def deprovision_host(self, params: dict) -> Tuple["Status", dict]: 

60 """ 

61 Deprovisions the Host/VM by deleting it. 

62 

63 Parameters 

64 ---------- 

65 params : dict 

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

67 

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 

75 def deallocate_host(self, params: dict) -> Tuple["Status", dict]: 

76 """ 

77 Deallocates the Host/VM by shutting it down then releasing the compute resources. 

78 

79 Note: This can cause the VM to arrive on a new host node when its 

80 restarted, which may have different performance characteristics. 

81 

82 Parameters 

83 ---------- 

84 params : dict 

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

86 

87 Returns 

88 ------- 

89 result : (Status, dict={}) 

90 A pair of Status and result. The result is always {}. 

91 Status is one of {PENDING, SUCCEEDED, FAILED} 

92 """