ec2-ssh 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f253fec1905d28a541b4a90f5539f850690ff1
4
- data.tar.gz: 5497db4af38b1ca7df990f23c18adbca843578f5
3
+ metadata.gz: c4a8cbe419bf1a45f6e32e01a1d4ba9cb192a895
4
+ data.tar.gz: 158753292a848f88511fd5f579d04f3626311251
5
5
  SHA512:
6
- metadata.gz: d0b7adbbe570f304bed85d7ae171a1f871375061eeb64a914b590684b40b32e39f53cb6adcc4481f9414895f7aadc1e79e9bd09b12e7c21a2e366d4f95bb9935
7
- data.tar.gz: 52078a2cd777a8477180f8e4a71fba99379c318b358e4a83a087fdfed5ddad0a5ffa2e2ff743d59c7529a78ccc37f6dfe4713d50e2400ba5553bb00b6e326ce1
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
@@ -1,5 +1,5 @@
1
1
  module Ec2Ssh
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  ABOUT = "ec2-ssh v#{VERSION} (c) #{Time.now.strftime("2015-%Y")} @innovia"
4
4
 
5
5
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -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 user is: #{Aws::IAM::CurrentUser.new.arn}"
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| acc << k.public_ip_address; acc}}
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
@@ -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', :required => true
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
- elsif options[:tag_value]
42
+ else options[:tag_value]
43
43
  get_instances(options[:tag_key].chomp, options[:tag_value].chomp)
44
44
  end
45
45
 
@@ -1,6 +1,7 @@
1
1
  module Ec2Ssh::Cli::Utils
2
2
  def open_in_terminal
3
3
  @all_servers.each do |server|
4
+ say "Opening #{server} in a new tab", color = :cyan
4
5
  `osascript <<-eof
5
6
  tell application "iTerm"
6
7
  make new terminal
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ami Mahloof