Module: Occi::Api::Client::Base::ProtectedHelpers

Included in:
ClientBase
Defined in:
lib/occi/api/client/base/protected_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get_endpoint_uri(endpoint) ⇒ URI

Checks whether the given endpoint URI is valid and converts it to a URI instance.

Examples:

get_endpoint_uri "http://localhost:3300" # => #<URI::*>

33
34
35
36
37
38
39
40
41
42
43
# File 'lib/occi/api/client/base/protected_helpers.rb', line 33

def get_endpoint_uri(endpoint)
  unless endpoint =~ URI::ABS_URI
    raise "Endpoint not a valid absolute URI! #{endpoint.inspect}"
  end

  # normalize URIs, remove trailing slashes
  endpoint = URI(endpoint)
  endpoint.path = endpoint.path.gsub(/\/+/, '/').chomp('/')

  endpoint
end

#get_logger(log_options) ⇒ Occi::Api::Log

Sets the logger and log levels. This allows users to pass existing logger instances to the rOCCI client.

Examples:

get_logger { :out => STDERR, :level => Occi::Api::Log::WARN, :logger => nil }

14
15
16
17
18
19
20
21
22
23
# File 'lib/occi/api/client/base/protected_helpers.rb', line 14

def get_logger(log_options)
  unless log_options[:logger].kind_of?(Occi::Api::Log)
    logger = Occi::Api::Log.new(log_options[:out])
    logger.level = log_options[:level]
  else
    logger = log_options[:logger]
  end

  logger
end

#get_model(model_collection) ⇒ Occi::Model

Creates an Occi::Model from data retrieved from the server.

Examples:

model_collection = get('/-/')
get_model model_collection # => #<Occi::Model>

53
54
55
56
# File 'lib/occi/api/client/base/protected_helpers.rb', line 53

def get_model(model_collection)
  # build model
  Occi::Model.new(model_collection)
end

#get_os_tpl_mixins_aryArray

Returns mixin type identifiers for os_tpl mixins in an array.


62
63
64
65
# File 'lib/occi/api/client/base/protected_helpers.rb', line 62

def get_os_tpl_mixins_ary
  mixins = get_os_tpls
  mixins.to_a.collect { |m| m.type_identifier }
end

#get_resource_tpl_mixins_aryArray

Returns mixin type identifiers for resource_tpl mixins in an array.


71
72
73
74
# File 'lib/occi/api/client/base/protected_helpers.rb', line 71

def get_resource_tpl_mixins_ary
  mixins = get_resource_tpls
  mixins.to_a.collect { |m| m.type_identifier }
end