-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawn_instance.py
executable file
·45 lines (35 loc) · 1.15 KB
/
spawn_instance.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
#!/usr/bin/env python3
import argparse
from modules.aws import AWSWrapper
from modules.digital_ocean import DigitalOceanWrapper
from modules.gcp import GCPWrapper
from modules.logger import Logger
logger = Logger(__name__)
def parse_arguments():
parser = argparse.ArgumentParser(description="Spawn a cloud provider instance")
parser.add_argument(
"provider", type=str, help="Which cloud provider to use", choices=["aws", "do", "gcp"]
)
parser.add_argument(
"image", type=str, help="The machine image to use"
)
return parser.parse_args()
def main(provider, image):
if provider == "aws":
cls = AWSWrapper
elif provider == "do":
cls = DigitalOceanWrapper
elif provider == "gcp":
cls = GCPWrapper
else:
raise LookupError(f"Cloud provider `{provider}` is not implemented")
try:
with cls(image) as instance:
instance.wait_for_instance()
input("Press enter to exit")
except Exception as e:
logger.error(f"Instance error: {e}")
exit(-1)
if __name__ == "__main__":
args = parse_arguments()
main(args.provider, args.image)