Sha256: f47fd27148fdb108dde6a3bb99d7f8277834cb0d724855431e42c31f4484fa5b

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

require 'cfn_manage/aws_credentials'

module CfnManage

  class SpotFleetStartStopHandler

    def initialize(fleet_id, skip_wait)
      @fleet_id = fleet_id
      @skip_wait = skip_wait
      credentials = CfnManage::AWSCredentials.get_session_credentials("startstopfleet_#{fleet_id}")
      @ec2_client = Aws::EC2::Client.new(retry_limit: 20)
      if credentials != nil
        @ec2_client = Aws::EC2::Client.new(credentials: credentials, retry_limit: 20)
      end

      @fleet = @ec2_client.describe_spot_fleet_requests({spot_fleet_request_ids:[fleet_id]})
      @fleet = @fleet.spot_fleet_request_configs[0].spot_fleet_request_config
    end

    def start(configuration)

      $log.info("Setting fleet #{@fleet_id} capacity to #{configuration['target_capacity']}")
      @ec2_client.modify_spot_fleet_request({
          spot_fleet_request_id: @fleet_id,
          target_capacity: configuration['target_capacity'],
      })

      return configuration
    end

    def stop

      if @fleet.target_capacity == 0
        $log.info("Spot fleet #{@fleet_id} already stopped")
        return nil
      end

      configuration = {
          target_capacity: @fleet.target_capacity
      }

      $log.info("Setting fleet #{@fleet_id} capacity to 0")
      @ec2_client.modify_spot_fleet_request({
          spot_fleet_request_id: @fleet_id,
          target_capacity: 0,
      })

      return configuration
    end

    def wait(wait_states=[])
      $log.debug("Not waiting for spot fleet #{@fleet_id}")
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

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