# 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
# File lib/virt/connection.rb, line 26 def closed? connection.closed? end
# File lib/virt/connection.rb, line 38 def disconnect connection.close end
# 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
# File lib/virt/connection.rb, line 30 def secure? connection.encrypted? end
# File lib/virt/connection.rb, line 34 def version connection.libversion end