Sha256: 68ddcafe2fff7e19984199932d7737246e6bd74bbaec2fc8fb671a05471611ec

Contents?: true

Size: 1.18 KB

Versions: 37

Compression:

Stored size: 1.18 KB

Contents

require 'fileutils'

module Kontena
  module Machine
    module Vagrant
      class NodeDestroyer
        include RandomName

        attr_reader :client, :api_client

        # @param [Kontena::Client] api_client Kontena api client
        def initialize(api_client)
          @api_client = api_client
        end

        def run!(grid, name)
          vagrant_path = "#{Dir.home}/.kontena/#{grid}/#{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
                if wait.value == 0
                  FileUtils.remove_entry_secure(vagrant_path)
                end
              end
            end
          end
          node = api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == name}
          if node
            ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid.colorize(:cyan)} " do
              api_client.delete("grids/#{grid}/nodes/#{name}")
            end
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
kontena-plugin-vagrant-0.1.2 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-plugin-vagrant-0.1.1 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-plugin-vagrant-0.1.0 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.7 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.6 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.5 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.4 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.3 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.2 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.1 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.14.0 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.4 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.3 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.2 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.1 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.0.1 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.13.0 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.12.3 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.12.2 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-cli-0.12.1 lib/kontena/machine/vagrant/node_destroyer.rb