class Virt::Host

Attributes

connection[R]

Represents a Physical host which runs the libvirt daemon

Public Class Methods

new() click to toggle source
# File lib/virt/host.rb, line 6
def initialize
  @connection = Virt.connection.connection
end

Public Instance Methods

defined_guests() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
guests() click to toggle source
# File lib/virt/host.rb, line 14
def guests
  {:running => running_guests, :defined => defined_guests}
end
name() click to toggle source
# File lib/virt/host.rb, line 10
def name
  connection.hostname
end
running_guests() click to toggle source
# 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) click to toggle source

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

# 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_pools() click to toggle source
# File lib/virt/host.rb, line 29
def storage_pools
  connection.list_storage_pools.map {|p| create_pool({:name => p})}
end
volumes() click to toggle source

Returns a hash of pools and their volumes objects.

# File lib/virt/host.rb, line 40
def volumes
  pools = {}
  storage_pools.each do |storage|
    pools[storage.name] = storage.volumes
  end
  pools
end

Protected Instance Methods

create_guest(opts) click to toggle source
# File lib/virt/host.rb, line 62
def create_guest opts
  Virt::Guest.new opts
end
create_pool(opts) click to toggle source
# File lib/virt/host.rb, line 66
def create_pool opts
  Virt::Pool.new opts
end