Class: Virt::Host

Inherits:
Connection show all
Defined in:
lib/virt/host.rb

Direct Known Subclasses

KVM::Host, VMWare::Host

Instance Attribute Summary collapse

Attributes inherited from Connection

#type

Instance Method Summary collapse

Methods inherited from Connection

#closed?, #disconnect, #host, #secure?, #version

Constructor Details

#initializeHost

Returns a new instance of Host.



6
7
8
# File 'lib/virt/host.rb', line 6

def initialize
  @connection = Virt.connection.connection
end

Instance Attribute Details

#connectionObject (readonly)

Represents a Physical host which runs the libvirt daemon



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

def connection
  @connection
end

Instance Method Details

#defined_guestsObject



24
25
26
27
28
# File 'lib/virt/host.rb', line 24

def defined_guests
  connection.list_defined_domains.map do |domain|
    find_guest_by_name domain
  end
end

#find_guest_by_id(id) ⇒ Object



54
55
56
57
58
# File 'lib/virt/host.rb', line 54

def find_guest_by_id id
  Array(id).map do |did|
    return create_guest({:name => connection.lookup_domain_by_id(did).name})
  end
end

#find_guest_by_name(name) ⇒ Object



48
49
50
51
52
# File 'lib/virt/host.rb', line 48

def find_guest_by_name name
  if connection.lookup_domain_by_name name
    return create_guest({:name => name})
  end
end

#guestsObject



14
15
16
# File 'lib/virt/host.rb', line 14

def guests
  {:running => running_guests, :defined => defined_guests}
end

#nameObject



10
11
12
# File 'lib/virt/host.rb', line 10

def name
  connection.hostname
end

#running_guestsObject



18
19
20
21
22
# File 'lib/virt/host.rb', line 18

def running_guests
  connection.list_domains.map do |domain|
    find_guest_by_id(domain)
  end
end

#storage_pool(pool) ⇒ Object

Returns a Virt::Pool object based on the pool name



34
35
36
37
# File 'lib/virt/host.rb', line 34

def storage_pool pool
  create_pool({:name => pool.is_a?(Libvirt::StoragePool) ? pool.name : pool })
rescue Libvirt::RetrieveError
end

#storage_poolsObject



29
30
31
# File 'lib/virt/host.rb', line 29

def storage_pools
  connection.list_storage_pools.map {|p| create_pool({:name => p})}
end

#volumesObject

Returns a hash of pools and their volumes objects.



40
41
42
43
44
45
46
# File 'lib/virt/host.rb', line 40

def volumes
  pools = {}
  storage_pools.each do |storage|
    pools[storage.name] = storage.volumes
  end
  pools
end