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
-
#clear_headers ⇒ nil
Clear out all headers.
-
#headers ⇒ Hash<String,String>
abstract
Hash with header keys/values.
-
#host ⇒ String
abstract
The collins host.
-
#locations ⇒ Hash<Symbol,OpenStruct>
abstract
Only used for multi-collins systems.
-
#logger ⇒ Logger
abstract
A logger instance.
-
#password ⇒ String
abstract
A password for authentication.
-
#set_header(key, value) ⇒ nil
Set a key/value in the headers hash.
-
#strict?(default = false) ⇒ Boolean
abstract
How to deal with unexpected API responses.
-
#timeout_i ⇒ Fixnum
abstract
A timeout in seconds.
-
#trace(progname = nil, &block) ⇒ Object
Provides a safe wrapper for our monkeypatched logger.
- #use_api_version(version) ⇒ Object
-
#username ⇒ String
abstract
A username for authentication.
Methods included from Util
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
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
Instance Method Details
#clear_headers ⇒ nil
Clear out all headers
76 77 78 |
# File 'lib/collins/api.rb', line 76 def clear_headers headers.clear # Yes, this returns an empty hash not nil end |
#headers ⇒ Hash<String,String>
Returns hash with header keys/values.
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 |
#host ⇒ String
Returns the collins host.
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 |
#locations ⇒ Hash<Symbol,OpenStruct>
Only used for multi-collins systems
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 |
#logger ⇒ Logger
Returns a logger instance.
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 |
#password ⇒ String
Returns a password for authentication.
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
85 86 87 |
# File 'lib/collins/api.rb', line 85 def set_header key, value headers.update(key => value) end |
#strict?(default = false) ⇒ Boolean
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.
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_i ⇒ Fixnum
Returns a timeout in seconds.
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 |
#username ⇒ String
Returns a username for authentication.
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 |