Class: Kontena::Machine::Aws::MasterDestroyer
- Inherits:
-
Object
- Object
- Kontena::Machine::Aws::MasterDestroyer
- Includes:
- Cli::ShellSpinner
- Defined in:
- lib/kontena/machine/aws/master_destroyer.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#ec2 ⇒ Object
readonly
Returns the value of attribute ec2.
Instance Method Summary collapse
-
#initialize(api_client, access_key_id, secret_key, region = 'eu-west-1') ⇒ MasterDestroyer
constructor
A new instance of MasterDestroyer.
- #run!(name) ⇒ Object
Constructor Details
#initialize(api_client, access_key_id, secret_key, region = 'eu-west-1') ⇒ MasterDestroyer
Returns a new instance of MasterDestroyer.
14 15 16 17 18 19 20 |
# File 'lib/kontena/machine/aws/master_destroyer.rb', line 14 def initialize(api_client, access_key_id, secret_key, region = 'eu-west-1') @api_client = api_client @ec2 = ::Aws::EC2::Resource.new( region: region, credentials: ::Aws::Credentials.new(access_key_id, secret_key) ) end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
8 9 10 |
# File 'lib/kontena/machine/aws/master_destroyer.rb', line 8 def api_client @api_client end |
#ec2 ⇒ Object (readonly)
Returns the value of attribute ec2.
8 9 10 |
# File 'lib/kontena/machine/aws/master_destroyer.rb', line 8 def ec2 @ec2 end |
Instance Method Details
#run!(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kontena/machine/aws/master_destroyer.rb', line 22 def run!(name) instances = ec2.instances({ filters: [ {name: 'tag:Name', values: [name]} ] }) abort("Cannot find AWS instance #{name}") if instances.to_a.size == 0 abort("There are multiple instances with name #{name}") if instances.to_a.size > 1 instance = instances.first if instance spinner "Terminating AWS instance #{name.colorize(:cyan)} " do instance.terminate until instance.reload.state.name.to_s == 'terminated' sleep 1 end end else abort "Cannot find instance #{name.colorize(:cyan)} in AWS" end end |