Class: Veewee::Provider::Kvm::Provider

Inherits:
Core::Provider show all
Defined in:
lib/veewee/provider/kvm/provider.rb

Instance Attribute Summary

Attributes inherited from Core::Provider

#env, #name, #options, #type

Instance Method Summary collapse

Methods inherited from Core::Provider

available?, #gem_available?, #gems_available?, #get_box, #initialize, #ui

Methods included from Core::Helper::Shell

#shell_exec

Constructor Details

This class inherits a constructor from Veewee::Provider::Core::Provider

Instance Method Details

#build(definition_name, box_name, options) ⇒ Object



53
54
55
56
57
# File 'lib/veewee/provider/kvm/provider.rb', line 53

def build(definition_name, box_name, options)

  super(definition_name, box_name, options)

end

#check_requirementsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/veewee/provider/kvm/provider.rb', line 8

def check_requirements
  require 'fog'

  env.logger.info "Falling back to qemu:///system for libvirt URI if no value is specified in the .fog config file"
  Fog.credentials[:libvirt_uri] ||= "qemu:///system"

  env.logger.info "Setting libvirt IP Command if not already defined in .fog config file"
  Fog.credentials[:libvirt_ip_command] ||= "arp -an |grep $mac|cut -d '(' -f 2 | cut -d ')' -f 1"

  env.logger.info "Opening a libvirt connection using fog.io"
  begin

    unless gems_available?(["ruby-libvirt"])
      raise Veewee::Error, "Please install ruby-libvirt gem first"
    end
  end

  begin

    env.logger.info "Opening a libvirt connection using fog.io"
    conn = Fog::Compute[:libvirt]
  rescue Exception => ex
    raise Veewee::Error, "There was a problem opening a connection to libvirt: #{ex}"
  end
  env.logger.info "Libvirt connection established"

  env.logger.debug "Found capabilities:"
  env.logger.debug "#{conn.client.capabilities}"

  env.logger.info "Checking libvirt version"
  # http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion
  # format major * 1,000,000 + minor * 1,000 + release
  conn.client.libversion > 8003 or raise Veewee::Error, "You need at least libvirt version 0.8.3 or higher "

  env.logger.info "Checking available networks"
  conn.networks.any? or raise Veewee::Error, "You need at least one (active) network defined in #{Fog.credentials[:libvirt_uri]}."

  env.logger.info "Checking available storagepools"
  conn.pools.any? or raise Veewee::Error, "You need at least one (active) storage pool defined in #{Fog.credentials[:libvirt_uri]}."

  env.logger.info "Checking availability of the arp utility"
  shell_exec("arp").status.zero? or raise Veewee::Error, "Could not execute the arp command. This is required to find the IP address of the VM"

end