class OneviewSDK::ImageStreamer::Client
The client defines the connection to the Image Streamer server and handles communication with it.
Public Class Methods
Creates client object, establish connection, and set up logging and api version. @param [Hash] options the options to configure the client @option options [Logger] :logger (Logger.new(STDOUT)) Logger object to use.
Must implement debug(String), info(String), warn(String), error(String), & level=
@option options [Symbol] :log_level (:info) Log level. Logger must define a constant with this name. ie Logger::INFO @option options [Boolean] :print_wait_dots (false) When true, prints status dots while waiting on the tasks to complete. @option options [String] :url URL of Image Streamer @option options [String] :token (ENV) The token to use for authentication @option options [Integer] :api_version (300) This is the API version to use by default for requests @option options [Boolean] :ssl_enabled (true) Use ssl for requests? Respects ENV @option options [Integer] :timeout (nil) Override the default request timeout value
# 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) %i[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
Public Instance Methods
Get array of all resources of a specified type @param [String] type Resource
type @param [Integer] api_ver API module version to fetch resources from @return [Array<Resource>] Results @example Get all Deployment Plans
deployment_plans = @client.get_all('DeploymentPlans')
@raise [TypeError] if the type is invalid
# 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
Private Instance Methods
Get current api version from the Image Streamer
# File lib/oneview-sdk/image-streamer/client.rb, line 86 def appliance_i3s_api_version options = { 'Content-Type' => :none, 'X-API-Version' => :none, 'auth' => :none } response = rest_api(:get, '/rest/version', options) version = response_handler(response)['currentVersion'] raise ConnectionError, "Couldn't get API version" unless version version = version.to_i if version.class != Integer version rescue ConnectionError @logger.warn "Failed to get Image Streamer max api version. Using default (#{OneviewSDK::ImageStreamer::DEFAULT_API_VERSION})" OneviewSDK::ImageStreamer::DEFAULT_API_VERSION end