<commit_before>require 'fog'

module Salt
  module Commands
    class Teardown < BaseCommand
      def run(args=[])
        vm = find name
        unless vm
          puts "Machine not found or not running: #{name}"
          return
        end
        if vm.state == :running
          unless force_yes
            require_confirmation! <<-EOE
            Are you sure you want to teardown the machine #{name}.
            This <%= color('cannot', RED) %> be undone
            EOE
          end
          provider.teardown(vm)
          if name != "#{environment}-master"
            Salt::Commands::Key.new(provider, config.merge(delete: true, name: name)).run([])
          end
        else
          puts "Not running"
        end
      end
      
      def self.additional_options(x)
        x.on('-y', '--yes', "Answer yes to all questions") {config[:force_yes] = true}
      end
      
    end
  end
end

Salt.register_command "teardown", Salt::Commands::Teardown<commit_msg>Added teardown -a to teardown the entire cluster<commit_after>require 'fog'

module Salt
  module Commands
    class Teardown < BaseCommand
      def run(args=[])
        if all
          teardown_all!
        else
          teardown_single!(name)
        end
      end
      
      def teardown_all!
        provider.running_list.each do |m|
          teardown_single! m.name unless m.name == "#{environment}-master"
        end
        teardown_single!("#{environment}-master")
      end
      
      def teardown_single!(name)
        vm = find name
        unless vm
          puts "Machine not found or not running: #{name}"
          return
        end
        if vm.state == :running
          unless force_yes
            require_confirmation! <<-EOE
            Are you sure you want to teardown the machine #{name}.
            This <%= color('cannot', RED) %> be undone
            EOE
          end
          provider.teardown(vm)
          if name != "#{environment}-master"
            Salt::Commands::Key.new(provider, config.merge(delete: true, name: name)).run([])
          end
        else
          puts "Not running"
        end
      end
      
      def self.additional_options(x)
        x.on('-y', '--yes', "Answer yes to all questions") {config[:force_yes] = true}
        x.on('-a', '--all', "Teardown all running nodes") {config[:all] = true}
      end
      
    end
  end
end

Salt.register_command "teardown", Salt::Commands::Teardown
{'fraction_non_alphanumeric': 0.10580065359477124, 'fraction_numerical': 0.0, 'mean_word_length': 1.7861205915813425, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924997', 'n_tokens_mistral': 718, 'n_tokens_neox': 707, 'n_words': 204}