Class: CfnManage::StartStopHandler::SpotFleet
- Inherits:
-
Object
- Object
- CfnManage::StartStopHandler::SpotFleet
- Defined in:
- lib/cfn_manage/handlers/spot_fleet.rb
Instance Method Summary collapse
-
#initialize(fleet_id, options = {}) ⇒ SpotFleet
constructor
A new instance of SpotFleet.
- #start(configuration) ⇒ Object
- #stop ⇒ Object
- #wait(wait_states = []) ⇒ Object
Constructor Details
#initialize(fleet_id, options = {}) ⇒ SpotFleet
Returns a new instance of SpotFleet.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cfn_manage/handlers/spot_fleet.rb', line 7 def initialize(fleet_id, = {}) @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 |
Instance Method Details
#start(configuration) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cfn_manage/handlers/spot_fleet.rb', line 19 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 |
#stop ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cfn_manage/handlers/spot_fleet.rb', line 30 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 |
#wait(wait_states = []) ⇒ Object
50 51 52 |
# File 'lib/cfn_manage/handlers/spot_fleet.rb', line 50 def wait(wait_states=[]) $log.debug("Not waiting for spot fleet #{@fleet_id}") end |