ec2-blackout 0.0.7 → 0.0.8

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.
@@ -41,6 +41,8 @@ class Ec2::Blackout::Ec2Instance
41
41
  [false, "matches exclude tags"]
42
42
  elsif !@options.matches_include_tags?(tags)
43
43
  [false, "does not match include tags"]
44
+ elsif @instance.root_device_type != :ebs
45
+ [false, "is not ebs root device"]
44
46
  else
45
47
  true
46
48
  end
@@ -77,7 +79,11 @@ class Ec2::Blackout::Ec2Instance
77
79
  def tag
78
80
  @instance.add_tag(TIMESTAMP_TAG_NAME, :value => Time.now.utc)
79
81
  if @instance.has_elastic_ip?
80
- @instance.add_tag(EIP_TAG_NAME, :value => @instance.elastic_ip.allocation_id)
82
+ if @instance.elastic_ip.vpc?
83
+ @instance.add_tag(EIP_TAG_NAME, :value => @instance.elastic_ip.allocation_id)
84
+ else
85
+ @instance.add_tag(EIP_TAG_NAME, :value => @instance.elastic_ip.public_ip)
86
+ end
81
87
  end
82
88
  end
83
89
 
@@ -7,7 +7,7 @@ class Ec2::Blackout::Shutdown
7
7
  end
8
8
 
9
9
  def execute
10
- @ui.say 'Dry run specified - no instances will be stopped'.bold
10
+ @ui.say 'Dry run specified - no instances will be stopped'.bold if @options.dry_run
11
11
  @ui.say "Stopping instances"
12
12
  @options.regions.each do |region|
13
13
  @ui.say "Checking region #{region}"
@@ -7,7 +7,7 @@ class Ec2::Blackout::Startup
7
7
  end
8
8
 
9
9
  def execute
10
- @ui.say 'Dry run specified - no instances will be started'.bold
10
+ @ui.say 'Dry run specified - no instances will be started'.bold if @options.dry_run
11
11
  @ui.say "Starting instances"
12
12
  @options.regions.each do |region|
13
13
  @ui.say "Checking region #{region}"
@@ -1,6 +1,6 @@
1
1
  module Ec2
2
2
  module Blackout
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
 
5
5
  def self.name
6
6
  'ec2-blackout'
@@ -36,12 +36,38 @@ module Ec2::Blackout
36
36
  instance.stop
37
37
  end
38
38
 
39
- it "saves the associated elastic IP as a tag" do
40
- aws_instance.stub(:has_elastic_ip?).and_return(true)
41
- eip = double(:allocation_id => "eipalloc-eab23c0d")
42
- aws_instance.stub(:elastic_ip).and_return(eip)
43
- aws_instance.should_receive(:add_tag).with(Ec2Instance::EIP_TAG_NAME, :value => "eipalloc-eab23c0d")
44
- instance.stop
39
+ context 'when the instance has an Elastic IP' do
40
+ let(:eip) { double(:eip) }
41
+
42
+ before do
43
+ aws_instance.stub(:has_elastic_ip?).and_return(true)
44
+ aws_instance.stub(:elastic_ip).and_return(eip)
45
+ end
46
+
47
+ context 'and it is running in a VPC' do
48
+
49
+ before do
50
+ eip.stub(:vpc?).and_return(true)
51
+ end
52
+
53
+ it "saves the associated elastic IP as a tag" do
54
+ eip.should_receive(:allocation_id).and_return("eipalloc-eab23c0d")
55
+ aws_instance.should_receive(:add_tag).with(Ec2Instance::EIP_TAG_NAME, :value => "eipalloc-eab23c0d")
56
+ instance.stop
57
+ end
58
+ end
59
+
60
+ context 'and it is running in EC2 classic' do
61
+ before do
62
+ eip.stub(:vpc?).and_return(false)
63
+ end
64
+
65
+ it "saves the elastic public IP as a tag" do
66
+ eip.should_receive(:public_ip).and_return("public-ip")
67
+ aws_instance.should_receive(:add_tag).with(Ec2Instance::EIP_TAG_NAME, :value => "public-ip")
68
+ instance.stop
69
+ end
70
+ end
45
71
  end
46
72
 
47
73
  end
@@ -116,6 +142,12 @@ module Ec2::Blackout
116
142
  stoppable, reason = instance.stoppable?
117
143
  expect(stoppable).to be_false
118
144
  end
145
+
146
+ it "returns false if the instance volume type is not EBS" do
147
+ aws_instance.stub(:root_device_type).and_return('not_ebs')
148
+ stoppable, reason = instance.stoppable?
149
+ expect(stoppable).to be_false
150
+ end
119
151
  end
120
152
 
121
153
  describe "#startable?" do
@@ -149,6 +181,7 @@ module Ec2::Blackout
149
181
  underlying_aws_stub.stub(:tags).and_return(ec2_tags({}))
150
182
  underlying_aws_stub.stub(:add_tag)
151
183
  underlying_aws_stub.stub(:stop)
184
+ underlying_aws_stub.stub(:root_device_type).and_return(:ebs)
152
185
  Ec2Instance.new(underlying_aws_stub, options)
153
186
  end
154
187
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2-blackout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-17 00:00:00.000000000 Z
13
+ date: 2014-03-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: commander