owssh 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/owssh +2 -80
- data/lib/owssh.rb +142 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 055e6687a3bc65588773367a5f3575263e4e607f
|
4
|
+
data.tar.gz: 5514751e984d80ea14b1f90d779b48c68e492db0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7126d2c876a5716df2812a40910d0ac3eade22c469559bb69e409fcd15bfe8c57c13dd355e91647f0727ffb6859f48765b1e80a969a4cb522611bd66d16ae57e
|
7
|
+
data.tar.gz: 09cec258e7b7e31ec574b507105e6948289d7120c31017a2c72facfeff2ade768518fa787adc795a6784d88c9e91cf4bcd3cfff4edfbf871d4b7e05ff446ddb0
|
data/bin/owssh
CHANGED
@@ -1,83 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'json'
|
5
|
-
require 'pp'
|
3
|
+
require 'owssh'
|
6
4
|
|
7
|
-
|
8
|
-
$debug = false
|
9
|
-
$ssh_key_file = "~/.ssh/id_rsa_dev"
|
10
|
-
$owssh_config = "~/.owssh_conf"
|
11
|
-
|
12
|
-
if ARGV.empty?
|
13
|
-
puts "Usage:"
|
14
|
-
puts "owssh list - List all environments"
|
15
|
-
puts "owssh describe - Show details of instances in all stacks"
|
16
|
-
puts "owssh describe [stack] - Show details of a specific stack"
|
17
|
-
puts "owssh [stack] [instance] - SSH to an instance in a stack"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
$stacks = {}
|
22
|
-
$instances = {}
|
23
|
-
|
24
|
-
stacks_json = JSON.parse(`aws opsworks describe-stacks`)
|
25
|
-
|
26
|
-
stacks_json['Stacks'].each do |stack|
|
27
|
-
if $debug then puts "Stack Name: #{stack['Name'].gsub(' ','_').downcase} Stack ID: #{stack['StackId']}" end
|
28
|
-
stack_name = stack['Name'].gsub(' ','_').downcase
|
29
|
-
$stacks[stack_name.to_s] = stack['StackId']
|
30
|
-
end
|
31
|
-
|
32
|
-
if ARGV[0] == "list" then
|
33
|
-
puts " --- Stacks ---"
|
34
|
-
$stacks.each do |stack_name, id|
|
35
|
-
puts "Name: #{stack_name} ID: #{id}"
|
36
|
-
end
|
37
|
-
exit
|
38
|
-
elsif ARGV[0] == "describe" && ARGV[1].nil? then
|
39
|
-
$stacks.each do |stack_name, id|
|
40
|
-
puts "Stack: #{stack_name} ID: #{id}"
|
41
|
-
instances_json = JSON.parse(`aws opsworks describe-instances --stack-id #{id}`)
|
42
|
-
instances_json['Instances'].each do |instance|
|
43
|
-
ip = instance['ElasticIp'] || instance['PublicIp']
|
44
|
-
puts "Name: #{instance['Hostname']} IP: #{ip}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
exit
|
48
|
-
elsif ARGV[0] == "describe" && !ARGV[1].nil? then
|
49
|
-
stack_arg = ARGV[1]
|
50
|
-
if $stacks.has_key?(ARGV[1].downcase.to_s) then
|
51
|
-
if $debug then puts "Stack ID: #{$stacks[stack_arg]}" end
|
52
|
-
puts "Getting data for Stack: #{stack_arg}"
|
53
|
-
instances_json = JSON.parse(`aws opsworks describe-instances --stack-id #{$stacks[stack_arg]}`)
|
54
|
-
instances_json['Instances'].each do |instance|
|
55
|
-
ip = instance['ElasticIp'] || instance['PublicIp'] || "DOWN"
|
56
|
-
puts "Name: #{instance['Hostname']} IP: #{ip}"
|
57
|
-
end
|
58
|
-
elsif
|
59
|
-
puts "Unable to find stack named '#{ARGV[1]}'"
|
60
|
-
exit
|
61
|
-
end
|
62
|
-
elsif $stacks.has_key?(ARGV[0].downcase.to_s) then
|
63
|
-
if ARGV[1].nil? then
|
64
|
-
puts "Please enter an instance name. I.E. rails-app3"
|
65
|
-
exit
|
66
|
-
end
|
67
|
-
stack_arg = ARGV[0].downcase
|
68
|
-
instances_json = JSON.parse(`aws opsworks describe-instances --stack-id #{$stacks[stack_arg]}`)
|
69
|
-
instances_json['Instances'].each do |instance|
|
70
|
-
$instances["#{instance["Hostname"]}"] = instance["PublicIp"]
|
71
|
-
end
|
72
|
-
if $instances.has_key?(ARGV[1]) then
|
73
|
-
puts "Opening connection to #{ARGV[1]}..."
|
74
|
-
exec("ssh -i ~/.ssh/id_rsa_dev ubuntu@#{$instances[ARGV[1].to_s]}")
|
75
|
-
else
|
76
|
-
puts "Instance with name '#{ARGV[1]}' not found"
|
77
|
-
exit
|
78
|
-
end
|
79
|
-
else
|
80
|
-
puts "I don't quite understand what you're asking me to do..."
|
81
|
-
puts " Try running owssh with no arguments for help!"
|
82
|
-
exit
|
83
|
-
end
|
5
|
+
Owssh.run
|
data/lib/owssh.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'json'
|
5
|
+
require 'pp'
|
6
|
+
require 'command_line_reporter'
|
7
|
+
|
8
|
+
class Owssh
|
9
|
+
include CommandLineReporter
|
10
|
+
|
11
|
+
def get_stacks
|
12
|
+
my_stacks = {}
|
13
|
+
stacks_json = JSON.parse(`aws opsworks describe-stacks`)
|
14
|
+
|
15
|
+
stacks_json['Stacks'].each do |stack|
|
16
|
+
if $debug then puts "Stack Name: #{stack['Name'].gsub(' ','_').downcase} Stack ID: #{stack['StackId']}" end
|
17
|
+
stack_name = stack['Name'].gsub(' ','_').downcase
|
18
|
+
my_stacks[stack_name.to_s] = stack['StackId']
|
19
|
+
end
|
20
|
+
my_stacks
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_instances(id)
|
24
|
+
my_instances = {}
|
25
|
+
instances_json = JSON.parse(`aws opsworks describe-instances --stack-id #{id}`)
|
26
|
+
instances_json['Instances'].each do |instance|
|
27
|
+
pub_ip = instance['ElasticIp'] || instance['PublicIp'] || "DOWN"
|
28
|
+
priv_ip = instance['PrivateIp'] || "N/A"
|
29
|
+
type = instance['Hostname'].split("-").first
|
30
|
+
my_instances[instance['Hostname'].to_s] = { "PUB_IP" => pub_ip.to_s, "PRIV_IP" => priv_ip.to_s, "TYPE" => type }
|
31
|
+
end
|
32
|
+
my_instances
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_instances(instances)
|
36
|
+
table(:border => true) do
|
37
|
+
row do
|
38
|
+
column('Hostname', :width => 20)
|
39
|
+
column('Public IP', :width => 15, :align => 'right')
|
40
|
+
column('Private IP', :width => 15, :align => 'right')
|
41
|
+
column('Type', :width => 12)
|
42
|
+
end
|
43
|
+
instances.each do |instance_name, data|
|
44
|
+
row do
|
45
|
+
column(instance_name)
|
46
|
+
column(data['PUB_IP'])
|
47
|
+
column(data['PRIV_IP'])
|
48
|
+
column(data['TYPE'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def print_stacks(stacks)
|
55
|
+
table(:border => true) do
|
56
|
+
row do
|
57
|
+
column('Stack Name', :width => 20)
|
58
|
+
column('Stack ID', :width => 40, :align => 'right')
|
59
|
+
end
|
60
|
+
stacks.each do |stack_name, id|
|
61
|
+
row do
|
62
|
+
column(stack_name)
|
63
|
+
column(id)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def run
|
70
|
+
# Export environment variables for AWS CLI here
|
71
|
+
$debug = false
|
72
|
+
$ssh_key_file = "~/.ssh/id_rsa_dev"
|
73
|
+
$owssh_config = "~/.owssh_conf"
|
74
|
+
|
75
|
+
if ARGV.empty?
|
76
|
+
puts "Usage:"
|
77
|
+
puts "owssh list - List all environments"
|
78
|
+
puts "owssh describe - Show details of hosts in all stacks"
|
79
|
+
puts "owssh describe [Stack Name] - Show details of a specific stack"
|
80
|
+
puts "owssh [Stack Name] [Hostname] - SSH to a host in a stack"
|
81
|
+
puts "owssh [Stack Name] [Hostname] [Command]- SSH to a host in a stack and run a command"
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
$stacks = {}
|
86
|
+
$instances = {}
|
87
|
+
|
88
|
+
$stacks = get_stacks
|
89
|
+
|
90
|
+
if ARGV[0] == "list" then
|
91
|
+
puts "Getting list of stacks..."
|
92
|
+
print_stacks($stacks)
|
93
|
+
exit
|
94
|
+
elsif ARGV[0] == "describe" && ARGV[1].nil? then
|
95
|
+
$stacks.each do |stack_name, id|
|
96
|
+
puts "Getting data for Stack: #{stack_name}"
|
97
|
+
$instances = get_instances(id)
|
98
|
+
print_instances($instances)
|
99
|
+
end
|
100
|
+
exit
|
101
|
+
elsif ARGV[0] == "describe" && !ARGV[1].nil? then
|
102
|
+
stack_name = ARGV[1]
|
103
|
+
if $stacks.has_key?(ARGV[1].downcase.to_s) then
|
104
|
+
if $debug then puts "Stack ID: #{$stacks[stack_name]}" end
|
105
|
+
puts "Getting data for Stack: #{stack_name}"
|
106
|
+
$instances = get_instances($stacks[stack_name])
|
107
|
+
print_instances($instances)
|
108
|
+
elsif
|
109
|
+
puts "Unable to find stack named '#{ARGV[1]}'"
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
elsif $stacks.has_key?(ARGV[0].downcase.to_s) then
|
113
|
+
if ARGV[1].nil? then
|
114
|
+
puts "Please enter an instance name. I.E. rails-app3"
|
115
|
+
exit
|
116
|
+
end
|
117
|
+
stack_arg = ARGV[0].downcase
|
118
|
+
instances_json = JSON.parse(`aws opsworks describe-instances --stack-id #{$stacks[stack_arg]}`)
|
119
|
+
instances_json['Instances'].each do |instance|
|
120
|
+
$instances["#{instance["Hostname"]}"] = instance["PublicIp"]
|
121
|
+
end
|
122
|
+
if $instances.has_key?(ARGV[1]) then
|
123
|
+
if ARGV[2].nil? then
|
124
|
+
puts "Opening connection to #{ARGV[1]}..."
|
125
|
+
exec("ssh -i ~/.ssh/id_rsa_dev ubuntu@#{$instances[ARGV[1].to_s]}")
|
126
|
+
else
|
127
|
+
puts "Running comand #{ARGV[2]} on host #{ARGV[1]}..."
|
128
|
+
exec("ssh -i ~/.ssh/id_rsa_dev ubuntu@#{$instances[ARGV[1].to_s]} '#{ARGV[2]}'")
|
129
|
+
end
|
130
|
+
else
|
131
|
+
puts "Instance with name '#{ARGV[1]}' not found"
|
132
|
+
exit
|
133
|
+
end
|
134
|
+
else
|
135
|
+
puts "I don't quite understand what you're asking me to do..."
|
136
|
+
puts " Try running owssh with no arguments for help!"
|
137
|
+
exit
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
Owssh.new.run
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: owssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Hutchins
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-02-27 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: command_line_reporter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
13
27
|
description: Wrapper for awscli for listing OpsWorks hosts and sshing to them
|
14
28
|
email: flipture@gmail.com
|
15
29
|
executables:
|
@@ -17,6 +31,7 @@ executables:
|
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
34
|
+
- lib/owssh.rb
|
20
35
|
- bin/owssh
|
21
36
|
homepage: http://phutchins.com/
|
22
37
|
licenses:
|
@@ -38,9 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
53
|
version: '0'
|
39
54
|
requirements: []
|
40
55
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.1.11
|
42
57
|
signing_key:
|
43
58
|
specification_version: 4
|
44
59
|
summary: OWssh
|
45
60
|
test_files: []
|
46
|
-
has_rdoc:
|