Class: Kontena::Machine::Vagrant::NodeDestroyer

Inherits:
Object
  • Object
show all
Includes:
Cli::ShellSpinner, Common, RandomName
Defined in:
lib/kontena/machine/vagrant/node_destroyer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#erb, #run_command

Constructor Details

#initialize(api_client) ⇒ NodeDestroyer

Returns a new instance of NodeDestroyer.

Parameters:

  • api_client (Kontena::Client)

    Kontena api client



14
15
16
# File 'lib/kontena/machine/vagrant/node_destroyer.rb', line 14

def initialize(api_client)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



11
12
13
# File 'lib/kontena/machine/vagrant/node_destroyer.rb', line 11

def api_client
  @api_client
end

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/kontena/machine/vagrant/node_destroyer.rb', line 11

def client
  @client
end

Instance Method Details

#run!(grid, name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kontena/machine/vagrant/node_destroyer.rb', line 18

def run!(grid, name)
  vagrant_path = "#{Dir.home}/.kontena/#{grid}/#{name}"
  Dir.chdir(vagrant_path) do
    spinner "Triggering termination of Vagrant machine #{name.colorize(:cyan)}"
    run_command('vagrant destroy -f')
    FileUtils.remove_entry_secure(vagrant_path)
  end
  node = api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
  if node
    spinner "Removing node #{name.colorize(:cyan)} from grid #{grid.colorize(:cyan)} " do
      api_client.delete("nodes/#{grid}/#{name}")
    end
  end
end