Class: Collins::Client

Inherits:
Object
  • Object
show all
Includes:
Api, Util, HTTParty
Defined in:
lib/collins/client.rb

Overview

Primary interface for interacting with collins

Examples:

client = Collins::Client.new :host => '...', :username => '...', :password => '...'
client.get 'asset_tag'

Constant Summary

Constants included from Util::Logging

Util::Logging::DEFAULT_LOG_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Api

#clear_headers, #set_header, #trace, #use_api_version

Methods included from Api::Util

#ping

Methods included from Api::Tag

#get_all_tags, #get_tag_values

Methods included from Api::Management

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

Methods included from Api::Logging

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

Methods included from Api::Ipmi

#ipmi_pools

Methods included from Api::IpAddress

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

Methods included from Api::Attributes

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

Methods included from Api::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 Api::AssetState

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

Methods included from Api::Asset

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

Methods included from Api::Admin

#repopulate_solr!

Constructor Details

#initialize(options = {}) ⇒ Client

Create a collins client instance

Parameters:

  • options (Hash) (defaults to: {})

    host, username and password are required

Options Hash (options):

  • :host (String)

    a scheme, hostname and port (e.g. hostname)

  • :logger (Logger)

    a logger to use, one is created if none is specified

  • :timeout (Fixnum) — default: 10

    timeout in seconds to wait for a response

  • :username (String)

    username for authentication

  • :password (String)

    password for authentication

  • :managed_process (String)
  • :strict (Boolean) — default: false

    see #strict



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/collins/client.rb', line 44

def initialize options = {}
  config = symbolize_hash options
  @locations = {}
  @headers = {}
  @host = fix_hostname(config.fetch(:host, ""))
  @logger = get_logger config.merge(:progname => 'Collins_Client')
  @timeout_i = config.fetch(:timeout, 10).to_i
  @username = config.fetch(:username, "")
  @password = config.fetch(:password, "")
  @strict = config.fetch(:strict, false)
  @managed_process = config.fetch(:managed_process, nil)
  require_non_empty(@host, "Collins::Client host must be specified")
  require_non_empty(@username, "Collins::Client username must be specified")
  require_non_empty(@password, "Collins::Client password must be specified")
end

Instance Attribute Details

#headersObject (readonly)

See Also:



15
16
17
# File 'lib/collins/client.rb', line 15

def headers
  @headers
end

#hostObject (readonly)

See Also:



17
18
19
# File 'lib/collins/client.rb', line 17

def host
  @host
end

#locationsObject (readonly)

See Also:



19
20
21
# File 'lib/collins/client.rb', line 19

def locations
  @locations
end

#loggerObject (readonly)

See Also:



21
22
23
# File 'lib/collins/client.rb', line 21

def logger
  @logger
end

#passwordObject (readonly)

See Also:



25
26
27
# File 'lib/collins/client.rb', line 25

def password
  @password
end

#strictBoolean (readonly)

Returns strict mode throws exceptions when unexpected responses occur.

Returns:

  • (Boolean)

    strict mode throws exceptions when unexpected responses occur



27
28
29
# File 'lib/collins/client.rb', line 27

def strict
  @strict
end

#timeout_iObject (readonly)

See Also:



23
24
25
# File 'lib/collins/client.rb', line 23

def timeout_i
  @timeout_i
end

#usernameObject (readonly)

See Also:



29
30
31
# File 'lib/collins/client.rb', line 29

def username
  @username
end

Instance Method Details

#manage_process(name = nil) ⇒ Collins::ManagedState::Mixin

Interact with a collins managed process

Parameters:

  • name (String) (defaults to: nil)

    Name of process

Returns:

  • (Collins::ManagedState::Mixin)

    see mixin for more information

Raises:

  • (CollinsError)

    if no managed process is specified/found



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/collins/client.rb', line 64

def manage_process name = nil
  name = @managed_process if name.nil?
  if name then
    begin
      Collins.const_get(name).new(self).run
    rescue Exception => e
      raise CollinsError.new(e.message)
    end
  else
    raise CollinsError.new("No managed process specified")
  end
end

#strict?(default = false) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



83
84
85
# File 'lib/collins/client.rb', line 83

def strict? default = false
  @strict || default
end

#to_sString

Returns Collins::Client(host = hostname).

Returns:

  • (String)

    Collins::Client(host = hostname)



78
79
80
# File 'lib/collins/client.rb', line 78

def to_s
  "Collins::Client(host = #{@host})"
end

#with_asset(asset) ⇒ Collins::AssetClient

Use the specified asset for subsequent method calls

Parameters:

Returns:



90
91
92
# File 'lib/collins/client.rb', line 90

def with_asset asset
  Collins::AssetClient.new(asset, self, @logger)
end