<commit_before>require 'provision/image/catalogue'
require 'provision/image/commands'

define "grow" do
  extend Provision::Image::Commands

  run("grow the partition table and filesystem") {
    case config[:vm_storage_type]
    when 'image'
      cmd "cp #{spec[:images_dir]}/gold/generic.img #{spec[:image_path]}"
      cmd "losetup /dev/#{spec[:loop0]} #{spec[:image_path]}"
      cmd "qemu-img resize #{spec[:image_path]} #{spec[:image_size]}"
      cmd "losetup -c /dev/#{spec[:loop0]}"
      vm_disk_location = "/dev/#{spec[:loop0]}"
    when 'lvm'
      cmd "lvcreate -n #{spec[:hostname]} -L #{spec[:image_size]} #{spec[:lvm_vg]}"
      cmd "dd if=#{spec[:images_dir]}/gold/generic.img of=/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
      vm_disk_location = "/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
    else
      raise "provisioning tools does not know about vm_storage_type '#{config[:vm_storage_type]}'"
    end

    cmd "parted -s #{vm_disk_location} rm 1"
    cmd "parted -s #{vm_disk_location} mkpart primary ext3 2048s 100%"
    vm_partition_name = cmd "kpartx -l #{vm_disk_location} | awk '{ print $1 }'"
    cmd "kpartx -a #{vm_disk_location}"

    cmd "e2fsck -f -p /dev/mapper/#{vm_partition_name}"
    cmd "resize2fs /dev/mapper/#{vm_partition_name}"
  }

  on_error {
    case config[:vm_storage_type]
    when 'lvm'
      if File.exists?("/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}")
        cmd "lvremove -f /dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
      end
    end
  }

  cleanup {
    case config[:vm_storage_type]
    when 'image'
      cmd "kpartx -d /dev/#{spec[:loop0]}"
      cmd "losetup -d /dev/#{spec[:loop0]}"
    when 'lvm'
      cmd "kpartx -d /dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
    else
      raise "provisioning tools does not know about vm_storage_type '#{config[:vm_storage_type]}'"<commit_msg>tomd: do not try to create logical volumnes if they already exist -- just bail<commit_after>require 'provision/image/catalogue'
require 'provision/image/commands'

define "grow" do
  extend Provision::Image::Commands

  run("grow the partition table and filesystem") {
    case config[:vm_storage_type]
    when 'image'
      cmd "cp #{spec[:images_dir]}/gold/generic.img #{spec[:image_path]}"
      cmd "losetup /dev/#{spec[:loop0]} #{spec[:image_path]}"
      cmd "qemu-img resize #{spec[:image_path]} #{spec[:image_size]}"
      cmd "losetup -c /dev/#{spec[:loop0]}"
      vm_disk_location = "/dev/#{spec[:loop0]}"
    when 'lvm'
      vm_disk_location = "/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
      if File.exists?(vm_disk_location)
        raise "Logical volume '#{vm_disk_location}' already exists!"
      end
      cmd "lvcreate -n #{spec[:hostname]} -L #{spec[:image_size]} #{spec[:lvm_vg]}"
      cmd "dd if=#{spec[:images_dir]}/gold/generic.img of=/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
    else
      raise "provisioning tools does not know about vm_storage_type '#{config[:vm_storage_type]}'"
    end

    cmd "parted -s #{vm_disk_location} rm 1"
    cmd "parted -s #{vm_disk_location} mkpart primary ext3 2048s 100%"
    vm_partition_name = cmd "kpartx -l #{vm_disk_location} | awk '{ print $1 }'"
    cmd "kpartx -a #{vm_disk_location}"

    cmd "e2fsck -f -p /dev/mapper/#{vm_partition_name}"
    cmd "resize2fs /dev/mapper/#{vm_partition_name}"
  }

  on_error {
    case config[:vm_storage_type]
    when 'lvm'
      if File.exists?("/dev/#{spec[:lvm_vg]}/#{spec[:hostname]}")
        cmd "lvremove -f /dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
      end
    end
  }

  cleanup {
    case config[:vm_storage_type]
    when 'image'
      cmd "kpartx -d /dev/#{spec[:loop0]}"
      cmd "losetup -d /dev/#{spec[:loop0]}"
    when 'lvm'
      cmd "kpartx -d /dev/#{spec[:lvm_vg]}/#{spec[:hostname]}"
    else
      raise "provisioning tools does not know about vm_storage_type '#{config[:vm_storage_type]}'"
{'fraction_non_alphanumeric': 0.17554291623578078, 'fraction_numerical': 0.008790072388831437, 'mean_word_length': 3.6224611708482675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6785775', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1413, 'n_words': 303}