Module: Collins::Api
- Includes:
- Admin, Asset, AssetState, AssetType, Attributes, IpAddress, Ipmi, Logging, Management, Tag, Util, Util
- Included in:
- Client
- Defined in:
- lib/collins/api.rb,
lib/collins/api/tag.rb,
lib/collins/api/ipmi.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, Ipmi, 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_allocate, #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 Ipmi
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
77 78 79 |
# File 'lib/collins/api.rb', line 77 def clear_headers headers.clear # Yes, this returns an empty hash not nil end |
#headers ⇒ Hash<String,String>
Returns hash with header keys/values.
21 22 23 |
# File 'lib/collins/api.rb', line 21 def headers raise NotImplementedError.new("Classes including the Api module must provide a headers hash") end |
#host ⇒ String
Returns the collins host.
27 28 29 |
# File 'lib/collins/api.rb', line 27 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
34 35 36 |
# File 'lib/collins/api.rb', line 34 def locations raise NotImplementedError.new("Classes including the Api module must provide a locations hash") end |
#logger ⇒ Logger
Returns a logger instance.
40 41 42 |
# File 'lib/collins/api.rb', line 40 def logger raise NotImplementedError.new("Classes including the Api module must provide a logger") end |
#password ⇒ String
Returns a password for authentication.
46 47 48 |
# File 'lib/collins/api.rb', line 46 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
86 87 88 |
# File 'lib/collins/api.rb', line 86 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.
59 60 61 |
# File 'lib/collins/api.rb', line 59 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.
65 66 67 |
# File 'lib/collins/api.rb', line 65 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.
94 95 96 97 98 99 100 |
# File 'lib/collins/api.rb', line 94 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
102 103 104 |
# File 'lib/collins/api.rb', line 102 def use_api_version version set_header "Accept", "application/json,#{version_string(version)}" end |
#username ⇒ String
Returns a username for authentication.
71 72 73 |
# File 'lib/collins/api.rb', line 71 def username raise NotImplementedError.new("Classes including the Api module must provide a username") end |