opsicle 0.11.0 → 0.12.0
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 +4 -4
- data/lib/opsicle/commands/list_instances.rb +7 -13
- data/lib/opsicle/commands/ssh.rb +10 -1
- data/lib/opsicle/instances.rb +4 -0
- data/lib/opsicle/monitor/panels/deployments.rb +4 -2
- data/lib/opsicle/monitor/spy/deployments.rb +1 -0
- data/lib/opsicle/monitor/spy/instances.rb +2 -1
- data/lib/opsicle/monitor/translatable.rb +1 -0
- data/lib/opsicle/stack.rb +8 -0
- data/lib/opsicle/version.rb +1 -1
- data/spec/opsicle/commands/list_instances_spec.rb +0 -1
- data/spec/opsicle/commands/ssh_spec.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 382eb43575e7839130f2b9aeb764eb073f00eb55
|
4
|
+
data.tar.gz: d2daa070bd8e667242c07655c9c9fe2f615a1a6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e3f9d74f4a3e204639c113564faae10f2714f7347a348044de701da4573fb76a915097ea482cc0c81d7b6d9d71365705b0ad11a10e8d16a1f52b10d43a970b4
|
7
|
+
data.tar.gz: eaf95944a7eaa244811546b382e5c1b05ed4cdd9522290e93f353173ad2adf97727dcf46db1c7a7c396e7da154189e39cec13387720c7e39eface42f2e0c57fb
|
@@ -2,39 +2,33 @@ require 'terminal-table'
|
|
2
2
|
|
3
3
|
module Opsicle
|
4
4
|
class ListInstances
|
5
|
-
attr_reader :client
|
5
|
+
attr_reader :client
|
6
6
|
|
7
7
|
def initialize(environment)
|
8
8
|
@client = Client.new(environment)
|
9
|
+
@stack = Stack.new(@client)
|
9
10
|
end
|
10
11
|
|
11
12
|
def execute(options={})
|
12
|
-
get_layers
|
13
13
|
print(get_instances)
|
14
14
|
end
|
15
15
|
|
16
|
-
def get_layers
|
17
|
-
@layers = client.api_call('describe_layers', stack_id: @client.config.opsworks_config[:stack_id])[:layers]
|
18
|
-
end
|
19
|
-
|
20
16
|
def get_instances
|
21
17
|
Opsicle::Instances.new(client).data
|
22
18
|
end
|
23
19
|
|
24
20
|
def print(instances)
|
25
|
-
puts Terminal::Table.new headings: ['Hostname', 'Layers', 'Status', 'Instance ID'], rows: instance_data(instances)
|
21
|
+
puts Terminal::Table.new headings: ['Hostname', 'Layers', 'Status', 'IP', 'Instance ID'], rows: instance_data(instances)
|
26
22
|
end
|
27
23
|
|
28
24
|
def instance_data(instances)
|
29
|
-
instances.
|
25
|
+
instances.sort { |a,b| a[:hostname] <=> b[:hostname] }.map { |instance|
|
26
|
+
[instance[:hostname], layer_names(instance), instance[:status], Opsicle::Instances::pretty_ip(instance), instance[:instance_id]]
|
27
|
+
}
|
30
28
|
end
|
31
29
|
|
32
30
|
def layer_names(instance)
|
33
|
-
instance[:layer_ids].map{ |layer_id| layer_name(layer_id) }.join(" | ")
|
34
|
-
end
|
35
|
-
|
36
|
-
def layer_name(layer_id)
|
37
|
-
layers.detect{ |layer| layer[:layer_id] == layer_id }[:name]
|
31
|
+
instance[:layer_ids].map{ |layer_id| @stack.layer_name(layer_id) }.join(" | ")
|
38
32
|
end
|
39
33
|
|
40
34
|
end
|
data/lib/opsicle/commands/ssh.rb
CHANGED
@@ -4,6 +4,7 @@ module Opsicle
|
|
4
4
|
|
5
5
|
def initialize(environment)
|
6
6
|
@client = Client.new(environment)
|
7
|
+
@stack = Opsicle::Stack.new(@client)
|
7
8
|
end
|
8
9
|
|
9
10
|
def execute(options={})
|
@@ -13,7 +14,7 @@ module Opsicle
|
|
13
14
|
else
|
14
15
|
Output.say "Choose an Opsworks instance:"
|
15
16
|
instances.each_with_index do |instance, index|
|
16
|
-
Output.say "#{index+1}) #{instance[:hostname]}"
|
17
|
+
Output.say "#{index+1}) #{instance[:hostname]} #{instance_info(instance)}"
|
17
18
|
end
|
18
19
|
choice = Output.ask("? ", Integer) { |q| q.in = 1..instances.length }
|
19
20
|
end
|
@@ -28,6 +29,7 @@ module Opsicle
|
|
28
29
|
@instances ||= client.api_call(:describe_instances, { stack_id: client.config.opsworks_config[:stack_id] })
|
29
30
|
.data[:instances]
|
30
31
|
.select { |instance| instance[:status].to_s == 'online'}
|
32
|
+
.sort { |a,b| a[:hostname] <=> b[:hostname] }
|
31
33
|
end
|
32
34
|
|
33
35
|
def public_ips
|
@@ -51,5 +53,12 @@ module Opsicle
|
|
51
53
|
"ssh #{ssh_options}#{ssh_string}#{ssh_command}"
|
52
54
|
end
|
53
55
|
|
56
|
+
def instance_info(instance)
|
57
|
+
infos = []
|
58
|
+
infos << instance[:layer_ids].map{ |layer_id| @stack.layer_name(layer_id) } if instance[:layer_ids]
|
59
|
+
infos << "EIP" if instance[:elastic_ip]
|
60
|
+
"(#{infos.join(', ')})"
|
61
|
+
end
|
62
|
+
|
54
63
|
end
|
55
64
|
end
|
data/lib/opsicle/instances.rb
CHANGED
@@ -14,6 +14,10 @@ module Opsicle
|
|
14
14
|
instances(reload: true)
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.pretty_ip(instance)
|
18
|
+
instance[:elastic_ip] ? "#{instance[:elastic_ip]} EIP" : instance[:public_ip]
|
19
|
+
end
|
20
|
+
|
17
21
|
def self.find_by_ip(client, ips)
|
18
22
|
instances = new(client).data.reject { |instance| instances_matching_ips(instance, ips) }
|
19
23
|
instances.empty? ? nil : instances
|
@@ -19,7 +19,8 @@ module Opsicle
|
|
19
19
|
[1, translate[:heading][:created_at], nil],
|
20
20
|
[1, translate[:heading][:completed_at], nil],
|
21
21
|
[1, translate[:heading][:user], nil],
|
22
|
-
[1, translate[:heading][:command], nil]
|
22
|
+
[1, translate[:heading][:command], nil],
|
23
|
+
[3, translate[:heading][:command_args], nil]
|
23
24
|
],
|
24
25
|
]
|
25
26
|
|
@@ -29,7 +30,8 @@ module Opsicle
|
|
29
30
|
[1, -> { @spies[:deployments][i][:created_at] }, nil],
|
30
31
|
[1, -> { @spies[:deployments][i][:completed_at] }, nil],
|
31
32
|
[1, -> { @spies[:deployments][i][:user] }, nil],
|
32
|
-
[1, -> { @spies[:deployments][i][:command] }, nil]
|
33
|
+
[1, -> { @spies[:deployments][i][:command] }, nil],
|
34
|
+
[3, -> { @spies[:deployments][i][:command_args] }, nil]
|
33
35
|
]
|
34
36
|
end
|
35
37
|
|
@@ -27,6 +27,7 @@ module Opsicle
|
|
27
27
|
:user => user_from_arn(deployment[:iam_user_arn]),
|
28
28
|
:comment => deployment[:comment],
|
29
29
|
:command => deployment[:command][:name],
|
30
|
+
:command_args => deployment[:command][:args],
|
30
31
|
:name => deployment[:name],
|
31
32
|
:args => deployment[:args],
|
32
33
|
:value => deployment[:value],
|
@@ -22,10 +22,11 @@ module Opsicle
|
|
22
22
|
:hostname => instance[:hostname],
|
23
23
|
:status => instance[:status],
|
24
24
|
:zone => instance[:availability_zone],
|
25
|
-
:ip => instance
|
25
|
+
:ip => Opsicle::Instances::pretty_ip(instance)
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
29
|
+
h.sort! { |a,b| a[:hostname] <=> b[:hostname] }
|
29
30
|
@data = h
|
30
31
|
end
|
31
32
|
|
data/lib/opsicle/stack.rb
CHANGED
@@ -18,5 +18,13 @@ module Opsicle
|
|
18
18
|
stack_summary[:name]
|
19
19
|
end
|
20
20
|
|
21
|
+
def layers
|
22
|
+
@layers ||= @client.api_call('describe_layers', stack_id: @client.config.opsworks_config[:stack_id])[:layers]
|
23
|
+
end
|
24
|
+
|
25
|
+
def layer_name(layer_id)
|
26
|
+
layers.detect{ |layer| layer[:layer_id] == layer_id }[:name]
|
27
|
+
end
|
28
|
+
|
21
29
|
end
|
22
30
|
end
|
data/lib/opsicle/version.rb
CHANGED
@@ -17,7 +17,6 @@ module Opsicle
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "shows a table with all of the instances for the stack from OpsWorks" do
|
20
|
-
expect(subject).to receive(:get_layers).and_return(layers)
|
21
20
|
expect(subject).to receive(:get_instances).and_return(instances)
|
22
21
|
expect(subject).to receive(:print).with(instances)
|
23
22
|
subject.execute
|
@@ -5,9 +5,11 @@ module Opsicle
|
|
5
5
|
describe SSH do
|
6
6
|
subject { SSH.new('derp') }
|
7
7
|
let(:client) { double(config: double(opsworks_config: {stack_id: "1234"})) }
|
8
|
+
let(:stack) { double(client: client) }
|
8
9
|
let(:api_call) { double }
|
9
10
|
before do
|
10
11
|
allow(Client).to receive(:new).with('derp').and_return(client)
|
12
|
+
allow(Stack).to receive(:new).with(client).and_return(stack)
|
11
13
|
end
|
12
14
|
|
13
15
|
context "#execute" do
|
@@ -92,6 +94,12 @@ module Opsicle
|
|
92
94
|
expect(api_call).to receive(:data).and_return(instances: [{:name => :foo, :status => "online"},{:name => :bar, :status => "stopped"}])
|
93
95
|
expect(subject.instances).to eq([{:name => :foo, :status=>"online"}])
|
94
96
|
end
|
97
|
+
it "sorts instances by hostname" do
|
98
|
+
expect(client).to receive(:api_call).with(:describe_instances, {stack_id: "1234"})
|
99
|
+
.and_return(api_call)
|
100
|
+
expect(api_call).to receive(:data).and_return(instances: [{:hostname => "taco", :status => "online"},{:hostname => "bar", :status => "online"}])
|
101
|
+
expect(subject.instances).to eq([{:hostname => "bar", :status=>"online"}, {:hostname => "taco", :status=>"online"}])
|
102
|
+
end
|
95
103
|
end
|
96
104
|
|
97
105
|
context "#ssh_username" do
|
@@ -134,5 +142,32 @@ module Opsicle
|
|
134
142
|
expect(subject.ssh_command({private_ip: "789.789.789.789"}, { :"ssh-opts" => "-c"} )).to eq("ssh -c -A -t mrderpyman2014@123.123.123.123 ssh 789.789.789.789")
|
135
143
|
end
|
136
144
|
end
|
145
|
+
|
146
|
+
context "#instance_info" do
|
147
|
+
before do
|
148
|
+
allow(stack).to receive(:layer_name).with("1").and_return("one")
|
149
|
+
allow(stack).to receive(:layer_name).with("2").and_return("two")
|
150
|
+
allow(subject).to receive(:instances) {[
|
151
|
+
{ hostname: "host1", public_ip: "123.123.123.123", layer_ids: [1] },
|
152
|
+
{ hostname: "host2", private_ip: "789.789.789.789", layer_ids: [1,2] },
|
153
|
+
{ hostname: "host3", private_ip: "789.789.789.789", layer_ids: nil }
|
154
|
+
]}
|
155
|
+
it "should handle no layers or EIP" do
|
156
|
+
expect(subject.instance_info({})).to eq("()")
|
157
|
+
end
|
158
|
+
it "should list a layer" do
|
159
|
+
expect(subject.instance_info(layer_ids: [1])).to eq("(one)")
|
160
|
+
end
|
161
|
+
it "should list layers" do
|
162
|
+
expect(subject.instance_info(layer_ids: [1, 2])).to eq("(one, two)")
|
163
|
+
end
|
164
|
+
it "should list a EIP" do
|
165
|
+
expect(subject.instance_info(elastic_ip: "1.1.1.1")).to eq("(EIP)")
|
166
|
+
end
|
167
|
+
it "should list all info" do
|
168
|
+
expect(subject.instance_info(layer_ids: [1], elastic_ip: "1.1.1.1")).to eq("(one, EIP)")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
137
172
|
end
|
138
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opsicle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Fleener
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|