Sha256: d68f057d792c97aacb89145d20f010b826242e23ce49ef94486b36972425cefd
Contents?: true
Size: 1.56 KB
Versions: 4
Compression:
Stored size: 1.56 KB
Contents
require 'cfn_manage/aws_credentials' module CfnManage module StartStopHandler class SpotFleet def initialize(fleet_id, options = {}) @fleet_id = fleet_id 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 end
Version data entries
4 entries across 4 versions & 1 rubygems