Skip to content

Instantly share code, notes, and snippets.

@maracuja
Created November 4, 2014 16:55
Show Gist options
  • Save maracuja/f6bf7b8801ccc860b4d0 to your computer and use it in GitHub Desktop.
Save maracuja/f6bf7b8801ccc860b4d0 to your computer and use it in GitHub Desktop.
Get the ips pf existing boxes
import boto.ec2
aws_access_key_id=''
aws_secret_access_key=''
conn = boto.ec2.connect_to_region("eu-west-1", aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
reservations = conn.get_all_reservations()
def get_login(instance):
if 'name' in instance.tags:
if instance.tags['name'] == machine_name:
return 'ubuntu@%s' % instance.ip_address
if 'Name' in instance.tags:
if instance.tags['Name'] == machine_name:
return 'ubuntu@%s' % instance.ip_address
if 'aws:autoscaling:groupName' in instance.tags:
if instance.tags['aws:autoscaling:groupName'] == scale_group_name:
return 'ubuntu@%s' % instance.ip_address
machine_name = 'prod-backend'
scale_group_name = 'sg-release-v1.0'
print '== %s - %s =======================' % (scale_group_name, machine_name,)
boxes = []
for r in reservations:
box = get_login(r.instances[0])
if box:
boxes.append(box)
print boxes
machine_name = 'web-prod'
scale_group_name = 'sg-release-v1.1'
print '== %s - %s =======================' % (scale_group_name, machine_name,)
boxes = []
for r in reservations:
box = get_login(r.instances[0])
if box:
boxes.append(box)
print boxes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment