Class: Libvirt::Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt/connect.rb

Overview

Extend Libvirt::Connect with a method which returns all available domains as an array and several methods to access the host info more easily.

Instance Method Summary collapse

Instance Method Details

#archObject

Returns CPU architecture.



31
32
33
# File 'lib/libvirt/connect.rb', line 31

def arch
  self.node_get_info.model
end

#coresObject

Returns number of cores as string.



16
17
18
# File 'lib/libvirt/connect.rb', line 16

def cores
  self.node_get_info.cores.to_s
end

#cpusObject

Returns number of CPUs as string.



21
22
23
# File 'lib/libvirt/connect.rb', line 21

def cpus
  self.node_get_info.cpus.to_s
end

#domainsObject

Returns array of domain objects.



5
6
7
8
9
10
11
12
13
# File 'lib/libvirt/connect.rb', line 5

def domains
  ret = Array.new

  self.list_domains.each do |id|
    ret.push self.lookup_domain_by_id id
  end

  ret
end

#ghzObject

Returns clock speed in GHz.



26
27
28
# File 'lib/libvirt/connect.rb', line 26

def ghz
  "%.2f" % (self.node_get_info.mhz / 1000.0)
end

#memObject

Returns total memory in mebibytes as string.



36
37
38
# File 'lib/libvirt/connect.rb', line 36

def mem
  (self.node_get_info.memory / 1024).to_s + 'M'
end

#memfreeObject

Returns memory which is not allocated to virtual machines in mebibytes as string.



42
43
44
45
46
47
48
49
50
# File 'lib/libvirt/connect.rb', line 42

def memfree
  memUsed = 0

  self.domains.each do |domain|
    memUsed += domain.info.memory
  end

  ((self.node_get_info.memory - memUsed) / 1024).to_s + 'M'
end

#versionObject

Returns the libvirt version number.



53
54
55
# File 'lib/libvirt/connect.rb', line 53

def version
  self.libversion.to_s
end