Module: Hyperkit::Configurable
Overview
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
The base URL for API requests (default:
https://localhost:8443/
). -
#auto_sync ⇒ String
Whether to automatically wait for asynchronous operations to complete.
-
#client_cert ⇒ String
The client certificate used to authenticate to the LXD server.
-
#client_key ⇒ String
The client key used to authenticate to the LXD server.
-
#default_media_type ⇒ String
The preferred media type (for API versioning, for example).
-
#middleware ⇒ Faraday::Builder or Faraday::RackBuilder
Middleware for Faraday.
-
#proxy ⇒ String
The URI of a proxy server used to connect to the LXD server.
-
#user_agent ⇒ String
The
User-Agent
header used for requests made to the LXD server. -
#verify_ssl ⇒ Boolean
Whether or not to verify the LXD server’s SSL certificate.
Class Method Summary collapse
-
.keys ⇒ Array
List of configurable keys for Client.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Set configuration options using a block.
-
#reset! ⇒ Object
(also: #setup)
Reset configuration options to default values.
-
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options.
Instance Attribute Details
#api_endpoint ⇒ String
Returns the base URL for API requests (default: https://localhost:8443/
).
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#auto_sync ⇒ String
Whether to automatically wait for asynchronous operations to complete
A good deal of the LXD API calls are asynchronous: you issue the call, and you receive an operation ID. You must then wait on the operation to complete. Each asynchronous method is marked as such in the Hyperkit documentation.
By default, Hyperkit provides auto-synchronization. When you initiate an asynchronous operation, Hyperkit will automatically wait for the operation to complete before returning. If you wish to override this functionality, there are two ways to do this:
-
Pass
sync: false
to any of the asynchronous methods -
Set
auto_sync
tofalse
at the module or class level (see examples)
Any asynchronous calls you issue after setting auto_sync
to false
will immediately return an operation ID instead of blocking. To ensure that an operation is complete, you will need to call Hyperkit::Client::Operations#wait_for_operation.
Most users will likely want to keep auto_sync
enabled for convenience.
94 95 96 |
# File 'lib/hyperkit/configurable.rb', line 94 def auto_sync @auto_sync end |
#client_cert ⇒ String
Returns the client certificate used to authenticate to the LXD server.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#client_key ⇒ String
Returns the client key used to authenticate to the LXD server.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#default_media_type ⇒ String
Returns the preferred media type (for API versioning, for example).
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#middleware ⇒ Faraday::Builder or Faraday::RackBuilder
Returns middleware for Faraday.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#proxy ⇒ String
Returns the URI of a proxy server used to connect to the LXD server.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#user_agent ⇒ String
Returns the User-Agent
header used for requests made to the LXD server.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
#verify_ssl ⇒ Boolean
Returns whether or not to verify the LXD server’s SSL certificate.
94 95 |
# File 'lib/hyperkit/configurable.rb', line 94 attr_accessor :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl |
Class Method Details
.keys ⇒ Array
List of configurable keys for Hyperkit::Client
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hyperkit/configurable.rb', line 103 def keys @keys ||= [ :api_endpoint, :auto_sync, :client_cert, :client_key, :default_media_type, :middleware, :proxy, :user_agent, :verify_ssl ] end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Set configuration options using a block
120 121 122 |
# File 'lib/hyperkit/configurable.rb', line 120 def configure yield self end |
#reset! ⇒ Object Also known as: setup
Reset configuration options to default values
125 126 127 128 129 130 |
# File 'lib/hyperkit/configurable.rb', line 125 def reset! Hyperkit::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", Hyperkit::Default.[key]) end self end |
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options
138 139 140 |
# File 'lib/hyperkit/configurable.rb', line 138 def (opts) opts.hash == .hash end |