Created
February 6, 2015 14:50
-
-
Save ericcitaire/45515939d81aaee14ed6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import boto | |
import boto.ec2 | |
ec2 = boto.ec2.connect_to_region('eu-west-1') | |
reservations = ec2.get_all_instances() | |
def ow_stack(instance): | |
if 'opsworks:stack' in instance.tags: | |
return instance.tags['opsworks:stack'] | |
else: | |
return None | |
def ow_instance(instance): | |
if 'opsworks:instance' in instance.tags: | |
return instance.tags['opsworks:instance'] | |
else: | |
return None | |
for reservation in reservations: | |
for instance in reservation.instances: | |
if ow_stack(instance) == sys.argv[2] and ow_instance(instance) == sys.argv[3]: | |
from subprocess import call | |
call(["ssh", "-i", sys.argv[1], "-l", "ec2-user", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", "-o", "ServerAliveInterval=5", "-o", "ServerAliveCountMax=1", instance.private_ip_address]) | |
sys.exit(0) | |
sys.exit("Instance not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment