Commit 4960a6b1 by Kevin Falcone

Merge pull request #3022 from edx/jibsheet/region-aware-lifecycle-watcher

Jibsheet/region aware lifecycle watcher
parents b3c74b47 71e6708f
......@@ -30,8 +30,10 @@ group and state.
"""
import argparse
import boto
import boto.ec2.autoscale
import json
from collections import defaultdict
from os import environ
class LifecycleInventory():
......@@ -54,7 +56,7 @@ class LifecycleInventory():
return environment,deployment
def get_instance_dict(self):
ec2 = boto.connect_ec2(profile_name=self.profile)
ec2 = boto.ec2.connect_to_region(region,profile_name=self.profile)
reservations = ec2.get_all_instances()
dict = {}
......@@ -65,8 +67,8 @@ class LifecycleInventory():
return dict
def run(self):
autoscale = boto.connect_autoscale(profile_name=self.profile)
groups = autoscale.get_all_groups()
asg = boto.ec2.autoscale.connect_to_region(region,profile_name=self.profile)
groups = asg.get_all_groups()
instances = self.get_instance_dict()
inventory = defaultdict(list)
......@@ -92,7 +94,6 @@ if __name__=="__main__":
parser.add_argument('-l', '--list', help='Ansible passes this, we ignore it.', action='store_true', default=True)
args = parser.parse_args()
LifecycleInventory(args.profile).run()
region = environ.get('AWS_REGION','us-east-1')
LifecycleInventory(args.profile).run()
......@@ -18,6 +18,8 @@ It relies on some component applying the proper tags and performing pre-retireme
import argparse
import boto
import boto.ec2
import boto.sqs
import json
import subprocess
from boto.sqs.message import RawMessage
......@@ -44,15 +46,19 @@ class LifecycleHandler:
os.environ["PATH"] = bin_directory + os.pathsep + os.environ["PATH"]
self.aws_bin = spawn.find_executable('aws')
self.python_bin = spawn.find_executable('python')
self.region = os.environ.get('AWS_REGION','us-east-1')
self.base_cli_command ="{python_bin} {aws_bin} --profile {profile} ".format(
self.base_cli_command ="{python_bin} {aws_bin} ".format(
python_bin=self.python_bin,
aws_bin=self.aws_bin,
profile=self.profile)
aws_bin=self.aws_bin)
if self.profile:
self.base_cli_command += "--profile {profile} ".format(profile=self.profile)
if self.region:
self.base_cli_command += "--region {region} ".format(region=self.region)
self.dry_run = dry_run
self.ec2_con = boto.connect_ec2()
self.sqs_con = boto.connect_sqs()
self.ec2_con = boto.ec2.connect_to_region(self.region)
self.sqs_con = boto.sqs.connect_to_region(self.region)
def process_lifecycle_messages(self):
queue = self.sqs_con.get_queue(self.queue)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment