Class: Central::Machine::Vagrant::NodeDestroyer

Inherits:
Object
  • Object
show all
Includes:
RandomName
Defined in:
lib/central/machine/vagrant/node_destroyer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RandomName

#generate_name

Constructor Details

#initialize(api_client) ⇒ NodeDestroyer

Returns a new instance of NodeDestroyer.

Parameters:



12
13
14
# File 'lib/central/machine/vagrant/node_destroyer.rb', line 12

def initialize(api_client)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



9
10
11
# File 'lib/central/machine/vagrant/node_destroyer.rb', line 9

def api_client
  @api_client
end

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/central/machine/vagrant/node_destroyer.rb', line 9

def client
  @client
end

Instance Method Details

#run!(stack, name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/central/machine/vagrant/node_destroyer.rb', line 16

def run!(stack, name)
  vagrant_path = "#{Dir.home}/.central/#{stack}/#{name}"
  Dir.chdir(vagrant_path) do
    ShellSpinner "Terminating Vagrant machine #{name.colorize(:cyan)} " do
      Open3.popen2('vagrant destroy -f') do |_stdin, output, wait|
        while o = output.gets
          puts o if ENV['DEBUG']
        end
        FileUtils.remove_entry_secure(vagrant_path) if wait.value == 0
      end
    end
  end
  node = api_client.get("stacks/#{stack}/nodes")['nodes'].find { |n| n['name'] == name }
  if node
    ShellSpinner "Removing node #{name.colorize(:cyan)} from stack #{stack.colorize(:cyan)} " do
      api_client.delete("stacks/#{stack}/nodes/#{name}")
    end
  end
end