Module: Hyperkit::Configurable

Included in:
Hyperkit, Client
Defined in:
lib/hyperkit/configurable.rb

Overview

Configuration options for Client, defaulting to values in Default

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_endpointString



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_syncString

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 to false 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.

Examples:

Create a container and automatically wait for it to complete (auto_sync is true by default)

Hyperkit.create_container("test-container", alias: "ubuntu/trusty/amd64")

Disable auto-synchronization at the module level

Hyperkit.auto_sync = false
op = Hyperkit.create_container("test-container", alias: "ubuntu/trusty/amd64")
Hyperkit.wait_for_operation(op.id)

Disable auto-synchronization at the class level

client = Hyperkit::Client.new(auto_sync: false)
op = client.create_container("test-container", alias: "ubuntu/trusty/amd64")
client.wait_for_operation(op.id)

Disable auto-synchronization, but enable it for one call by passing sync: true

Hyperkit.auto_sync = false
Hyperkit.create_container("test-container", alias: "ubuntu/trusty/amd64", sync: true)

Enable auto-synchronization, but disable it for one call by passing sync: false

Hyperkit.auto_sync = true
op = Hyperkit.create_container("test-container", alias: "ubuntu/trusty/amd64", sync: false)
Hyperkit.wait_for_operation(op.id)


94
95
96
# File 'lib/hyperkit/configurable.rb', line 94

def auto_sync
  @auto_sync
end

#client_certString



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_keyString



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_typeString



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

#middlewareFaraday::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

#proxyString

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_agentString



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_sslBoolean



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

.keysArray

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

Yields:

  • (_self)

Yield Parameters:



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.options[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 same_options?(opts)
  opts.hash == options.hash
end