Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 59 lines (53 sloc) 2.235 kb
1 2 3 4 5 6 7 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 52 53 54 55 56 57 58
# Author: John Alberts
#
# Plugin to give more information about the kvm host and guest

provides 'virtualization/kvm'
require_plugin 'virtualization'
if not virtualization.nil? and virtualization[:system] == 'kvm'
  if virtualization[:role] == 'host'
    guest_maxmemory_total=0
    guest_usedmemory_total=0
    guest_cpu_total=0
    virtualization[:kvm] = Mash.new unless virtualization[:kvm]
    virtualization[:kvm][:guests] = Mash.new unless virtualization[:kvm][:guests]
    %x{virsh list --all | grep -vP '\S*Id|^-|^$'}.each_line do |g|
      id, name, state = g.split
      virtualization[:kvm][:guests][name] = Mash.new
      virtualization[:kvm][:guests][name][:id] = id.strip
      virtualization[:kvm][:guests][name][:state] = state.strip
      # Let's parse dominfo for more guest information
      if "#{id}" == "-"
        domains = %x{virsh dominfo #{name} | grep -v 'Id:'}
      else
        domains = %x{virsh dominfo #{id} | grep -v 'Id:'}
      end
      domains.each_line do |l|
        k, v = l.split(":")
        virtualization[:kvm][:guests][name][k.strip] = v.strip unless v.nil?
        virtualization[:kvm][:guests][name][:vncdisplay] = sprintf("59%02d", %x(virsh vncdisplay #{id}).strip.gsub(/(\d+.\d+.\d+.\d+)?:/, '')).to_i unless "#{id}" == "-"
        case k.strip
        when 'CPU(s)'
          guest_cpu_total += v.strip.to_i
        when 'Max memory'
          guest_maxmemory_total += v.strip.to_i
        when 'Used memory'
          guest_usedmemory_total += v.strip.to_i
        end
      end
      virtualization[:kvm][:guest_cpu_total] = guest_cpu_total
      virtualization[:kvm][:guest_maxmemory_total] = guest_maxmemory_total.to_s + " kB"
      virtualization[:kvm][:guest_usedmemory_total] = guest_usedmemory_total.to_s + " kB"
    end

    # gather hardware details for the host
    virtualization[:kvm][:hardware] = Mash.new
    %x{virsh nodeinfo}.each_line do |detail|
      k,v = detail.split ":"
      virtualization[:kvm][:hardware][k.strip] = v.strip unless v.nil?
    end
    %x{virsh freecell}.each_line do |detail|
      k,v = detail.split ":"
      virtualization[:kvm][:hardware][:freecell] = v.strip unless v.nil?
    end

  elsif virtualization[:role] == 'guest'


  end
end
Something went wrong with that request. Please try again.