Sha256: 0e7abd9e864ea6c1e0ecdf22233cd92a238db9a31ea8e83b65235e80bc21b6cc

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'beaker/hypervisor/vagrant'

class Beaker::VagrantLibvirt < Beaker::Vagrant
  @memory = nil
  @cpu    = nil

  class << self
    attr_reader :memory
  end

  # Return a random mac address with colons
  #
  # @return [String] a random mac address
  def randmac
    "08:00:27:" + (1..3).map{"%0.2X"%rand(256)}.join(':')
  end

  def provision(provider = 'libvirt')
    # This needs to be unique for every system with the same hostname but does
    # not affect VirtualBox
    vagrant_path_digest = Digest::SHA256.hexdigest(@vagrant_path)
    @vagrant_path = @vagrant_path + '_' + vagrant_path_digest[0..2] + vagrant_path_digest[-3..-1]
    @vagrant_file = File.expand_path(File.join(@vagrant_path, "Vagrantfile"))

    super
  end

  def self.provider_vfile_section(host, options)
    "    v.vm.provider :libvirt do |node|\n" +
      "      node.cpus = #{cpus(host, options)}\n" +
      "      node.memory = #{memsize(host, options)}\n" +
      "      node.qemu_use_session = false\n" +
      build_options_str(options) +
      "    end\n"
  end

  def self.build_options_str(options)
    other_options_str = ''
    if options['libvirt']
      other_options = []
      options['libvirt'].each do |k, v|
        other_options << "      node.#{k} = '#{v}'"
      end
      other_options_str = other_options.join("\n")
    end
    "#{other_options_str}\n"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
beaker-vagrant-0.6.7 lib/beaker/hypervisor/vagrant_libvirt.rb