awsssh 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +2 -0
- data/awsssh.gemspec +27 -16
- data/bin/awsssh +1 -1
- data/lib/awsssh.rb +169 -155
- data/lib/awsssh/version.rb +3 -0
- data/spec/awsssh_spec.rb +17 -0
- metadata +66 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b63fb129a41f40f706decc85cd615a650050d9c
|
4
|
+
data.tar.gz: 65d9e9f45738dd2a61dbc6340213e5306a7067fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4f6daf66995d090eccdc8748f0485816a5153e494c2ceeceef62928b2247d1ff282ca913e614f89b44423d370ca3ed294b3fb0b2358d49e5b41531f5cba50a
|
7
|
+
data.tar.gz: 99afa2c0f438f16472e39162ca15fcfd292ca06f0560d32804c93f821ad9a04cefc250fb00c3fa35ff2d061508f889daf57d615ebe18cbb3302c106e11ca3873
|
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sebastian Thiele
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -34,6 +34,9 @@ Zeigt die Hilfe an
|
|
34
34
|
Sebastian Thiele Twitter: (@sebat)
|
35
35
|
|
36
36
|
## Changelog
|
37
|
+
**2015-03-02 - v 2.2.0**
|
38
|
+
* [enh] Alias for list servers and accounts changed
|
39
|
+
* [fix] Build own punlic DNS if no public dns is set
|
37
40
|
|
38
41
|
**2014-08-01 - v 2.1.2**
|
39
42
|
* [enh] Alias for `--list-servers` and `--list-accounts`
|
data/Rakefile
ADDED
data/awsssh.gemspec
CHANGED
@@ -1,19 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
s.summary = "Connects you with OpsWorks EC2"
|
6
|
-
s.description = "This will connects you with an EC2 instace"
|
7
|
-
s.authors = ["Sebastian Thiele"]
|
8
|
-
s.email = [%w(Sebastian.Thiele infopark.de).join('@')]
|
9
|
-
s.license = "MIT"
|
10
|
-
s.files = `git ls-files`.split("\n")
|
11
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
s.homepage = "https://github.com/sethiele/awsssh"
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'awsssh/version'
|
13
5
|
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "awsssh"
|
8
|
+
spec.version = Awsssh::VERSION
|
9
|
+
spec.authors = ["Sebastian Thiele"]
|
10
|
+
spec.email = [%w(Sebastian.Thiele infopark.de).join('@')]
|
11
|
+
spec.summary = "Connects you with OpsWorks EC2"
|
12
|
+
spec.description = "This will connects you with an EC2 instace"
|
13
|
+
spec.homepage = "https://github.com/sethiele/awsssh"
|
14
|
+
spec.license = "MIT"
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.8.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.4.2"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.10.1"
|
24
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "net-ssh", "2.7.0"
|
27
|
+
spec.add_runtime_dependency "inifile", "2.0.2"
|
28
|
+
spec.add_runtime_dependency "aws-sdk", "1.35.0"
|
29
|
+
spec.add_runtime_dependency "thor", "0.18.1"
|
19
30
|
end
|
data/bin/awsssh
CHANGED
data/lib/awsssh.rb
CHANGED
@@ -1,194 +1,208 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
1
|
+
require "awsssh/version"
|
3
2
|
require 'net/ssh'
|
4
3
|
require 'json'
|
5
4
|
require "aws-sdk"
|
6
|
-
# require
|
5
|
+
# Bundler.require(:default, :development)
|
7
6
|
require "inifile"
|
8
7
|
require "thor"
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
module Awsssh
|
10
|
+
class Awsssh < Thor
|
11
|
+
CONFIG_DIR = ENV['AWSSSH_CONFIG_DIR'] || "/Users/#{ENV['USER']}/.aws/"
|
12
|
+
CONF_FILE = ENV['AWSSSH_CONFIG_FILE'] || "aws_config_"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Connect to a Server:
|
14
|
+
desc "-s SERVER [-a ACCOUNT]", "connect to a server"
|
15
|
+
option :server, :aliases => '-s', :desc => "(required) The server name to connect with"
|
16
|
+
option :account, :aliases => '-a', :desc => "Specify a account for a connection. Needet if the account don't came from the server name"
|
17
|
+
option :list, :aliases => '-l', :desc => "List any items use with -s for Servers or -a ACCOUNT for accounts", :type => :boolean
|
18
|
+
option :check, :aliases => '-c', :desc => "Alerts when -c STATE comes up for -s SERVER"
|
19
|
+
long_desc <<-LONGDESC
|
20
|
+
# Connect to a Server:
|
22
21
|
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
> $ awsssh -s SERVER
|
24
|
+
\x5 This will connect you to a Server. This will work only if the first part of the server name is the same as the account name.
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
> $ awsssh -s SERVER -a ACCOUNT
|
27
|
+
\x5 With -a you can spezify a account to connect with. The server name don't play any role.
|
29
28
|
|
30
|
-
|
29
|
+
# List all Account:
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
> $ awsssh -l -a
|
32
|
+
\x5 This will list all Accounts
|
34
33
|
|
35
|
-
|
34
|
+
# List all Servers for a Account
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
> $ awsssh -l -a ACCOUNT
|
37
|
+
\x5 List all Servers vor Account ACCOUNT
|
39
38
|
|
40
|
-
|
39
|
+
# Check Server Status
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
help "connect"
|
41
|
+
LONGDESC
|
42
|
+
def connect
|
43
|
+
if options[:list] && options[:account]
|
44
|
+
list_accounts
|
45
|
+
elsif options[:list] && options[:server]
|
46
|
+
list_servers(options[:server])
|
47
|
+
elsif options[:server]
|
48
|
+
connecting(options[:server], options[:account])
|
49
|
+
else
|
50
|
+
help "connect"
|
51
|
+
end
|
54
52
|
end
|
55
|
-
end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
def help(*args)
|
55
|
+
super("connect")
|
56
|
+
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
58
|
+
private
|
59
|
+
|
60
|
+
##
|
61
|
+
# List stacks for a account
|
62
|
+
#
|
63
|
+
# * *Args* :
|
64
|
+
# - +account+ -> Account name
|
65
|
+
#
|
66
|
+
# * *Returns* :
|
67
|
+
# - [Array] StackIDs
|
68
|
+
def list_stacks(account)
|
69
|
+
ow = awscfg(account)
|
70
|
+
stacks = ow.client.describe_stacks[:stacks]
|
71
|
+
stack_ids = []
|
72
|
+
stacks.each do |stack|
|
73
|
+
stack_ids << stack[:stack_id]
|
74
|
+
end
|
75
|
+
return stack_ids
|
76
76
|
end
|
77
|
-
return stack_ids
|
78
|
-
end
|
79
77
|
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
79
|
+
##
|
80
|
+
# Read Stack
|
81
|
+
#
|
82
|
+
# * *Args* :
|
83
|
+
# - +stackid+ -> Stack ID
|
84
|
+
# - +account+ -> Account name
|
85
|
+
#
|
86
|
+
# * *Returns* :
|
87
|
+
# - Stecks JSON
|
88
|
+
#
|
89
|
+
def read_stack(stackid, account)
|
90
|
+
ow = awscfg(account)
|
91
|
+
ow.client.describe_instances({:stack_id => stackid})
|
92
|
+
# JSON.parse(`aws opsworks describe-instances --stack-id #{stackid}`)
|
93
|
+
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
95
|
+
##
|
96
|
+
# Lists all AWS Accounts
|
97
|
+
#
|
98
|
+
# * *Returns* :
|
99
|
+
# - [String]
|
100
|
+
# This are the known AWS Accounts:
|
101
|
+
# - account
|
102
|
+
def list_accounts
|
103
|
+
length = 30
|
104
|
+
puts "This are the known AWS Accounts:"
|
105
|
+
config_files = Dir.entries(CONFIG_DIR)
|
106
|
+
config_files.each do |file|
|
107
|
+
if file[0,CONF_FILE.length] == CONF_FILE
|
108
|
+
file_part = file.split("_")
|
109
|
+
unless file_part.last.nil?
|
110
|
+
printf "\t- %-#{length}s\n", file_part[2]
|
111
|
+
end
|
113
112
|
end
|
114
113
|
end
|
115
114
|
end
|
116
|
-
end
|
117
115
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
116
|
+
##
|
117
|
+
# Server Name
|
118
|
+
#
|
119
|
+
# * *Args* :
|
120
|
+
# - +stack+ -> Stack as JSON
|
121
|
+
#
|
122
|
+
# * *Returns* :
|
123
|
+
# - [String]
|
124
|
+
# - <servername> (<status>)
|
125
|
+
def server_name(stack)
|
126
|
+
stack[:instances].each do |instance|
|
127
|
+
host = build_hostname(instance)
|
128
|
+
printf "\t- %-20s %s \t %-15s \t %s\n", instance[:hostname], instance[:status], host[:ip], host[:hostname]
|
129
|
+
end
|
130
130
|
end
|
131
|
-
end
|
132
131
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
132
|
+
##
|
133
|
+
# List all Servers for a given AWS Account
|
134
|
+
#
|
135
|
+
# * *Args* :
|
136
|
+
# - +account+ -> AWS Account name
|
137
|
+
#
|
138
|
+
def list_servers(account)
|
139
|
+
stacks = list_stacks account
|
140
|
+
stacks.each do |stack_id|
|
141
|
+
stack = read_stack stack_id, account
|
142
|
+
server_name stack
|
143
|
+
end
|
144
144
|
end
|
145
|
-
end
|
146
145
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
146
|
+
##
|
147
|
+
# Establish the connection
|
148
|
+
#
|
149
|
+
# * *Args* :
|
150
|
+
# - +server+ -> Server name
|
151
|
+
#
|
152
|
+
def connecting(server, account=nil)
|
153
|
+
public_dns = nil
|
154
|
+
host = server.split("-")
|
155
|
+
ac = account || host[0]
|
156
|
+
stack_ids = list_stacks ac
|
157
|
+
stack_ids.each do |stack_id|
|
158
|
+
stack = read_stack(stack_id, ac)
|
159
|
+
stack.instances.each do |i|
|
160
|
+
if i[:hostname] == server
|
161
|
+
public_dns = build_hostname(i)[:hostname]
|
162
|
+
break
|
163
|
+
end
|
164
164
|
end
|
165
|
+
break unless public_dns.nil?
|
165
166
|
end
|
166
|
-
break unless public_dns.nil?
|
167
|
-
end
|
168
167
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
168
|
+
if public_dns.nil?
|
169
|
+
puts "Server '#{server}' not found. Try ssh"
|
170
|
+
exec "ssh #{server}"
|
171
|
+
exit -1
|
172
|
+
end
|
174
173
|
|
175
|
-
|
176
|
-
|
174
|
+
puts "Connecting to #{server} (#{public_dns})"
|
175
|
+
exec "ssh #{public_dns}"
|
177
176
|
|
178
|
-
|
177
|
+
end
|
179
178
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
179
|
+
def build_hostname(instance)
|
180
|
+
host = {}
|
181
|
+
if instance[:status] != 'online'
|
182
|
+
host[:ip] = host[:hostname] = nil
|
183
|
+
return host
|
184
|
+
end
|
185
|
+
az = (instance[:availability_zone][-1].match(/[a-z]/)) ?
|
186
|
+
instance[:availability_zone][0..-2] :
|
187
|
+
instance[:availability_zone]
|
188
|
+
host[:ip] = instance[:public_ip] || instance[:elastic_ip]
|
189
|
+
host[:hostname] = "ec2-#{host[:ip].gsub("\.", "\-")}.#{az}.compute.amazonaws.com"
|
190
|
+
host
|
191
191
|
end
|
192
|
-
|
193
|
-
|
192
|
+
|
193
|
+
def awscfg(account)
|
194
|
+
if cnf = IniFile.load(CONFIG_DIR + CONF_FILE + account)
|
195
|
+
cnf = cnf['default']
|
196
|
+
return AWS::OpsWorks.new(
|
197
|
+
access_key_id: cnf['aws_access_key_id'],
|
198
|
+
secret_access_key: cnf['aws_secret_access_key'],
|
199
|
+
region: cnf['region']
|
200
|
+
)
|
201
|
+
else
|
202
|
+
puts "No config #{CONF_FILE}#{account} found. Maybe use -a to specify a account."
|
203
|
+
exit -1
|
204
|
+
end
|
205
|
+
end
|
206
|
+
default_task :connect
|
207
|
+
end
|
194
208
|
end
|
data/spec/awsssh_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "awsssh"
|
2
|
+
describe Awsssh::Awsssh do
|
3
|
+
def runner(options = {})
|
4
|
+
@runner ||= Awsssh::Awsssh.new([1], options, :destination_root => destination_root)
|
5
|
+
end
|
6
|
+
|
7
|
+
def action(*args, &block)
|
8
|
+
capture(:stdout) { runner.send(*args, &block) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "on list stacks" do
|
12
|
+
it "lists all stacks" do
|
13
|
+
base = Awsssh::Awsssh.new ["-s"]
|
14
|
+
base.send(:list_stacks, 'trox').class.should eq [].class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awsssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Thiele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.6'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: net-ssh
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,10 +131,15 @@ extensions: []
|
|
75
131
|
extra_rdoc_files: []
|
76
132
|
files:
|
77
133
|
- ".gitignore"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
78
136
|
- README.md
|
137
|
+
- Rakefile
|
79
138
|
- awsssh.gemspec
|
80
139
|
- bin/awsssh
|
81
140
|
- lib/awsssh.rb
|
141
|
+
- lib/awsssh/version.rb
|
142
|
+
- spec/awsssh_spec.rb
|
82
143
|
homepage: https://github.com/sethiele/awsssh
|
83
144
|
licenses:
|
84
145
|
- MIT
|
@@ -99,8 +160,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
160
|
version: '0'
|
100
161
|
requirements: []
|
101
162
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.2.2
|
103
164
|
signing_key:
|
104
165
|
specification_version: 4
|
105
166
|
summary: Connects you with OpsWorks EC2
|
106
|
-
test_files:
|
167
|
+
test_files:
|
168
|
+
- spec/awsssh_spec.rb
|