Sha256: f04832cc80e99c23927e89283fe435d4acca55c40d5c1ac5dd27cbe2b484f7e6

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

require 'cfn_manage/aws_credentials'

module CfnManage

  class Ec2StartStopHandler

    @instance

    def initialize(instance_id, skip_wait)
      credentials = CfnManage::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
      @skip_wait = skip_wait
    end

    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

    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

    def wait(wait_states=[])
      $log.debug("Not waiting for EC2 instance #{@instance_id}")
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cfn_manage-0.7.1 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.7.0 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.6.0 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.5 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.4 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.3 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.2 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.1 lib/cfn_manage/ec2_start_stop_handler.rb
cfn_manage-0.5.0 lib/cfn_manage/ec2_start_stop_handler.rb