class BoxGrinder::LibvirtCapabilities

Constants

DEFAULT_DOMAIN_MAPPINGS

Arrays are populated in order of precedence. Best first.

DOMAINS
PLUGINS
PLUGIN_MAPPINGS

Public Class Methods

new(opts={}) click to toggle source
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 90
def initialize(opts={})
  @log = opts[:log] || LogHelper.new
end

Public Instance Methods

build_guest(xml) click to toggle source
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 133
def build_guest(xml)
  dom = DOMAINS[xpath_first_intern(xml, ".//domain/@type")]
  bus = 'ide'
  bus = dom.bus if dom

  OpenStruct.new({
    :domain_type => xpath_first_intern(xml, ".//domain/@type"),
    :os_type => xpath_first_intern(xml, './/os_type'),
    :bus => bus
  })
end
determine_capabilities(conn, previous_plugin_info) click to toggle source

Connect to the remote machine and determine the best available settings

# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 95
def determine_capabilities(conn, previous_plugin_info)
  plugin = get_plugin(previous_plugin_info)
  root = Nokogiri::XML.parse(conn.capabilities)
  guests = root.xpath("//guest/arch[@name='x86_64']/..")

  guests = guests.sort do |a, b|
    dom_maps = [a,b].map { |x| plugin.domain_map[xpath_first_intern(x, './/domain/@type')] }

    # Handle unknown mappings
    next resolve_unknowns(dom_maps) if dom_maps.include?(nil)

    # Compare according to domain ranking
    dom_rank = dom_maps.map { |m| m[:rank]}.reduce(:<=>)

    # Compare according to virtualisation ranking
    virt_rank = [a,b].enum_for(:each_with_index).map do |x, i|
      dom_maps[i][:domain].virt_map[xpath_first_intern(x, './/os_type')]
    end

    # Handle unknown mappings
    next resolve_unknowns(virt_rank) if virt_rank.include?(nil)

    # Domain rank first
    next dom_rank unless dom_rank == 0

    # OS type rank second
    virt_rank.reduce(:<=>)
  end
  # Favourite!
  build_guest(guests.first)
end
get_plugin(previous_plugin_info) click to toggle source

At present we don't have enough meta-data to work with to easily generalise, so we have to assume defaults often. This is something to improve later.

# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 151
def get_plugin(previous_plugin_info)
  if previous_plugin_info[:type] == :platform
    if PLUGINS.has_key?(previous_plugin_info[:name])
      @log.debug("Using #{previous_plugin_info[:name]} mapping")
      return PLUGINS[previous_plugin_info[:name]]
    else
      @log.debug("This plugin does not know what mappings to choose, so will assume default values where user values are not provided.")
    end
  end
  @log.debug("Using default domain mappings.")
  PLUGINS[:default]
end
resolve_unknowns(pair) click to toggle source
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 127
def resolve_unknowns(pair)
  return 0 if pair.first.nil? and pair.last.nil?
  return 1 if pair.first.nil?
  -1 if pair.last.nil?
end
xpath_first_intern(xml, path) click to toggle source
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 145
def xpath_first_intern(xml, path)
  xml.xpath(path).first.text.intern
end