From b6945395d7759c77c70ae8af015e192cf74729f8 Mon Sep 17 00:00:00 2001 From: Aleck Landgraf Date: Fri, 15 Jan 2016 11:05:15 -0800 Subject: [PATCH 1/2] adds filtering capability --- README.md | 11 +++++++++++ ssh2 | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 0f0221b..618657f 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,19 @@ Options: -p PROFILE, --profile=PROFILE provide AWS profile --ip=IP connect using IP instead of DNS + -g GREP, --grep=GREP filter the server list + +$ ssh2 -g Cron + +Servers list: + +[1] ec2-XXX-XXX-XXX-XXX.us-west-2.compute.amazonaws.com Cron + +Which server would you like to connect to [1]? ``` + + ## 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): From 3104d3b1d6be8674477c137e6c228f4a67d15f4c Mon Sep 17 00:00:00 2001 From: Aleck Landgraf Date: Fri, 15 Jan 2016 11:07:19 -0800 Subject: [PATCH 2/2] finishes docs --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 618657f..6404ce3 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,22 @@ Options: 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 Cron +``` +$ ssh2 -g webrt Servers list: -[1] ec2-XXX-XXX-XXX-XXX.us-west-2.compute.amazonaws.com Cron +[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 -Which server would you like to connect to [1]? +Connecting to webrtc-kurento ec2-XX-XX-XX-XX.us-west-2.compute.amazonaws.com ```