Module: Miasma::Contrib::Lxd::Api

Included in:
Models::Compute::Lxd
Defined in:
lib/miasma/contrib/lxd.rb

Overview

API updates required for LXD communication

Constant Summary collapse

DEFAULT_API_VERSION =

Default API version to require

'1.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Load required attributes into API class

Parameters:

  • klass (Class)


15
16
17
18
19
20
21
22
23
24
# File 'lib/miasma/contrib/lxd.rb', line 15

def self.included(klass)
  klass.class_eval do
    attribute :name, String, :required => true, :default => Socket.gethostname
    attribute :password, String
    attribute :api_endpoint, String, :required => true
    attribute :ssl_certificate, String, :required => true
    attribute :ssl_key, String, :required => true
    attribute :version, Gem::Version, :coerce => lambda{|v| Gem::Version.new(v.to_s)}, :required => true, :default => lambda{ Miasma::Contrib::Lxd::Api::DEFAULT_API_VERSION }
  end
end

Instance Method Details

#custom_setup(args) ⇒ Object

Clean up endpoint prior to data loading

Parameters:

  • args (Hash)


34
35
36
37
38
# File 'lib/miasma/contrib/lxd.rb', line 34

def custom_setup(args)
  if(args[:api_endpoint].to_s.end_with?('/'))
    args[:api_endpoint] = args[:api_endpoint][0, endpoint.length - 1]
  end
end

#endpointString

Returns versioned endpoint.

Returns:

  • (String)

    versioned endpoint



27
28
29
# File 'lib/miasma/contrib/lxd.rb', line 27

def endpoint
  "#{api_endpoint}/#{version}"
end

#make_request(connection, http_method, request_args) ⇒ HTTP::Response

Perform request

Parameters:

  • connection (HTTP)
  • http_method (Symbol)
  • request_args (Array)

Returns:

  • (HTTP::Response)


46
47
48
49
50
51
# File 'lib/miasma/contrib/lxd.rb', line 46

def make_request(connection, http_method, request_args)
  dest, options = request_args
  options = Smash.new unless options
  options[:ssl_context] = ssl_context
  connection.send(http_method, dest, options)
end