-
Notifications
You must be signed in to change notification settings - Fork 1
/
classroom.py
49 lines (34 loc) · 1013 Bytes
/
classroom.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
48
49
#! python
import csv
import boto3
import click
import summon as summon_module
from instances import get_sammancoach_machines
@click.group()
def cli():
pass
@cli.command()
@click.argument("classroom")
def terminate(classroom):
yes = click.prompt("are you sure? [y/N] ")
if yes == "y":
boto3.client("ec2").terminate_instances(InstanceIds=(ids_in_classroom(classroom)))
@cli.command()
@click.argument("classroom")
def stop(classroom):
boto3.client("ec2").stop_instances(InstanceIds=(ids_in_classroom(classroom)))
@cli.command()
@click.argument("classroom")
def start(classroom):
boto3.client("ec2").start_instances(InstanceIds=(ids_in_classroom(classroom)))
@cli.command()
@click.argument("classroom")
def ids(classroom):
print(ids_in_classroom(classroom))
def ids_in_classroom(classroom):
with open(classroom, "r", newline="") as f:
reader = csv.DictReader(f)
ids = [row["id"] for row in reader]
return ids
if __name__ == '__main__':
cli()