Skip to content

Commit

Permalink
Merge pull request soheil-zz#17 from alecklandgraf/master
Browse files Browse the repository at this point in the history
adds filters of EC2 instance names
  • Loading branch information
soheil committed Jan 15, 2016
2 parents d39fa16 + 3104d3b commit eb22eef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ssh2
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit eb22eef

Please sign in to comment.