Class: Forger::Destroy

Inherits:
Base
  • Object
show all
Includes:
AwsServices
Defined in:
lib/forger/destroy.rb

Constant Summary

Constants inherited from Base

Base::BUILD_ROOT, Base::SCRIPTS_INFO_PATH

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #ec2, #s3

Methods inherited from Base

#derandomize, #initialize, #randomize

Constructor Details

This class inherits a constructor from Forger::Base

Instance Method Details

#cancel_spot_request(instance_id) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/forger/destroy.rb', line 14

def cancel_spot_request(instance_id)
  resp = ec2.describe_instances(instance_ids: [instance_id])
  spot_id = resp.reservations.first.instances.first.spot_instance_request_id

  return unless spot_id
  ec2.cancel_spot_instance_requests(spot_instance_request_ids: [spot_id])
  puts "Spot instance request #{spot_id} cancelled."
end

#run(instance_id) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/forger/destroy.rb', line 5

def run(instance_id)
  puts "Destroying #{instance_id}"
  return if ENV['TEST']

  cancel_spot_request(instance_id)
  ec2.terminate_instances(instance_ids: [instance_id])
  puts "Instance #{instance_id} terminated."
end