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

7 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-07 01:52 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Protocol interface for Host/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 SupportsHostProvisioning(Protocol): 

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

16 

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

18 """ 

19 Check if Host/VM is ready. Deploy a new Host/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_host_deployment(self, params: dict, *, is_setup: bool) -> Tuple["Status", dict]: 

36 """ 

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

38 Return TIMED_OUT when timing out. 

39 

40 Parameters 

41 ---------- 

42 params : dict 

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

44 is_setup : bool 

45 If True, wait for Host/VM being deployed; otherwise, wait for successful 

46 deprovisioning. 

47 

48 Returns 

49 ------- 

50 result : (Status, dict) 

51 A pair of Status and result. 

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

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

54 """ 

55 

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

57 """ 

58 Deprovisions the Host/VM by deleting it. 

59 

60 Parameters 

61 ---------- 

62 params : dict 

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

64 

65 Returns 

66 ------- 

67 result : (Status, dict={}) 

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

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

70 """ 

71 

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

73 """ 

74 Deallocates the Host/VM by shutting it down then releasing the compute 

75 resources. 

76 

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

78 restarted, which may have different performance characteristics. 

79 

80 Parameters 

81 ---------- 

82 params : dict 

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

84 

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