<commit_before>module Cucumber::Chef::Helpers::Container

################################################################################

  def container_create(name)
    unless container_exists?(name)
      command_run_local("lxc-create -n #{name} -f /etc/lxc/#{name} -t ubuntu 2>&1")
      command_run_local("mkdir -p #{container_root(name)}/root/.ssh/ 2>&1")
      command_run_local("chmod 0700 #{container_root(name)}/root/.ssh/ 2>&1")
      command_run_local("cat /root/.ssh/id_rsa.pub > #{container_root(name)}/root/.ssh/authorized_keys 2>&1")
    end
    container_start(name)
  end

  def container_destroy(name)
    if container_exists?(name)
      container_stop(name)
      command_run_local("lxc-destroy -n #{name} 2>&1")
      chef_server_node_destroy(name)
      chef_server_client_destroy(name)
    end
  end

################################################################################

  def container_start(name)
    status = command_run_local("lxc-info -n #{name} 2>&1")
    if status.include?("STOPPED")
      command_run_local("lxc-start -d -n #{name}")
    end
  end

  def container_stop(name)
    status = command_run_local("lxc-info -n #{name} 2>&1")
    if status.include?("RUNNING")
      command_run_local("lxc-stop -n #{name}")
    end
  end

################################################################################

  def container_config_network(name)
    lxc_network_config = File.join("/etc/lxc", name)
    File.open(lxc_network_config, 'w') do |f|
      f.puts(Cucumber::Chef.generate_do_not_edit_warning("LXC Container Configuration"))
      f.puts("")
      f.puts("lxc.network.type = veth")
      f.puts("lxc.network.flags = up")
      f.puts("lxc.network.link = br0")
      f.puts("lxc.network.name = eth0")
      f.puts("lxc.network.hwaddr = #{$servers[name][:mac]}")
      f.puts("lxc.network.ipv4 = 0.0.0.0")
    end
  end

################################################################################

  def containers
    command_run_local("lxc-ls 2>&1").split("\n").uniq
  end

  def container_exists?(name)
    (File.directory?(container_root(name)) ? true : false)
  end

  def container_root(name)
    File.join("/", "var", "lib", "lxc", name, "rootfs")
  end

################################################################################

end
<commit_msg>copy ubuntu users public key into containers authorized_keys<commit_after>module Cucumber::Chef::Helpers::Container

################################################################################

  def container_create(name)
    unless container_exists?(name)
      command_run_local("lxc-create -n #{name} -f /etc/lxc/#{name} -t ubuntu 2>&1")
      command_run_local("mkdir -p #{container_root(name)}/root/.ssh/ 2>&1")
      command_run_local("chmod 0700 #{container_root(name)}/root/.ssh/ 2>&1")
      command_run_local("cat /root/.ssh/id_rsa.pub > #{container_root(name)}/root/.ssh/authorized_keys 2>&1")
      command_run_local("cat /home/ubuntu/.ssh/id_rsa.pub >> #{container_root(name)}/root/.ssh/authorized_keys 2>&1")
    end
    container_start(name)
  end

  def container_destroy(name)
    if container_exists?(name)
      container_stop(name)
      command_run_local("lxc-destroy -n #{name} 2>&1")
      chef_server_node_destroy(name)
      chef_server_client_destroy(name)
    end
  end

################################################################################

  def container_start(name)
    status = command_run_local("lxc-info -n #{name} 2>&1")
    if status.include?("STOPPED")
      command_run_local("lxc-start -d -n #{name}")
    end
  end

  def container_stop(name)
    status = command_run_local("lxc-info -n #{name} 2>&1")
    if status.include?("RUNNING")
      command_run_local("lxc-stop -n #{name}")
    end
  end

################################################################################

  def container_config_network(name)
    lxc_network_config = File.join("/etc/lxc", name)
    File.open(lxc_network_config, 'w') do |f|
      f.puts(Cucumber::Chef.generate_do_not_edit_warning("LXC Container Configuration"))
      f.puts("")
      f.puts("lxc.network.type = veth")
      f.puts("lxc.network.flags = up")
      f.puts("lxc.network.link = br0")
      f.puts("lxc.network.name = eth0")
      f.puts("lxc.network.hwaddr = #{$servers[name][:mac]}")
      f.puts("lxc.network.ipv4 = 0.0.0.0")
    end
  end

################################################################################

  def containers
    command_run_local("lxc-ls 2>&1").split("\n").uniq
  end

  def container_exists?(name)
    (File.directory?(container_root(name)) ? true : false)
  end

  def container_root(name)
    File.join("/", "var", "lib", "lxc", name, "rootfs")
  end

################################################################################

end

{'fraction_non_alphanumeric': 0.2999376429016836, 'fraction_numerical': 0.011639991685720224, 'mean_word_length': 4.4006734006734005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5380648', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1525, 'n_words': 249}