Class: Libvirt::Connect
- Inherits:
-
Object
- Object
- Libvirt::Connect
- 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
-
#arch ⇒ Object
Returns CPU architecture.
-
#cores ⇒ Object
Returns number of cores as string.
-
#cpus ⇒ Object
Returns number of CPUs as string.
-
#domains ⇒ Object
Returns array of domain objects.
-
#ghz ⇒ Object
Returns clock speed in GHz.
-
#mem ⇒ Object
Returns total memory in mebibytes as string.
-
#memfree ⇒ Object
Returns memory which is not allocated to virtual machines in mebibytes as string.
-
#version ⇒ Object
Returns the libvirt version number.
Instance Method Details
#arch ⇒ Object
Returns CPU architecture.
31 32 33 |
# File 'lib/libvirt/connect.rb', line 31 def arch self.node_get_info.model end |
#cores ⇒ Object
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 |
#cpus ⇒ Object
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 |
#domains ⇒ Object
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 |
#ghz ⇒ Object
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 |
#mem ⇒ Object
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 |
#memfree ⇒ Object
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 |
#version ⇒ Object
Returns the libvirt version number.
53 54 55 |
# File 'lib/libvirt/connect.rb', line 53 def version self.libversion.to_s end |