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
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
Connect to the remote machine and determine the best available settings