<commit_before>require 'boucher/env'
require 'boucher/meals'
require 'boucher/io'
require 'fog'
require 'retryable'

module Boucher

  EC2_CONFIG = {
          :provider => 'AWS',
          :aws_secret_access_key => Boucher::Config[:aws_secret_access_key],
          :aws_access_key_id => Boucher::Config[:aws_access_key_id],
          :region => Boucher::Config[:aws_region]
  }

  def self.compute
    @compute ||= Fog::Compute.new(EC2_CONFIG)
    @compute
  end

  def self.snapshots
    @snapshots ||= compute.snapshots
  end

  def self.ssh(server, command=nil)
    command_arg = nil
    if command
      command_arg = "\"#{command}\""
    end

    command = "#{ssh_command} #{Boucher::Config[:username]}@#{server.dns_name} #{command_arg}"
    verbose command
    Kernel.system command
    raise "command failed with code #{$?.exitstatus}" unless $?.success?
  end

  def self.ssh_command
    "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Boucher::Config[:aws_key_filename]}.pem"
  end

  def self.update_recipes(server)
    puts "Updating recipes on #{server.id}"
    ssh server, "cd infrastructure && git checkout . && git clean -d -f && git pull && bundle"
  end

  def self.cook_meal(server, meal_name)
    update_recipes(server)
    ssh server, "cd infrastructure && git pull && sudo BUTCHER_ENV=#{Boucher::Config[:env]} BRANCH=#{Boucher::Config[:branch]} chef-solo -c config/solo.rb -j config/#{meal_name}.json"
  end

  def self.ssh_open?(server)
    ssh server, "echo 'SSH is open for business!'"
    true
  rescue Exception => e
    false
  end

  def self.change_server_state(server_id, command, new_state)
    print "#{command}-ing server #{server_id}..."
    server = compute.servers.get(server_id)
    server.send(command.to_sym)
    server.wait_for { print "."; state == new_state }
    puts
    Boucher.print_servers [server]
    puts
    puts "The server has been #{command}-ed."
  end<commit_msg>removes rsync commands<commit_after>require 'boucher/env'
require 'boucher/meals'
require 'boucher/io'
require 'fog'
require 'retryable'

module Boucher

  EC2_CONFIG = {
          :provider => 'AWS',
          :aws_secret_access_key => Boucher::Config[:aws_secret_access_key],
          :aws_access_key_id => Boucher::Config[:aws_access_key_id],
          :region => Boucher::Config[:aws_region]
  }

  def self.compute
    @compute ||= Fog::Compute.new(EC2_CONFIG)
    @compute
  end

  def self.snapshots
    @snapshots ||= compute.snapshots
  end

  def self.ssh(server, command=nil)
    command_arg = nil
    if command
      command_arg = "\"#{command}\""
    end

    command = "#{ssh_command} #{Boucher::Config[:username]}@#{server.dns_name} #{command_arg}"
    verbose command
    Kernel.system command
    raise "command failed with code #{$?.exitstatus}" unless $?.success?
  end

  def self.ssh_command
    "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{Boucher::Config[:aws_key_filename]}.pem"
  end

  def self.update_recipes(server)
    puts "Updating recipes on #{server.id}"
    ssh server, "cd infrastructure && git checkout . && git clean -d -f && git pull && bundle"
  end

  def self.cook_meal(server, meal_name)
    update_recipes(server)
    ssh server, "cd infrastructure && sudo BUTCHER_ENV=#{Boucher::Config[:env]} BRANCH=#{Boucher::Config[:branch]} chef-solo -c config/solo.rb -j config/#{meal_name}.json"
  end

  def self.ssh_open?(server)
    ssh server, "echo 'SSH is open for business!'"
    true
  rescue Exception => e
    false
  end

  def self.change_server_state(server_id, command, new_state)
    print "#{command}-ing server #{server_id}..."
    server = compute.servers.get(server_id)
    server.send(command.to_sym)
    server.wait_for { print "."; state == new_state }
    puts
    Boucher.print_servers [server]
    puts
    puts "The server has been #{command}-ed."
  end
{'fraction_non_alphanumeric': 0.13295542385982995, 'fraction_numerical': 0.001030662200463798, 'mean_word_length': 3.5886524822695036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4701779', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1313, 'n_words': 301}