Class: Ec2::Blackout::Ec2Instance
- Inherits:
-
Object
- Object
- Ec2::Blackout::Ec2Instance
- Defined in:
- lib/ec2-blackout/ec2_instance.rb
Constant Summary collapse
- TIMESTAMP_TAG_NAME =
'ec2:blackout:on'
- EIP_TAG_NAME =
'ec2:blackout:eip'
Instance Attribute Summary collapse
-
#eip_retry_delay_seconds ⇒ Object
Returns the value of attribute eip_retry_delay_seconds.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(instance, options) ⇒ Ec2Instance
constructor
A new instance of Ec2Instance.
- #start ⇒ Object
- #startable? ⇒ Boolean
- #stop ⇒ Object
- #stoppable? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(instance, options) ⇒ Ec2Instance
Returns a new instance of Ec2Instance.
19 20 21 22 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 19 def initialize(instance, ) @instance, @options = instance, @eip_retry_delay_seconds = 5 end |
Instance Attribute Details
#eip_retry_delay_seconds ⇒ Object
Returns the value of attribute eip_retry_delay_seconds.
17 18 19 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 17 def eip_retry_delay_seconds @eip_retry_delay_seconds end |
Class Method Details
.running_instances(region, options) ⇒ Object
8 9 10 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 8 def self.running_instances(region, ) instances(region, , 'running') end |
.stopped_instances(region, options) ⇒ Object
12 13 14 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 12 def self.stopped_instances(region, ) instances(region, , 'stopped') end |
Instance Method Details
#start ⇒ Object
29 30 31 32 33 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 29 def start @instance.start associate_eip untag end |
#startable? ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 51 def startable? if @instance.status != :stopped [false, "instance is not in stopped state"] elsif @options.force true elsif ![TIMESTAMP_TAG_NAME] [false, "instance was not originally stopped by ec2-blackout"] elsif @options.() [false, "matches exclude tags"] elsif !@options.() [false, "does not match include tags"] else true end end |
#stop ⇒ Object
24 25 26 27 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 24 def stop tag @instance.stop end |
#stoppable? ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 35 def stoppable? if ['aws:autoscaling:groupName'] [false, "instance is part of an autoscaling group"] elsif @instance.status != :running [false, "instance is not in running state"] elsif @options.() [false, "matches exclude tags"] elsif !@options.() [false, "does not match include tags"] elsif @instance.root_device_type != :ebs [false, "is not ebs root device"] else true end end |
#to_s ⇒ Object
67 68 69 70 71 |
# File 'lib/ec2-blackout/ec2_instance.rb', line 67 def to_s s = "instance #{@instance.id}" s += " (#{['Name']})" if ['Name'] s end |