ec2-ssh 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/ec2-ssh.rb +1 -1
- data/lib/ec2-ssh/aws.rb +12 -4
- data/lib/ec2-ssh/cli.rb +2 -2
- data/lib/ec2-ssh/utils.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4a8cbe419bf1a45f6e32e01a1d4ba9cb192a895
|
4
|
+
data.tar.gz: 158753292a848f88511fd5f579d04f3626311251
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e507425bf577899eccb6868198457ad189eb7f15585e92d51fb09380e2f039e41f59d741c4f4b5e54cc300c03ecad97fb5f59f0b19b1ecad4789c7aa855300ca
|
7
|
+
data.tar.gz: 6c1372931fe51e79e7d59fb9c67c9f39b1a45e41dc51a71d6e8eb39058427a88504cc719f9c8d9ae32cb97bc24621003db0ba42f7cfb73a7e3cb3bfbde15ea1e
|
data/README.md
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
This utility is to be able to connect and run multiple commands either parallel sequential or in groups (based on sshkit https://github.com/capistrano/sshkit)
|
2
|
+
|
3
|
+
|
4
|
+
seperate commands with a semicolon
|
5
|
+
|
6
|
+
default region: us-east-1
|
7
|
+
default user: ec2-user
|
8
|
+
default connnection :parallel
|
9
|
+
|
10
|
+
|
11
|
+
Groups were designed in this case to relieve problems (mass Git checkouts) where you rely on a contested resource that you don't want to DDOS by hitting it too hard.
|
12
|
+
|
13
|
+
Sequential runs were intended to be used for rolling restarts, amongst other similar use-cases.
|
14
|
+
|
15
|
+
|
16
|
+
--terminal will open multiple terminals windows of all servers found (currently only supported on OSX iTerm2)
|
17
|
+
|
18
|
+
|
19
|
+
Usage:
|
20
|
+
ec2-ssh connect --cmd=CMD
|
21
|
+
|
22
|
+
Options:
|
23
|
+
--cmd=CMD # commmand to run on remote servers
|
24
|
+
[--profile=PROFILE] # aws cli profile
|
25
|
+
# Default: default
|
26
|
+
[--region=REGION] # region
|
27
|
+
# Default: us-east-1
|
28
|
+
u, [--user=USER] # run as user
|
29
|
+
# Default: ec2-user
|
30
|
+
p, [--parallel=PARALLEL] # run in parallel
|
31
|
+
s, [--sequence=SEQUENCE] # run in sequence
|
32
|
+
g, [--groups=GROUPS] # run in groups
|
33
|
+
l, [--groups-limit=N] # limit
|
34
|
+
w, [--wait=N] # wait
|
35
|
+
[--as=AS] # get autoscale groups
|
36
|
+
[--tag-key=TAG_KEY] # tag key to filter instances by
|
37
|
+
# Default: Name
|
38
|
+
[--tag-value=TAG_VALUE] # tag value to filter instances by
|
39
|
+
t, [--terminal=TERMINAL] # open terminal tabs for all servers
|
40
|
+
|
41
|
+
Connect to autoscale instance (random instance), Pass --cmd='whatever' to run a cmd on the server
|
data/lib/ec2-ssh.rb
CHANGED
data/lib/ec2-ssh/aws.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pry'
|
1
2
|
module Ec2Ssh::Cli::Aws
|
2
3
|
def aws_init(profile, region)
|
3
4
|
ENV['AWS_PROFILE'] = profile
|
@@ -7,7 +8,7 @@ module Ec2Ssh::Cli::Aws
|
|
7
8
|
@as = Aws::AutoScaling::Client.new()
|
8
9
|
@ec2 = Aws::EC2::Client.new()
|
9
10
|
|
10
|
-
say "Currently running
|
11
|
+
say "Currently running AWS User is: #{Aws::IAM::CurrentUser.new.arn}"
|
11
12
|
end
|
12
13
|
|
13
14
|
def get_auto_scale_groups
|
@@ -34,6 +35,7 @@ module Ec2Ssh::Cli::Aws
|
|
34
35
|
def get_instances(tag_key, tag_value)
|
35
36
|
@all_servers = []
|
36
37
|
|
38
|
+
say "Fetching instances with #{tag_key}: #{tag_value}", color = :white
|
37
39
|
response = @ec2.describe_instances({
|
38
40
|
filters: [
|
39
41
|
{
|
@@ -51,11 +53,17 @@ module Ec2Ssh::Cli::Aws
|
|
51
53
|
})
|
52
54
|
|
53
55
|
if !response.reservations.empty?
|
54
|
-
response.reservations.each {|r| r.instances.inject(@all_servers){|acc, k|
|
56
|
+
response.reservations.each {|r| r.instances.inject(@all_servers){|acc, k|
|
57
|
+
if k.public_ip_address.nil?
|
58
|
+
say "Could not find public ip address for instance: #{k.instance_id}, falling back to private ip address", color = :yellow
|
59
|
+
acc << k.private_ip_address; acc
|
60
|
+
else
|
61
|
+
acc << k.public_ip_address; acc
|
62
|
+
end
|
63
|
+
}}
|
55
64
|
else
|
56
65
|
say "could not find any instances with the tag #{tag_key}: #{tag_value} on #{@region}"
|
57
66
|
end
|
58
|
-
|
59
|
-
say "All servers: #{@all_servers.size}"
|
67
|
+
say "All servers: #{@all_servers}"
|
60
68
|
end
|
61
69
|
end
|
data/lib/ec2-ssh/cli.rb
CHANGED
@@ -17,7 +17,7 @@ class Ec2Ssh::Cli < Thor
|
|
17
17
|
default_task :connect
|
18
18
|
|
19
19
|
desc "connect", "Connect to autoscale instance (random instance), Pass --cmd='whatever' to run a cmd on the server (use ; to seperate commands)"
|
20
|
-
method_option :cmd, :desc => 'commmand to run on remote servers'
|
20
|
+
method_option :cmd, :desc => 'commmand to run on remote servers'
|
21
21
|
method_option :profile, :desc => 'aws cli profile', :default => 'default'
|
22
22
|
method_option :region, :desc => "region", :default => 'us-east-1'
|
23
23
|
method_option :user, :aliases => 'u', :desc => 'run as user', :default => 'ec2-user'
|
@@ -39,7 +39,7 @@ class Ec2Ssh::Cli < Thor
|
|
39
39
|
|
40
40
|
if options[:as]
|
41
41
|
get_auto_scale_groups
|
42
|
-
|
42
|
+
else options[:tag_value]
|
43
43
|
get_instances(options[:tag_key].chomp, options[:tag_value].chomp)
|
44
44
|
end
|
45
45
|
|
data/lib/ec2-ssh/utils.rb
CHANGED