-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_scope.py
47 lines (37 loc) · 1.77 KB
/
cloud_scope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import argparse
import toml
from src.api_throttle import APIThrottle
from src.config import Config
from src.monitor import Monitor
if __name__ == "__main__":
# Parse command line arguments
parser = argparse.ArgumentParser(description="""
Monitors the availability of Lambda Labs' cloud instances
with customizable monitoring for specific instance types and regions.
Features configurable alerts via email or email-to-text for newly available instances.
Additionally, it can launch new instances upon availability and execute predefined scripts.
""")
parser.add_argument("config_file", help="Path to the configuration file.")
parser.add_argument("namespace", help="TOML configuration namespace.")
args = parser.parse_args()
# Attempt to load the TOML configuration file
try:
with open(args.config_file, "r") as file:
config_data = toml.load(file)
except FileNotFoundError:
raise FileNotFoundError(f"The configuration file '{args.config_file}' was not found.")
# Ensure the specified namespace exists
if args.namespace not in config_data:
raise ValueError(f"Namespace '{args.namespace}' not found in the configuration file.")
# Get the configuration for the specified namespace
namespace_config = config_data[args.namespace]
# Create an instance of the Config class, which also sets up logging
config = Config(**namespace_config)
# Create an instance of the Monitor class
monitor = Monitor(config=config)
# Create an instance of the APIThrottle class
api_throttle = APIThrottle(request_interval_ms=config.min_poll_delay_ms)
# Start monitoring instance availability with wait intervals
while True:
monitor.poll()
api_throttle.wait_for_next_request()