Class: OneviewSDK::ImageStreamer::Client
- 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
-
#get_all(type, api_ver = @api_version) ⇒ Array<Resource>
Get array of all resources of a specified type.
-
#initialize(options = {}) ⇒ Client
constructor
Creates client object, establish connection, and set up logging and api version.
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.
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( = {}) = Hash[.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols STDOUT.sync = true @logger = [: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 = [:log_level] || :info @print_wait_dots = .fetch(:print_wait_dots, false) @url = [:url] || ENV['I3S_URL'] raise InvalidClient, 'Must set the url option' unless @url @max_api_version = appliance_i3s_api_version if [:api_version] && [:api_version].to_i > @max_api_version logger.warn "API version #{[:api_version]} is greater than the Image Streamer API version (#{@max_api_version})" end @api_version = [: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 = [:ssl_enabled] unless [:ssl_enabled].nil? @timeout = [:timeout] unless [:timeout].nil? @cert_store = OneviewSDK::SSLHelper.load_trusted_certs if @ssl_enabled raise InvalidClient, 'Must set token option' unless [:token] || ENV['ONEVIEWSDK_TOKEN'] @token = [: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
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 |