Class: Central::Machine::Vagrant::MasterDestroyer

Inherits:
Object
  • Object
show all
Defined in:
lib/central/machine/vagrant/master_destroyer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ MasterDestroyer

Returns a new instance of MasterDestroyer.

Parameters:



10
11
12
# File 'lib/central/machine/vagrant/master_destroyer.rb', line 10

def initialize(api_client)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



7
8
9
# File 'lib/central/machine/vagrant/master_destroyer.rb', line 7

def api_client
  @api_client
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/central/machine/vagrant/master_destroyer.rb', line 7

def client
  @client
end

Instance Method Details

#run!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/central/machine/vagrant/master_destroyer.rb', line 14

def run!
  if api_client.get('stacks')['stacks'].size > 0
    abort('Cannot remove central-machine because it has stacks'.colorize(:red))
  end

  vagrant_path = "#{Dir.home}/.central/vagrant_master"
  Dir.chdir(vagrant_path) do
    ShellSpinner 'Terminating Vagrant central-machine ' 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
end