Class: Base2::Ec2StartStopHandler
- Inherits:
-
Object
- Object
- Base2::Ec2StartStopHandler
- Defined in:
- lib/ec2_start_stop_handler.rb
Instance Method Summary collapse
-
#initialize(instance_id) ⇒ Ec2StartStopHandler
constructor
A new instance of Ec2StartStopHandler.
- #start(configuration) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(instance_id) ⇒ Ec2StartStopHandler
Returns a new instance of Ec2StartStopHandler.
9 10 11 12 13 14 |
# File 'lib/ec2_start_stop_handler.rb', line 9 def initialize(instance_id) credentials = Base2::AWSCredentials.get_session_credentials("stoprun_#{instance_id}") ec2_client = Aws::EC2::Client.new(credentials: credentials, retry_limit: 20) @instance = Aws::EC2::Resource.new(client: ec2_client, retry_limit: 20).instance(instance_id) @instance_id = instance_id end |
Instance Method Details
#start(configuration) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ec2_start_stop_handler.rb', line 16 def start(configuration) if %w(running).include?(@instance.state.name) $log.info("Instance #{@instance_id} already running") return end $log.info("Starting instance #{@instance_id}") @instance.start() end |
#stop ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ec2_start_stop_handler.rb', line 25 def stop if %w(stopped stopping).include?(@instance.state.name) $log.info("Instance #{@instance_id} already stopping or stopped") return end $log.info("Stopping instance #{@instance_id}") @instance.stop() # empty configuration for ec2 instances return {} end |