Class: Virt::Connection
- Inherits:
-
Object
- Object
- Virt::Connection
- Defined in:
- lib/virt/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #closed? ⇒ Boolean
- #disconnect ⇒ Object
- #host ⇒ Object
-
#initialize(uri, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #secure? ⇒ Boolean
- #version ⇒ Object
Constructor Details
#initialize(uri, options = {}) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/virt/connection.rb', line 6 def initialize uri, = {} raise("Must provide a host to connect to") unless uri if uri =~ /^(esx|vpx)/ raise("Must provide a username and password") unless [:username] or [: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 [:username] when ::Libvirt::CRED_PASSPHRASE [:password] end end else @type = "KVM" @connection = Libvirt::open uri end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/virt/connection.rb', line 4 def connection @connection end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/virt/connection.rb', line 4 def type @type end |
Instance Method Details
#closed? ⇒ Boolean
26 27 28 |
# File 'lib/virt/connection.rb', line 26 def closed? connection.closed? end |
#disconnect ⇒ Object
38 39 40 |
# File 'lib/virt/connection.rb', line 38 def disconnect connection.close end |
#host ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# 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? ⇒ Boolean
30 31 32 |
# File 'lib/virt/connection.rb', line 30 def secure? connection.encrypted? end |
#version ⇒ Object
34 35 36 |
# File 'lib/virt/connection.rb', line 34 def version connection.libversion end |