Skip to content

Instantly share code, notes, and snippets.

@maracuja
Created September 19, 2014 16:23
Show Gist options
  • Save maracuja/389ae55d7f332ff1aee8 to your computer and use it in GitHub Desktop.
Save maracuja/389ae55d7f332ff1aee8 to your computer and use it in GitHub Desktop.
Get Your Box IP Addresses
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()
boxes = [
{ 'name': 'skylark-web-dev-01', 'current_ip': '' },
{ 'name': 'skylark-web-uat-01', 'current_ip': '' },
{ 'name': 'skylark-web-staging-01', 'current_ip': '' },
{ 'name': 'bfi-web-dev-01', 'current_ip': '' },
{ 'name': 'bfi-web-uat-01', 'current_ip': '' },
{ 'name': 'bfi-web-staging-01', 'current_ip': '' },
]
def get_ip_address(box_name):
for r in reservations:
if r.instances[0].tags['Name'] == box_name:
return r.instances[0].ip_address
for box in boxes:
print '--- ' + box['name'] + ' - ' + box['current_ip'] + ' - ' + get_ip_address(box['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment