Class: Libvirt::Node

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

Overview

Represents a node which libvirt resides on.

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ Node

Initializes a node object with the given Connection pointer. This shouldn't be called directly. Instead, retrieve the node using Connection#node.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/libvirt/node.rb', line 7

def initialize(pointer)
  # This pointer can either be a `virConnectPtr` directly or a
  # {Connection} since it implements `to_ptr`.
  @pointer = pointer

  # We increase the reference count on the connection while this
  # node object is in use.
  FFI::Libvirt.virConnectRef(connection)

  # Register finalizer for reference cleanup
  ObjectSpace.define_finalizer(self, method(:finalize))
end

Instance Method Details

#connectionConnection

Returns the connection this node belongs to as a Connection object.

Returns:



24
25
26
# File 'lib/libvirt/node.rb', line 24

def connection
  @connection ||= @pointer.is_a?(Connection) ? @pointer : Connection.new(@pointer)
end

#coresInteger

Returns the number of cores per socket.

Returns:

  • (Integer)


88
89
90
# File 'lib/libvirt/node.rb', line 88

def cores
  info[:cores]
end

#cpu_modelString

Returns the CPU model of the node.

Returns:

  • (String)


46
47
48
# File 'lib/libvirt/node.rb', line 46

def cpu_model
  info[:model]
end

#cpusInteger

Returns the number of active CPUs.

Returns:

  • (Integer)


60
61
62
# File 'lib/libvirt/node.rb', line 60

def cpus
  info[:cpus]
end

#devicesCollection::NodeDeviceCollection

Returns the devices connected to this node.



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

def devices
  Collection::NodeDeviceCollection.new(connection)
end

#free_memoryInteger

Returns the free memory available on the node. This is returned in bytes.

Returns:

  • (Integer)


39
40
41
# File 'lib/libvirt/node.rb', line 39

def free_memory
  FFI::Libvirt.virNodeGetFreeMemory(connection)
end

#memoryInteger

Returns the memory size in kilobytes.

Returns:

  • (Integer)


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

def memory
  info[:memory]
end

#mhzInteger

Returns the expected CPU frequency in MHz.

Returns:

  • (Integer)


67
68
69
# File 'lib/libvirt/node.rb', line 67

def mhz
  info[:mhz]
end

#nodesInteger

Returns the number of NUMA cell, 1 for uniform memory access.

Returns:

  • (Integer)


74
75
76
# File 'lib/libvirt/node.rb', line 74

def nodes
  info[:nodes]
end

#socketsInteger

Returns the number of CPU sockets per node.

Returns:

  • (Integer)


81
82
83
# File 'lib/libvirt/node.rb', line 81

def sockets
  info[:sockets]
end

#threadsInteger

Returns the number of threads per core.

Returns:

  • (Integer)


95
96
97
# File 'lib/libvirt/node.rb', line 95

def threads
  info[:threads]
end