Class: Central::Machine::Vagrant::NodeDestroyer
- Inherits:
-
Object
- Object
- Central::Machine::Vagrant::NodeDestroyer
- Includes:
- RandomName
- Defined in:
- lib/central/machine/vagrant/node_destroyer.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(api_client) ⇒ NodeDestroyer
constructor
A new instance of NodeDestroyer.
- #run!(stack, name) ⇒ Object
Methods included from RandomName
Constructor Details
#initialize(api_client) ⇒ NodeDestroyer
Returns a new instance of NodeDestroyer.
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_client ⇒ Object (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 |
#client ⇒ Object (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 |