opsicle 2.12.3 → 2.12.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/opsicle/commands/delete_instance.rb +10 -0
- data/lib/opsicle/commands/stop_instance.rb +10 -0
- data/lib/opsicle/ec2_adapter.rb +2 -2
- data/lib/opsicle/manageable_instance.rb +0 -1
- data/lib/opsicle/questionnaire/eip_inquiry.rb +13 -1
- data/lib/opsicle/version.rb +1 -1
- data/spec/opsicle/commands/delete_instance_spec.rb +90 -71
- data/spec/opsicle/commands/stop_instance_spec.rb +100 -0
- data/spec/opsicle/questionnaire/eip_inquiry_spec.rb +50 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0d4b66a5b078018b67348b894fe8274491719348c5d24d3672ddaebdbd667d2e
|
4
|
+
data.tar.gz: c6928a8a60d29c02924287bba794a3c0f75767916610020d905119d8abb4b65e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71647e38b87fa0077864cc3f255e2edf1ee9c9be3a0a59f59d66bd2d1c7e3169d76a7a0f2c43a17836b8de6278ef554144fd8067c10d446d30e84835ac15a493
|
7
|
+
data.tar.gz: 5229246562d67aa4405589eb00fedecb72e0f94c3bf8274bc8bbd45e9e1e7190a812aa7c1765f2aebff6c81c53e20a740abdd077cfc27faf75cb0b700d572c9e
|
@@ -60,6 +60,7 @@ module Opsicle
|
|
60
60
|
instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
|
61
61
|
instance_indices_string = @cli.ask("Which instances would you like to delete? (enter as a comma separated list)\n", String)
|
62
62
|
instance_indices_list = instance_indices_string.split(/,\s*/)
|
63
|
+
check_for_valid_indices!(instance_indices_list, instances.count)
|
63
64
|
instance_indices_list.map! { |instance_index| instance_index.to_i - 1 }
|
64
65
|
instance_indices_list.each do |index|
|
65
66
|
return_array << instances[index]
|
@@ -67,5 +68,14 @@ module Opsicle
|
|
67
68
|
end
|
68
69
|
return_array
|
69
70
|
end
|
71
|
+
|
72
|
+
def check_for_valid_indices!(instance_indices_list, option_count)
|
73
|
+
valid_indices = 1..option_count
|
74
|
+
|
75
|
+
unless instance_indices_list.all?{ |i| valid_indices.include?(i.to_i) }
|
76
|
+
raise StandardError, "At least one of the indices passed is invalid. Please try again."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
private :check_for_valid_indices!
|
70
80
|
end
|
71
81
|
end
|
@@ -60,6 +60,7 @@ module Opsicle
|
|
60
60
|
instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
|
61
61
|
instance_indices_string = @cli.ask("Which instances would you like to stop? (enter as a comma separated list)\n", String)
|
62
62
|
instance_indices_list = instance_indices_string.split(/,\s*/)
|
63
|
+
check_for_valid_indices!(instance_indices_list, instances.count)
|
63
64
|
instance_indices_list.map! { |instance_index| instance_index.to_i - 1 }
|
64
65
|
instance_indices_list.each do |index|
|
65
66
|
return_array << instances[index]
|
@@ -67,5 +68,14 @@ module Opsicle
|
|
67
68
|
end
|
68
69
|
return_array
|
69
70
|
end
|
71
|
+
|
72
|
+
def check_for_valid_indices!(instance_indices_list, option_count)
|
73
|
+
valid_indices = 1..option_count
|
74
|
+
|
75
|
+
unless instance_indices_list.all?{ |i| valid_indices.include?(i.to_i) }
|
76
|
+
raise StandardError, "At least one of the indices passed is invalid. Please try again."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
private :check_for_valid_indices!
|
70
80
|
end
|
71
81
|
end
|
data/lib/opsicle/ec2_adapter.rb
CHANGED
@@ -18,6 +18,7 @@ module Opsicle
|
|
18
18
|
def which_instance_should_get_eip(moveable_eip)
|
19
19
|
puts "\nHere are all of the instances in the current instance's layer:"
|
20
20
|
instances = get_potential_target_instances(moveable_eip)
|
21
|
+
check_for_printable_items!(instances)
|
21
22
|
print_potential_target_instances(instances)
|
22
23
|
instance_index = ask_eip_question("What is your target instance?\n", instances)
|
23
24
|
instances[instance_index].instance_id
|
@@ -40,9 +41,20 @@ module Opsicle
|
|
40
41
|
|
41
42
|
def get_potential_target_instances(moveable_eip)
|
42
43
|
instances = @opsworks_adapter.instances_by_layer(moveable_eip[:layer_id])
|
43
|
-
instances.select
|
44
|
+
instances.select do |instance|
|
45
|
+
instance.elastic_ip.nil? &&
|
46
|
+
instance.auto_scaling_type.nil? &&
|
47
|
+
instance.status == "online"
|
48
|
+
end
|
44
49
|
end
|
45
50
|
private :get_potential_target_instances
|
51
|
+
|
52
|
+
def check_for_printable_items!(instances)
|
53
|
+
if instances.empty? # instances is the list of instances that an eip can be moved to
|
54
|
+
raise StandardError, "You cannot move an EIP when there's only one instance running."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
private :check_for_printable_items!
|
46
58
|
end
|
47
59
|
end
|
48
60
|
end
|
data/lib/opsicle/version.rb
CHANGED
@@ -3,79 +3,98 @@ require "opsicle"
|
|
3
3
|
require 'gli'
|
4
4
|
require "opsicle/user_profile"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
6
|
+
describe Opsicle::DeleteInstance do
|
7
|
+
let(:config) { double(:config, opsworks_config: {stack_id: "1234"}) }
|
8
|
+
let(:opsicle_client) { double(:client, config: config, opsworks: opsworks_client, ec2: ec2_client) }
|
9
|
+
let(:opsworks_stack) { double(:stack, id: "1234", vpc_id: "21") }
|
10
|
+
let(:layer1) { double(:layer, name: "layer1", layer_id: "123") }
|
11
|
+
let(:layer2) { double(:layer, name: "layer2", layer_id: "456") }
|
12
|
+
|
13
|
+
let(:instance1) do
|
14
|
+
double(:instance,
|
15
|
+
name: "instance1",
|
16
|
+
layer_ids: [ "456" ],
|
17
|
+
status: "stopped",
|
18
|
+
auto_scaling_type: nil,
|
19
|
+
instance_id: "123",
|
20
|
+
hostname: "instance1"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:opsworks_client) do
|
25
|
+
double(:opsworks_client,
|
26
|
+
associate_elastic_ip: true,
|
27
|
+
describe_stacks: double(stack: [ opsworks_stack ]),
|
28
|
+
describe_instances: double(instances: [ instance1 ])
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:ec2_client) { double(:ec2_client) }
|
33
|
+
|
34
|
+
let(:opsworks_adapter) do
|
35
|
+
double(:opsworks_adapter,
|
36
|
+
client: opsworks_client,
|
37
|
+
stack: opsworks_stack,
|
38
|
+
layers: [ layer1, layer2 ],
|
39
|
+
instances_by_stack: [ instance1 ]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:ec2_adapter) do
|
44
|
+
double(:ec2_adapter,
|
45
|
+
client: ec2_client,
|
46
|
+
stack: opsworks_stack,
|
47
|
+
elastic_ips: []
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
allow(Opsicle::Client).to receive(:new).with("staging").and_return(opsicle_client)
|
53
|
+
allow(Opsicle::OpsworksAdapter).to receive(:new).and_return(opsworks_adapter)
|
54
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Layer?\n", Integer).and_return(2)
|
55
|
+
end
|
56
|
+
|
57
|
+
subject { described_class.new("staging") }
|
58
|
+
|
59
|
+
|
60
|
+
describe "#execute" do
|
61
|
+
context "when everything works as expected" do
|
62
|
+
before do
|
63
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to delete? (enter as a comma separated list)\n", String).and_return("1")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should properly ask to delete instances" do
|
67
|
+
expect(opsworks_adapter).to receive(:delete_instance).with("123")
|
68
|
+
subject.execute
|
69
|
+
end
|
63
70
|
end
|
64
71
|
|
65
|
-
|
72
|
+
context "when an improper value is passed in as something to delete" do
|
73
|
+
before do
|
74
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to delete? (enter as a comma separated list)\n", String).and_return("-1")
|
75
|
+
end
|
66
76
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
it "should properly ask to delete instances" do
|
78
|
+
expect{subject.execute}.to raise_error(StandardError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when there are no deletable instances" do
|
83
|
+
let(:instance1) do
|
84
|
+
double(:instance,
|
85
|
+
name: "instance1",
|
86
|
+
layer_ids: [ "456" ],
|
87
|
+
status: "online",
|
88
|
+
auto_scaling_type: nil,
|
89
|
+
instance_id: "123",
|
90
|
+
hostname: "instance1"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not delete any instances" do
|
95
|
+
expect(opsworks_adapter).not_to receive(:delete_instance)
|
96
|
+
subject.execute
|
97
|
+
end
|
98
|
+
end
|
80
99
|
end
|
81
100
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "opsicle"
|
3
|
+
require 'gli'
|
4
|
+
require "opsicle/user_profile"
|
5
|
+
|
6
|
+
describe Opsicle::StopInstance do
|
7
|
+
let(:config) { double(:config, opsworks_config: {stack_id: "1234"}) }
|
8
|
+
let(:opsicle_client) { double(:client, config: config, opsworks: opsworks_client, ec2: ec2_client) }
|
9
|
+
let(:opsworks_stack) { double(:stack, id: "1234", vpc_id: "21") }
|
10
|
+
let(:layer1) { double(:layer, name: "layer1", layer_id: "123") }
|
11
|
+
let(:layer2) { double(:layer, name: "layer2", layer_id: "456") }
|
12
|
+
|
13
|
+
let(:instance1) do
|
14
|
+
double(:instance,
|
15
|
+
name: "instance1",
|
16
|
+
layer_ids: [ "456" ],
|
17
|
+
status: "online",
|
18
|
+
elastic_ip: nil,
|
19
|
+
instance_id: "123",
|
20
|
+
hostname: "instance1"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:opsworks_client) do
|
25
|
+
double(:opsworks_client,
|
26
|
+
associate_elastic_ip: true,
|
27
|
+
describe_stacks: double(stack: [ opsworks_stack ]),
|
28
|
+
describe_instances: double(instances: [ instance1 ])
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:ec2_client) { double(:ec2_client) }
|
33
|
+
|
34
|
+
let(:opsworks_adapter) do
|
35
|
+
double(:opsworks_adapter,
|
36
|
+
client: opsworks_client,
|
37
|
+
stack: opsworks_stack,
|
38
|
+
layers: [ layer1, layer2 ],
|
39
|
+
instances_by_stack: [ instance1 ]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:ec2_adapter) do
|
44
|
+
double(:ec2_adapter,
|
45
|
+
client: ec2_client,
|
46
|
+
stack: opsworks_stack,
|
47
|
+
elastic_ips: []
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
allow(Opsicle::Client).to receive(:new).with("staging").and_return(opsicle_client)
|
53
|
+
allow(Opsicle::OpsworksAdapter).to receive(:new).and_return(opsworks_adapter)
|
54
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Layer?\n", Integer).and_return(2)
|
55
|
+
end
|
56
|
+
|
57
|
+
subject { described_class.new("staging") }
|
58
|
+
|
59
|
+
|
60
|
+
describe "#execute" do
|
61
|
+
context "when everything works as expected" do
|
62
|
+
before do
|
63
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to stop? (enter as a comma separated list)\n", String).and_return("1")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should properly ask to stop instances" do
|
67
|
+
expect(opsworks_adapter).to receive(:stop_instance).with("123")
|
68
|
+
subject.execute
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when an improper value is passed in as something to stop" do
|
73
|
+
before do
|
74
|
+
allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to stop? (enter as a comma separated list)\n", String).and_return("-1")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should properly ask to stop instances" do
|
78
|
+
expect{subject.execute}.to raise_error(StandardError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when there are no stoppable instances" do
|
83
|
+
let(:instance1) do
|
84
|
+
double(:instance,
|
85
|
+
name: "instance1",
|
86
|
+
layer_ids: [ "456" ],
|
87
|
+
status: "stopped",
|
88
|
+
elastic_ip: nil,
|
89
|
+
instance_id: "123",
|
90
|
+
hostname: "instance1"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not stop any instances" do
|
95
|
+
expect(opsworks_adapter).not_to receive(:stop_instance)
|
96
|
+
subject.execute
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -66,5 +66,55 @@ describe Opsicle::Questionnaire::EipInquiry do
|
|
66
66
|
it "should return a single instance" do
|
67
67
|
expect(instance_response).to eq("instance-id")
|
68
68
|
end
|
69
|
+
|
70
|
+
context "when there are no target instances" do
|
71
|
+
let(:online_instance_with_eip) do
|
72
|
+
double(:instance,
|
73
|
+
elastic_ip: true,
|
74
|
+
auto_scaling_type: nil,
|
75
|
+
status: "stopped",
|
76
|
+
hostname: "example",
|
77
|
+
instance_id: "instance-id"
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:online_instance_without_eip) do
|
82
|
+
double(:instance,
|
83
|
+
elastic_ip: nil,
|
84
|
+
auto_scaling_type: nil,
|
85
|
+
status: "stopped",
|
86
|
+
hostname: "example",
|
87
|
+
instance_id: "instance-id"
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
let(:stopped_instance) do
|
92
|
+
double(:instance,
|
93
|
+
elastic_ip: nil,
|
94
|
+
auto_scaling_type: nil,
|
95
|
+
status: "stopped",
|
96
|
+
hostname: "example",
|
97
|
+
instance_id: "instance-id"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should raise an error" do
|
102
|
+
expect{subject.which_instance_should_get_eip(eip_info)}.to raise_error(StandardError)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#check_for_printable_items" do
|
108
|
+
context "when there are instances" do
|
109
|
+
it "should not raise an error" do
|
110
|
+
expect(subject.send(:check_for_printable_items!, [ 1, 2, 3 ])).to eq(nil)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when there are no instances" do
|
115
|
+
it "should raise an error" do
|
116
|
+
expect{subject.send(:check_for_printable_items!, [])}.to raise_error(StandardError)
|
117
|
+
end
|
118
|
+
end
|
69
119
|
end
|
70
120
|
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: 2.12.
|
4
|
+
version: 2.12.5
|
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:
|
12
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- spec/opsicle/commands/move_eip_spec.rb
|
256
256
|
- spec/opsicle/commands/ssh_key_spec.rb
|
257
257
|
- spec/opsicle/commands/ssh_spec.rb
|
258
|
+
- spec/opsicle/commands/stop_instance_spec.rb
|
258
259
|
- spec/opsicle/commands/update_spec.rb
|
259
260
|
- spec/opsicle/commands/user_profile_info_spec.rb
|
260
261
|
- spec/opsicle/config_spec.rb
|
@@ -296,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
296
297
|
version: '0'
|
297
298
|
requirements: []
|
298
299
|
rubyforge_project:
|
299
|
-
rubygems_version: 2.
|
300
|
+
rubygems_version: 2.7.8
|
300
301
|
signing_key:
|
301
302
|
specification_version: 4
|
302
303
|
summary: An opsworks specific abstraction on top of the aws sdk
|
@@ -323,6 +324,7 @@ test_files:
|
|
323
324
|
- spec/opsicle/commands/list_spec.rb
|
324
325
|
- spec/opsicle/commands/ssh_key_spec.rb
|
325
326
|
- spec/opsicle/commands/update_spec.rb
|
327
|
+
- spec/opsicle/commands/stop_instance_spec.rb
|
326
328
|
- spec/opsicle/commands/failure_log_spec.rb
|
327
329
|
- spec/opsicle/commands/delete_instance_spec.rb
|
328
330
|
- spec/opsicle/commands/move_eip_spec.rb
|