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

7 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

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

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

16 

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

18 """ 

19 Start a Host/VM. 

20 

21 Parameters 

22 ---------- 

23 params : dict 

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

25 

26 Returns 

27 ------- 

28 result : (Status, dict) 

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

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

31 """ 

32 

33 def stop_host(self, params: dict, force: bool = False) -> Tuple["Status", dict]: 

34 """ 

35 Stops the Host/VM by initiating a (graceful) shutdown. 

36 

37 Parameters 

38 ---------- 

39 params : dict 

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

41 force : bool 

42 If True, force stop the Host/VM. 

43 

44 Returns 

45 ------- 

46 result : (Status, dict) 

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

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

49 """ 

50 

51 def restart_host(self, params: dict, force: bool = False) -> Tuple["Status", dict]: 

52 """ 

53 Restarts the host by initiating a (graceful) shutdown. 

54 

55 Parameters 

56 ---------- 

57 params : dict 

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

59 force : bool 

60 If True, force restart the Host/VM. 

61 

62 Returns 

63 ------- 

64 result : (Status, dict) 

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

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

67 """ 

68 

69 def wait_host_operation(self, params: dict) -> Tuple["Status", dict]: 

70 """ 

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

72 Return TIMED_OUT when timing out. 

73 

74 Parameters 

75 ---------- 

76 params: dict 

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

78 Must have the "asyncResultsUrl" key to get the results. 

79 If the key is not present, return Status.PENDING. 

80 

81 Returns 

82 ------- 

83 result : (Status, dict) 

84 A pair of Status and result. 

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

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

87 """