added image search, expand user home dir based on platform, removed elastic ips to save budget, load AWS credentials file, fixed ÓOM in AWS m1.tiny when installing faafo reqs using pip, increased timeout

This commit is contained in:
Sebastian Rieger
2022-04-26 23:39:38 +02:00
parent 162db34e1b
commit 23f48f85cd
2 changed files with 118 additions and 77 deletions

View File

@ -1,4 +1,6 @@
import getpass
import configparser
from os.path import expanduser
# import os
# import libcloud.security
@ -6,6 +8,8 @@ import time
from libcloud.compute.providers import get_driver
from libcloud.compute.types import Provider, NodeState
home = expanduser("~")
# reqs:
# services: EC2 (nova, glance, neutron)
# resources: 2 instances (m1.small), 2 elastic ips (1 keypair, 2 security groups)
@ -28,14 +32,18 @@ def main():
#
###########################################################################
# see AWS Educate classroom, Account Details
# see AWS Academy Lab for Account Details
# read credentials from file
config = configparser.ConfigParser()
config.read_file(open(home + '/.aws/credentials'))
aws_access_key_id = config['default']['aws_access_key_id']
aws_secret_access_key = config['default']['aws_secret_access_key']
aws_session_token = config['default']['aws_session_token']
# aws_access_key_id = "ASIAX..."
# aws_secret_access_key = "eGwE12j..."
# aws_session_token = "FwoGZXIvYXdzEK///////////wEaDE..."
# access_id = getpass.win_getpass("Enter your access_id:")
# secret_key = getpass.win_getpass("Enter your secret_key:")
# session_token = getpass.win_getpass("Enter your session_token:")
access_id = "ASIAX..."
secret_key = "eGwE12j..."
session_token = "FwoGZXIvYXdzEK///////////wEaDE..."
###########################################################################
#
@ -44,9 +52,9 @@ def main():
###########################################################################
provider = get_driver(Provider.EC2)
conn = provider(access_id,
secret_key,
token=session_token,
conn = provider(aws_access_key_id,
aws_secret_access_key,
token=aws_session_token,
region=region_name)
###########################################################################
@ -59,8 +67,9 @@ def main():
for instance in conn.list_nodes():
if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
'app-services', 'app-api-1', 'app-api-2']:
print('Destroying Instance: %s' % instance.name)
conn.destroy_node(instance)
if instance.state.value != 'terminated':
print('Destroying Instance: %s' % instance.name)
conn.destroy_node(instance)
# wait until all nodes are destroyed to be able to remove depended security groups
nodes_still_running = True
@ -78,7 +87,19 @@ def main():
# delete security groups
for group in conn.ex_list_security_groups():
if group in ['control', 'worker', 'api', 'services']:
# services depends on worker and api, so delete services first...
if group in ['services']:
print('Deleting security group: %s' % group)
conn.ex_delete_security_group(group)
for group in conn.ex_list_security_groups():
# control depends on worker, so delete control before worker...
if group in ['control']:
print('Deleting security group: %s' % group)
conn.ex_delete_security_group(group)
for group in conn.ex_list_security_groups():
if group in ['worker', 'api']:
print('Deleting security group: %s' % group)
conn.ex_delete_security_group(group)