Class: Fog::Compute::Libvirt::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Libvirt::Real
- Defined in:
- lib/fog/libvirt/compute.rb
Instance Attribute Summary collapse
-
#ip_command ⇒ Object
readonly
Returns the value of attribute ip_command.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #enhance_uri(uri) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#method_missing(method_sym, *arguments, &block) ⇒ Object
hack to provide ‘requests’.
- #respond_to?(method) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/libvirt/compute.rb', line 43 def initialize(={}) @uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri([:libvirt_uri])) @ip_command = [:libvirt_ip_command] # libvirt is part of the gem => ruby-libvirt require 'libvirt' begin if [:libvirt_username] and [:libvirt_password] @raw = ::Libvirt::open_auth(@uri.uri, [::Libvirt::CRED_AUTHNAME, ::Libvirt::CRED_PASSPHRASE]) do |cred| if cred['type'] == ::Libvirt::CRED_AUTHNAME res = [:libvirt_username] elsif cred["type"] == ::Libvirt::CRED_PASSPHRASE res = [:libvirt_password] else end end else @raw = ::Libvirt::open(@uri.uri) end rescue ::Libvirt::ConnectionError raise Fog::Errors::Error.new("Error making a connection to libvirt URI #{uri.uri}:\n#{$!}") end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
hack to provide ‘requests’
97 98 99 100 101 102 103 |
# File 'lib/fog/libvirt/compute.rb', line 97 def method_missing(method_sym, *arguments, &block) if @raw.respond_to?(method_sym) @raw.send(method_sym, *arguments) else super end end |
Instance Attribute Details
#ip_command ⇒ Object (readonly)
Returns the value of attribute ip_command.
40 41 42 |
# File 'lib/fog/libvirt/compute.rb', line 40 def ip_command @ip_command end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
38 39 40 |
# File 'lib/fog/libvirt/compute.rb', line 38 def raw @raw end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
39 40 41 |
# File 'lib/fog/libvirt/compute.rb', line 39 def uri @uri end |
Instance Method Details
#enhance_uri(uri) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fog/libvirt/compute.rb', line 70 def enhance_uri(uri) require 'cgi' append="" # on macosx, chances are we are using libvirt through homebrew # the client will default to a socket location based on it's own location (/opt) # we conveniently point it to /var/run/libvirt/libvirt-sock # if no socket option has been specified explicitly if RUBY_PLATFORM =~ /darwin/ querystring=::URI.parse(uri).query if querystring.nil? append="?socket=/var/run/libvirt/libvirt-sock" else if !::CGI.parse(querystring).has_key?("socket") append="&socket=/var/run/libvirt/libvirt-sock" end end end uri+append end |
#respond_to?(method) ⇒ Boolean
92 93 94 |
# File 'lib/fog/libvirt/compute.rb', line 92 def respond_to?(method, *) super or @connection.respond_to? method end |