| Path: | lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb |
| Last Update: | Mon Dec 19 21:34:07 +0000 2011 |
Copyright 2010 Red Hat, Inc.
This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: www.fsf.org.
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 90
90: def initialize(opts={})
91: @log = opts[:log] || LogHelper.new
92: end
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 133
133: def build_guest(xml)
134: dom = DOMAINS[xpath_first_intern(xml, ".//domain/@type")]
135: bus = 'ide'
136: bus = dom.bus if dom
137:
138: OpenStruct.new({
139: :domain_type => xpath_first_intern(xml, ".//domain/@type"),
140: :os_type => xpath_first_intern(xml, './/os_type'),
141: :bus => bus
142: })
143: end
Connect to the remote machine and determine the best available settings
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 95
95: def determine_capabilities(conn, previous_plugin_info)
96: plugin = get_plugin(previous_plugin_info)
97: root = Nokogiri::XML.parse(conn.capabilities)
98: guests = root.xpath("//guest/arch[@name='x86_64']/..")
99:
100: guests = guests.sort do |a, b|
101: dom_maps = [a,b].map { |x| plugin.domain_map[xpath_first_intern(x, './/domain/@type')] }
102:
103: # Handle unknown mappings
104: next resolve_unknowns(dom_maps) if dom_maps.include?(nil)
105:
106: # Compare according to domain ranking
107: dom_rank = dom_maps.map { |m| m[:rank]}.reduce(:<=>)
108:
109: # Compare according to virtualisation ranking
110: virt_rank = [a,b].enum_for(:each_with_index).map do |x, i|
111: dom_maps[i][:domain].virt_map[xpath_first_intern(x, './/os_type')]
112: end
113:
114: # Handle unknown mappings
115: next resolve_unknowns(virt_rank) if virt_rank.include?(nil)
116:
117: # Domain rank first
118: next dom_rank unless dom_rank == 0
119:
120: # OS type rank second
121: virt_rank.reduce(:<=>)
122: end
123: # Favourite!
124: build_guest(guests.first)
125: end
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
151: def get_plugin(previous_plugin_info)
152: if previous_plugin_info[:type] == :platform
153: if PLUGINS.has_key?(previous_plugin_info[:name])
154: @log.debug("Using #{previous_plugin_info[:name]} mapping")
155: return PLUGINS[previous_plugin_info[:name]]
156: else
157: @log.debug("This plugin does not know what mappings to choose, so will assume default values where user values are not provided.")
158: end
159: end
160: @log.debug("Using default domain mappings.")
161: PLUGINS[:default]
162: end
# File lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb, line 127
127: def resolve_unknowns(pair)
128: return 0 if pair.first.nil? and pair.last.nil?
129: return 1 if pair.first.nil?
130: -1 if pair.last.nil?
131: end