Sha256: 3d3abe88710079568938b7812b7a14ecd28c0d16392b65d0eb7a0916a8790249

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'fileutils'

module Kontena
  module Machine
    module Vagrant
      class NodeDestroyer
        include RandomName
        include Kontena::Cli::ShellSpinner

        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
            spinner "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
            spinner "Removing node #{name.colorize(:cyan)} from grid #{grid.colorize(:cyan)} " do
              api_client.delete("nodes/#{grid}/#{name}")
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kontena-plugin-vagrant-0.2.7 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-plugin-vagrant-0.2.6 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-plugin-vagrant-0.2.5 lib/kontena/machine/vagrant/node_destroyer.rb
kontena-plugin-vagrant-0.2.2 lib/kontena/machine/vagrant/node_destroyer.rb