class VagrantPlugins::ProviderLibvirt::Config

Attributes

cmd_line[RW]
connect_via_ssh[RW]

If use ssh tunnel to connect to Libvirt.

cpu_mode[RW]
cpus[RW]
default_prefix[RW]

Default host prefix (alternative to use project folder name)

disk_bus[RW]
disks[RW]

Storage

driver[RW]
host[RW]

The name of the server, where libvirtd is running.

id_ssh_key_file[RW]

ID SSH key file

initrd[RW]
kernel[RW]
management_network_address[RW]
management_network_name[RW]

Libvirt default network

memory[RW]

Domain specific settings used while creating new domain.

nested[RW]
password[RW]

Password for Libvirt connection.

socket[RW]

Path towards the libvirt socket

storage_pool_name[RW]

Libvirt storage pool name, where box image and instance snapshots will be stored.

username[RW]

The username to access Libvirt.

volume_cache[RW]

Public Class Methods

new() click to toggle source
# File lib/vagrant-libvirt/config.rb, line 61
def initialize
  @driver            = UNSET_VALUE
  @host              = UNSET_VALUE
  @connect_via_ssh   = UNSET_VALUE
  @username          = UNSET_VALUE
  @password          = UNSET_VALUE
  @id_ssh_key_file   = UNSET_VALUE
  @storage_pool_name = UNSET_VALUE
  @management_network_name    = UNSET_VALUE
  @management_network_address = UNSET_VALUE

  # Domain specific settings.
  @memory            = UNSET_VALUE
  @cpus              = UNSET_VALUE
  @cpu_mode          = UNSET_VALUE
  @disk_bus          = UNSET_VALUE
  @nested            = UNSET_VALUE
  @volume_cache      = UNSET_VALUE
  @kernel            = UNSET_VALUE
  @initrd            = UNSET_VALUE
  @cmd_line          = UNSET_VALUE

  # Storage
  @disks             = UNSET_VALUE
end

Public Instance Methods

_get_device(disks) click to toggle source
# File lib/vagrant-libvirt/config.rb, line 87
def _get_device(disks)
  disks = [] if disks == UNSET_VALUE
  # skip existing devices and also the first one (vda)
  exist = disks.collect {|x| x[:device]}+[1.vdev.to_s]
  skip = 1                # we're 1 based, not 0 based...
  while true do
    dev = skip.vdev       # get lettered device
    if !exist.include?(dev)
      return dev
    end
    skip+=1
  end
end
finalize!() click to toggle source
# File lib/vagrant-libvirt/config.rb, line 125
def finalize!
  @driver = 'kvm' if @driver == UNSET_VALUE
  @host = nil if @host == UNSET_VALUE
  @connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE
  @username = nil if @username == UNSET_VALUE
  @password = nil if @password == UNSET_VALUE
  @id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE
  @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
  @management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
  @management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE

  # Domain specific settings.
  @memory = 512 if @memory == UNSET_VALUE
  @cpus = 1 if @cpus == UNSET_VALUE
  @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
  @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE
  @nested = false if @nested == UNSET_VALUE
  @volume_cache = 'default' if @volume_cache == UNSET_VALUE
  @kernel = nil if @kernel == UNSET_VALUE
  @cmd_line = '' if @cmd_line == UNSET_VALUE
  @initrd = '' if @initrd == UNSET_VALUE

  # Storage
  @disks = [] if @disks == UNSET_VALUE
end
storage(storage_type, options={}) click to toggle source

NOTE: this will run twice for each time it's needed- keep it idempotent

# File lib/vagrant-libvirt/config.rb, line 102
def storage(storage_type, options={})
  options = {
    :device => _get_device(@disks),
    :type => 'qcow2',
    :size => '10G',       # matches the fog default
    :path => nil,
  }.merge(options)

  #puts "storage(#{storage_type} --- #{options.to_s})"
  @disks = [] if @disks == UNSET_VALUE

  disk = {
    :device => options[:device],
    :type => options[:type],
    :size => options[:size],
    :path => options[:path],
  }

  if storage_type == :file
    @disks << disk        # append
  end
end
validate(machine) click to toggle source
# File lib/vagrant-libvirt/config.rb, line 151
def validate(machine)
end