Class: Libvirt::Domain
- Inherits:
-
Object
- Object
- Libvirt::Domain
- Defined in:
- lib/libvirt/domain.rb
Overview
Extend Libvirt::Domain with different methods for human readable display of the domain state.
Instance Method Summary collapse
-
#cpu_num ⇒ Object
Return the number of assigned virtual CPUs as string.
-
#cpu_time ⇒ Object
Return time the virtual domain’s CPU was scheduled as string formatted d-hh:mm:ss.
-
#mem ⇒ Object
Return current memory assignment in mebibytes as string.
-
#mem_max ⇒ Object
Return maximum memory assignment in mebibytes as string.
-
#state ⇒ Object
Return state as string symbol.
-
#to_s ⇒ Object
Default string representation of domain object is the domain’s name.
Instance Method Details
#cpu_num ⇒ Object
Return the number of assigned virtual CPUs as string.
26 27 28 |
# File 'lib/libvirt/domain.rb', line 26 def cpu_num self.info.nr_virt_cpu.to_s end |
#cpu_time ⇒ Object
Return time the virtual domain’s CPU was scheduled as string formatted d-hh:mm:ss.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/libvirt/domain.rb', line 32 def cpu_time t = self.info.cpu_time / 10**9 s = (t % 60 ).to_s m = (t / 60 % 60 ).to_s h = (t / 60 / 60 % 24 ).to_s d = (t / 60 / 60 / 24 % 365).to_s "%i-%02i:%02i:%02i" % [d, h, m, s] end |
#mem ⇒ Object
Return current memory assignment in mebibytes as string.
16 17 18 |
# File 'lib/libvirt/domain.rb', line 16 def mem (self.info.memory / 1024).to_s + "M" end |
#mem_max ⇒ Object
Return maximum memory assignment in mebibytes as string.
21 22 23 |
# File 'lib/libvirt/domain.rb', line 21 def mem_max (self.info.max_mem / 1024).to_s + "M" end |
#state ⇒ Object
Return state as string symbol.
10 11 12 13 |
# File 'lib/libvirt/domain.rb', line 10 def state states = ['none', 'run', 'block', 'pause', 'halting', 'off', 'crash'] states[self.info.state] end |
#to_s ⇒ Object
Default string representation of domain object is the domain’s name.
5 6 7 |
# File 'lib/libvirt/domain.rb', line 5 def to_s self.name end |