opsicle 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab993b3d50de8fe63817cfdadf477b2226e7b988
4
- data.tar.gz: 627593752949a28787510fcb7808fac626fe2f22
3
+ metadata.gz: 382eb43575e7839130f2b9aeb764eb073f00eb55
4
+ data.tar.gz: d2daa070bd8e667242c07655c9c9fe2f615a1a6b
5
5
  SHA512:
6
- metadata.gz: 27dc029b0626c90206a77eb74f8e14b8a74a3b68c30d4a9d5acdfb059690354036d6fa1e7b66ffa18081f36be65f1f1ded65ddb23b4d1255b047e5a57d45f585
7
- data.tar.gz: e573205db262222309adad4b7d30f2a7a897ed302199aa09440fbb4c72b878b0353624fb6b7c5b3541751dea8495cb23a67245754650f3f41527ebfdfe476d0a
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, :layers
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.map{|instance| [instance[:hostname], layer_names(instance), instance[:status], instance[:instance_id]] }
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
@@ -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
@@ -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[:elastic_ip] || instance[:public_ip]
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
 
@@ -25,6 +25,7 @@ module Opsicle
25
25
  completed_at: "COMPLETED",
26
26
  user: "USER",
27
27
  command: "COMMAND",
28
+ command_args: "ARGS",
28
29
  hostname: "HOSTNAME",
29
30
  zone: "AZ",
30
31
  ip: "IP ADDRESS",
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
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -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.11.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-01-28 00:00:00.000000000 Z
12
+ date: 2015-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk