diff --git a/README.md b/README.md index 0f0221b..6404ce3 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,27 @@ Options: -p PROFILE, --profile=PROFILE provide AWS profile --ip=IP connect using IP instead of DNS + -g GREP, --grep=GREP filter the server list ``` +### Filtering the list by EC2 instance name + +``` +$ ssh2 -g webrt + +Servers list: + +[1] ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com webrtc-kurento + +Which server would you like to connect to [1]? ^C + +$ ssh2 -g webrt 1 + +Connecting to webrtc-kurento ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com +``` + + + ## Requirements * [AWS CLI](https://aws.amazon.com/cli/) * Python diff --git a/ssh2 b/ssh2 index f87238f..660cd4f 100755 --- a/ssh2 +++ b/ssh2 @@ -24,6 +24,9 @@ parser.add_option("-r", "--region", action="store", parser.add_option("--ip", action="store", dest="ip", default=0, help="connect using IP instead of DNS") +parser.add_option("-g", "--grep", action="store", + dest="grep", default="", + help="filter the server list") (options, args) = parser.parse_args() cache_dir = os.environ.get('XDG_CACHE_HOME', @@ -88,6 +91,9 @@ for instances in parsed['Reservations']: for instance in instances['Instances']: all_instances.append(instance) +if options.grep: + all_instances = [inst for inst in all_instances if options.grep in extract_name(inst)] + if not num: print "\nServers list:\n" for i, instance in enumerate(all_instances, 1):