Class: Xen::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/xen/host.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detail_hash = {}) ⇒ Host

Returns a new instance of Host.



5
6
7
# File 'lib/xen/host.rb', line 5

def initialize(detail_hash={})
  detail_hash.each { |i,j| instance_variable_set("@#{i}", j) }
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/xen/host.rb', line 3

def host
  @host
end

#machineObject (readonly)

Returns the value of attribute machine.



3
4
5
# File 'lib/xen/host.rb', line 3

def machine
  @machine
end

#nr_cpusObject (readonly)

Returns the value of attribute nr_cpus.



3
4
5
# File 'lib/xen/host.rb', line 3

def nr_cpus
  @nr_cpus
end

#total_memoryObject (readonly)

Returns the value of attribute total_memory.



3
4
5
# File 'lib/xen/host.rb', line 3

def total_memory
  @total_memory
end

Class Method Details

.findObject



9
10
11
# File 'lib/xen/host.rb', line 9

def self.find
  new Xen::Command.xm_info
end

Instance Method Details

#domu_memoryObject



21
22
23
# File 'lib/xen/host.rb', line 21

def domu_memory
  Xen::Slice.find(:running).inject(0){|m, slice| m += slice.instance.memory.to_i; m}
end

#free_memoryObject



13
14
15
16
17
18
19
# File 'lib/xen/host.rb', line 13

def free_memory
  if f = `free -m`
    if (m = f.match /buffers\/cache.*\s+(\w+)\n/)
      m[1].to_i
    end
  end
end