Module: Collins::Api

Includes:
Admin, Asset, AssetState, AssetType, Attributes, IpAddress, Logging, Management, Tag, Util, Util
Included in:
Client
Defined in:
lib/collins/api.rb,
lib/collins/api/tag.rb,
lib/collins/api/util.rb,
lib/collins/api/admin.rb,
lib/collins/api/asset.rb,
lib/collins/api/logging.rb,
lib/collins/api/asset_type.rb,
lib/collins/api/attributes.rb,
lib/collins/api/ip_address.rb,
lib/collins/api/management.rb,
lib/collins/api/asset_state.rb,
lib/collins/api/util/errors.rb,
lib/collins/api/util/requests.rb,
lib/collins/api/util/responses.rb,
lib/collins/api/util/parameters.rb

Defined Under Namespace

Modules: Admin, Asset, AssetState, AssetType, Attributes, IpAddress, Logging, Management, Tag, Util

Constant Summary

Constants included from Util::Logging

Util::Logging::DEFAULT_LOG_FORMAT

Instance Method Summary collapse

Methods included from Util

#ping

Methods included from Tag

#get_all_tags, #get_tag_values

Methods included from Util

#deep_copy_hash, #get_asset_or_tag, included, #require_non_empty, #require_that, #stringify_hash, #symbolize_hash

Methods included from Util::Logging

#get_logger

Methods included from Management

#ipmi_create, #ipmi_update, #power!, #power_status, #provision, #provisioning_profiles

Methods included from Logging

#all_logs, #get_log, #log!, #logs, #search_logs

Methods included from IpAddress

#addresses_for_asset, #asset_at_address, #assets_in_pool, #ipaddress_allocate!, #ipaddress_delete!, #ipaddress_pools, #ipaddress_update!

Methods included from Attributes

#delete_attribute!, #set_attribute!, #set_multi_attribute!, #set_status!

Methods included from AssetType

#asset_type_create!, #asset_type_delete!, #asset_type_get, #asset_type_get_all, asset_type_test, asset_type_test=, #asset_type_update!

Methods included from AssetState

#state_create!, #state_delete!, #state_get, #state_get_all, state_test, state_test=, #state_update!

Methods included from Asset

#count, #create!, #delete!, #exists?, #find, #find_similar, #get, #search

Methods included from Admin

#repopulate_solr!

Instance Method Details

#clear_headersnil

Clear out all headers

Returns:

  • (nil)


76
77
78
# File 'lib/collins/api.rb', line 76

def clear_headers
  headers.clear # Yes, this returns an empty hash not nil
end

#headersHash<String,String>

This method is abstract.

Returns hash with header keys/values.

Returns:

  • (Hash<String,String>)

    hash with header keys/values

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/collins/api.rb', line 20

def headers
  raise NotImplementedError.new("Classes including the Api module must provide a headers hash")
end

#hostString

This method is abstract.

Returns the collins host.

Returns:

  • (String)

    the collins host

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/collins/api.rb', line 26

def host
  raise NotImplementedError.new("Classes including the Api module must provide a host")
end

#locationsHash<Symbol,OpenStruct>

This method is abstract.

Only used for multi-collins systems

Returns:

  • (Hash<Symbol,OpenStruct>)

    hash with keys as locations, values as collins credentials.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/collins/api.rb', line 33

def locations
  raise NotImplementedError.new("Classes including the Api module must provide a locations hash")
end

#loggerLogger

This method is abstract.

Returns a logger instance.

Returns:

  • (Logger)

    a logger instance

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/collins/api.rb', line 39

def logger
  raise NotImplementedError.new("Classes including the Api module must provide a logger")
end

#passwordString

This method is abstract.

Returns a password for authentication.

Returns:

  • (String)

    a password for authentication

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/collins/api.rb', line 45

def password
  raise NotImplementedError.new("Classes including the Api module must provide a password")
end

#set_header(key, value) ⇒ nil

Set a key/value in the headers hash

Parameters:

  • key (Symbol, String)
  • value (String)

Returns:

  • (nil)


85
86
87
# File 'lib/collins/api.rb', line 85

def set_header key, value
  headers.update(key => value)
end

#strict?(default = false) ⇒ Boolean

This method is abstract.

How to deal with unexpected API responses

When true, API methods will throw an exception if an unexpected response is encountered. When false, API methods will usually normalize responses to an appropriate value indicating failure.

Parameters:

  • default (Boolean) (defaults to: false)

Returns:

  • (Boolean)

    strict or not

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/collins/api.rb', line 58

def strict? default = false
  raise NotImplementedError.new("Classes including the Api module must provide a strict? method")
end

#timeout_iFixnum

This method is abstract.

Returns a timeout in seconds.

Returns:

  • (Fixnum)

    a timeout in seconds

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/collins/api.rb', line 64

def timeout_i
  raise NotImplementedError.new("Classes including the Api module must provide a timeout")
end

#trace(progname = nil, &block) ⇒ Object

Provides a safe wrapper for our monkeypatched logger

If the provided logger responds to a trace method, use that method. Otherwise fallback to using the debug method.



93
94
95
96
97
98
99
# File 'lib/collins/api.rb', line 93

def trace(progname = nil, &block)
  if logger.respond_to?(:trace) then
    logger.trace(progname, &block)
  else
    logger.debug(progname, &block)
  end
end

#use_api_version(version) ⇒ Object



101
102
103
# File 'lib/collins/api.rb', line 101

def use_api_version version
  set_header "Accept", "application/json,#{version_string(version)}"
end

#usernameString

This method is abstract.

Returns a username for authentication.

Returns:

  • (String)

    a username for authentication

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/collins/api.rb', line 70

def username
  raise NotImplementedError.new("Classes including the Api module must provide a username")
end