ec2-blackout 0.0.5 → 0.0.6
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.
- data/README.md +6 -1
- data/lib/ec2-blackout/startup.rb +18 -5
- data/lib/ec2-blackout/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -10,6 +10,9 @@ If you don't, `ec2-blackout` could save you money
|
|
10
10
|
|
11
11
|
Use ec2-blackout to shutdown EC2 instances when they are idle, for example when you are not in the office.
|
12
12
|
|
13
|
+
If an instance has an Elastic IP address, `ec2-blackout` will reassociate the EIP when the instance is started.
|
14
|
+
Note: When an instance with an EIP is stopped AWS will automatically disassociate the EIP. AWS charge a small hourly fee for an unattached EIP.
|
15
|
+
|
13
16
|
Certinaly not suitable for production instances but development and test instances can generally be shutdown overnight to save money.
|
14
17
|
|
15
18
|
## Installation
|
@@ -30,7 +33,9 @@ It is recommended you create an access policy using Amazon IAM
|
|
30
33
|
"ec2:CreateTags",
|
31
34
|
"ec2:DeleteTags",
|
32
35
|
"ec2:DescribeInstances",
|
33
|
-
"ec2:DescribeRegions"
|
36
|
+
"ec2:DescribeRegions",
|
37
|
+
"ec2:DescribeAddresses",
|
38
|
+
"ec2:AssociateAddress"
|
34
39
|
],
|
35
40
|
"Effect": "Allow",
|
36
41
|
"Resource": "\*"
|
data/lib/ec2-blackout/startup.rb
CHANGED
@@ -11,14 +11,11 @@ class Ec2::Blackout::Startup
|
|
11
11
|
AWS.memoize do
|
12
12
|
@aws.regions[region].instances.each do |instance|
|
13
13
|
if startable? instance
|
14
|
-
@ui.say "-> Starting instance: #{instance.id}, name: #{instance.tags['Name']}"
|
14
|
+
@ui.say "-> Starting instance: #{instance.id}, name: #{instance.tags['Name']}."
|
15
15
|
unless dry_run?
|
16
16
|
instance.tags.delete('ec2:blackout:on')
|
17
17
|
instance.start
|
18
|
-
|
19
|
-
instance.associate_elastic_ip(instance.tags['ec2:blackout:eip']) rescue nil
|
20
|
-
instance.tags.delete('ec2:blackout:eip')
|
21
|
-
end
|
18
|
+
associate_eip(instance)
|
22
19
|
end
|
23
20
|
elsif instance.status == :stopped
|
24
21
|
@ui.say "-> Skipping instance: #{instance.id}, name: #{instance.tags['Name'] || 'N/A'}"
|
@@ -43,4 +40,20 @@ class Ec2::Blackout::Startup
|
|
43
40
|
def dry_run?
|
44
41
|
@options[:dry_run]
|
45
42
|
end
|
43
|
+
|
44
|
+
def associate_eip instance
|
45
|
+
eip = instance.tags['ec2:blackout:eip']
|
46
|
+
if eip
|
47
|
+
@ui.say("Associating Elastic IP #{eip} to #{instance.id}")
|
48
|
+
attempts = 0
|
49
|
+
begin
|
50
|
+
instance.associate_elastic_ip(eip)
|
51
|
+
rescue
|
52
|
+
sleep 5
|
53
|
+
attempts += 1
|
54
|
+
retry if attempts < 60 # 5 mins
|
55
|
+
end
|
56
|
+
instance.tags.delete('ec2:blackout:eip')
|
57
|
+
end
|
58
|
+
end
|
46
59
|
end
|
data/lib/ec2-blackout/version.rb
CHANGED