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. ...@@ -30,8 +30,10 @@ group and state.
""" """
import argparse import argparse
import boto import boto
import boto.ec2.autoscale
import json import json
from collections import defaultdict from collections import defaultdict
from os import environ
class LifecycleInventory(): class LifecycleInventory():
...@@ -54,7 +56,7 @@ class LifecycleInventory(): ...@@ -54,7 +56,7 @@ class LifecycleInventory():
return environment,deployment return environment,deployment
def get_instance_dict(self): 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() reservations = ec2.get_all_instances()
dict = {} dict = {}
...@@ -65,8 +67,8 @@ class LifecycleInventory(): ...@@ -65,8 +67,8 @@ class LifecycleInventory():
return dict return dict
def run(self): def run(self):
autoscale = boto.connect_autoscale(profile_name=self.profile) asg = boto.ec2.autoscale.connect_to_region(region,profile_name=self.profile)
groups = autoscale.get_all_groups() groups = asg.get_all_groups()
instances = self.get_instance_dict() instances = self.get_instance_dict()
inventory = defaultdict(list) inventory = defaultdict(list)
...@@ -92,7 +94,6 @@ if __name__=="__main__": ...@@ -92,7 +94,6 @@ if __name__=="__main__":
parser.add_argument('-l', '--list', help='Ansible passes this, we ignore it.', action='store_true', default=True) parser.add_argument('-l', '--list', help='Ansible passes this, we ignore it.', action='store_true', default=True)
args = parser.parse_args() 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 ...@@ -18,6 +18,8 @@ It relies on some component applying the proper tags and performing pre-retireme
import argparse import argparse
import boto import boto
import boto.ec2
import boto.sqs
import json import json
import subprocess import subprocess
from boto.sqs.message import RawMessage from boto.sqs.message import RawMessage
...@@ -44,15 +46,19 @@ class LifecycleHandler: ...@@ -44,15 +46,19 @@ class LifecycleHandler:
os.environ["PATH"] = bin_directory + os.pathsep + os.environ["PATH"] os.environ["PATH"] = bin_directory + os.pathsep + os.environ["PATH"]
self.aws_bin = spawn.find_executable('aws') self.aws_bin = spawn.find_executable('aws')
self.python_bin = spawn.find_executable('python') 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, python_bin=self.python_bin,
aws_bin=self.aws_bin, aws_bin=self.aws_bin)
profile=self.profile) 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.dry_run = dry_run
self.ec2_con = boto.connect_ec2() self.ec2_con = boto.ec2.connect_to_region(self.region)
self.sqs_con = boto.connect_sqs() self.sqs_con = boto.sqs.connect_to_region(self.region)
def process_lifecycle_messages(self): def process_lifecycle_messages(self):
queue = self.sqs_con.get_queue(self.queue) 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