class Virt::Connection

Attributes

connection[R]
type[R]

Public Class Methods

new(uri, options = {}) click to toggle source
# File lib/virt/connection.rb, line 6
def initialize uri, options = {}
  raise("Must provide a host to connect to") unless uri
  if uri =~ %r^(esx|vpx)/
    raise("Must provide a username and password") unless options[:username] or options[:password]
    @connection = Libvirt::open_auth(uri, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) do |cred|
      # This may only be required for ESXi connections, not sure.
      @type = "VMWare"
      case cred['type']
      when ::Libvirt::CRED_AUTHNAME
        options[:username]
      when ::Libvirt::CRED_PASSPHRASE
        options[:password]
      end
    end
  else
    @type = "KVM"
    @connection = Libvirt::open uri
  end
end

Public Instance Methods

closed?() click to toggle source
# File lib/virt/connection.rb, line 26
def closed?
  connection.closed?
end
disconnect() click to toggle source
# File lib/virt/connection.rb, line 38
def disconnect
  connection.close
end
host() click to toggle source
# File lib/virt/connection.rb, line 42
def host
  case type
  when "KVM"
    KVM::Host.new
  when "VMWare"
    VMWare::Host.new
  else
    raise "Non supported hypervisor"
  end
end
secure?() click to toggle source
# File lib/virt/connection.rb, line 30
def secure?
  connection.encrypted?
end
version() click to toggle source
# File lib/virt/connection.rb, line 34
def version
  connection.libversion
end