Class: OneviewSDK::ImageStreamer::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/oneview-sdk/image-streamer/client.rb

Overview

The client defines the connection to the Image Streamer server and handles communication with it.

Constant Summary

Constants included from Rest

Rest::READ_TIMEOUT, Rest::RESPONSE_CODE_ACCEPTED, Rest::RESPONSE_CODE_BAD_REQUEST, Rest::RESPONSE_CODE_CREATED, Rest::RESPONSE_CODE_NOT_FOUND, Rest::RESPONSE_CODE_NO_CONTENT, Rest::RESPONSE_CODE_OK, Rest::RESPONSE_CODE_UNAUTHORIZED

Instance Attribute Summary

Attributes inherited from Client

#api_version, #cert_store, #domain, #log_level, #logger, #max_api_version, #password, #print_wait_dots, #ssl_enabled, #timeout, #token, #url, #user

Instance Method Summary collapse

Methods inherited from Client

#create, #delete, #destroy_session, #new_i3s_client, #refresh, #refresh_login, #update, #wait_for

Methods included from Rest

#download_file, #response_handler, #rest_api, #rest_delete, #rest_get, #rest_patch, #rest_post, #rest_put, #upload_file

Constructor Details

#initialize(options = {}) ⇒ Client

Creates client object, establish connection, and set up logging and api version.

Parameters:

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

    the options to configure the client

Options Hash (options):

  • :logger (Logger) — default: Logger.new(STDOUT)

    Logger object to use. Must implement debug(String), info(String), warn(String), error(String), & level=

  • :log_level (Symbol) — default: :info

    Log level. Logger must define a constant with this name. ie Logger::INFO

  • :print_wait_dots (Boolean) — default: false

    When true, prints status dots while waiting on the tasks to complete.

  • :url (String)

    URL of Image Streamer

  • :token (String) — default: ENV['ONEVIEWSDK_TOKEN']

    The token to use for authentication

  • :api_version (Integer) — default: 300

    This is the API version to use by default for requests

  • :ssl_enabled (Boolean) — default: true

    Use ssl for requests? Respects ENV

  • :timeout (Integer) — default: nil

    Override the default request timeout value

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/oneview-sdk/image-streamer/client.rb', line 38

def initialize(options = {})
  options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
  STDOUT.sync = true
  @logger = options[:logger] || Logger.new(STDOUT)
  [:debug, :info, :warn, :error, :level=].each { |m| raise InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
  self.log_level = options[:log_level] || :info
  @print_wait_dots = options.fetch(:print_wait_dots, false)
  @url = options[:url] || ENV['I3S_URL']
  raise InvalidClient, 'Must set the url option' unless @url
  @max_api_version = appliance_i3s_api_version
  if options[:api_version] && options[:api_version].to_i > @max_api_version
    logger.warn "API version #{options[:api_version]} is greater than the Image Streamer API version (#{@max_api_version})"
  end
  @api_version = options[:api_version] || [OneviewSDK::ImageStreamer::DEFAULT_API_VERSION, @max_api_version].min
  # Set the default Image Streamer module API version
  OneviewSDK::ImageStreamer.api_version = @api_version unless
    OneviewSDK::ImageStreamer.api_version_updated? || !OneviewSDK::ImageStreamer::SUPPORTED_API_VERSIONS.include?(@api_version)
  @ssl_enabled = true
  if ENV.key?('I3S_SSL_ENABLED')
    if %w(true false 1 0).include?(ENV['I3S_SSL_ENABLED'])
      @ssl_enabled = !%w(false 0).include?(ENV['I3S_SSL_ENABLED'])
    else
      @logger.warn "Unrecognized ssl_enabled value '#{ENV['I3S_SSL_ENABLED']}'. Valid options are 'true' & 'false'"
    end
  end
  @ssl_enabled = options[:ssl_enabled] unless options[:ssl_enabled].nil?
  @timeout = options[:timeout] unless options[:timeout].nil?
  @cert_store = OneviewSDK::SSLHelper.load_trusted_certs if @ssl_enabled
  raise InvalidClient, 'Must set token option' unless options[:token] || ENV['ONEVIEWSDK_TOKEN']
  @token = options[:token] || ENV['ONEVIEWSDK_TOKEN']
end

Instance Method Details

#get_all(type, api_ver = @api_version) ⇒ Array<Resource>

Get array of all resources of a specified type

Examples:

Get all Deployment Plans

deployment_plans = @client.get_all('DeploymentPlans')

Parameters:

  • type (String)

    Resource type

  • api_ver (Integer) (defaults to: @api_version)

    API module version to fetch resources from

Returns:

Raises:

  • (TypeError)

    if the type is invalid



77
78
79
80
81
# File 'lib/oneview-sdk/image-streamer/client.rb', line 77

def get_all(type, api_ver = @api_version)
  klass = OneviewSDK::ImageStreamer.resource_named(type, api_ver)
  raise TypeError, "Invalid resource type '#{type}'. OneviewSDK::ImageStreamer::API#{api_ver} does not contain a class like it." unless klass
  klass.get_all(self)
end