class MiqVimClientBase

require 'profile'

Attributes

connId[R]
password[R]
port[R]
server[R]
username[R]

Public Class Methods

new(server:, username:, password:, port: 443, ssl_options: {}) click to toggle source
Calls superclass method VimService::new
# File lib/VMwareWebService/MiqVimClientBase.rb, line 13
def initialize(server:, username:, password:, port: 443, ssl_options: {})
  @server   = server
  @port     = port
  @username = username
  @password = password
  @connId   = "#{@server}_#{@username}"

  @receiveTimeout = @@receiveTimeout

  on_http_client_init do |http_client, _headers|
    http_client.receive_timeout        = @receiveTimeout
    http_client.ssl_config.verify_mode = ssl_options[:verify_ssl] || OpenSSL::SSL::VERIFY_NONE
    http_client.ssl_config.cert_store.add_cert(OpenSSL::X509::Certificate.new(ssl_options[:ca_file])) if ssl_options[:ca_file]
  end

  on_log_header { |msg| logger.info msg }
  on_log_body   { |msg| logger.debug msg } if $miq_wiredump

  super(:uri => sdk_uri, :version => 1)

  @connected  = false
  @connLock = Sync.new
end
receiveTimeout() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 45
def self.receiveTimeout
  @@receiveTimeout
end
receiveTimeout=(val) click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 41
def self.receiveTimeout=(val)
  @@receiveTimeout = val
end

Public Instance Methods

acquireCloneTicket() click to toggle source
Calls superclass method VimService#acquireCloneTicket
# File lib/VMwareWebService/MiqVimClientBase.rb, line 84
def acquireCloneTicket
  super(@sic.sessionManager)
end
connect() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 62
def connect
  logger.debug { "#{self.class.name}.connect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" }
  @connLock.synchronize(:EX) do
    return if @connected
    login(@sic.sessionManager, @username, @password)
    @connected = true
  end
end
currentServerTime() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 80
def currentServerTime
  DateTime.parse(currentTime)
end
disconnect() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 71
def disconnect
  logger.debug { "#{self.class.name}.disconnect(#{@connId}): #{$PROGRAM_NAME} #{ARGV.join(' ')}" }
  @connLock.synchronize(:EX) do
    return unless @connected
    logout(@sic.sessionManager)
    @connected = false
  end
end
receiveTimeout() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 56
def receiveTimeout
  @connLock.synchronize(:SH) do
    @receiveTimeout
  end
end
receiveTimeout=(val) click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 49
def receiveTimeout=(val)
  @connLock.synchronize(:EX) do
    @receiveTimeout = val
    http_client.receive_timeout = @receiveTimeout if http_client
  end
end
sdk_uri() click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 37
def sdk_uri
  URI::HTTPS.build(:host => server, :port => port, :path => "/sdk")
end
verify_callback(is_ok, ctx) click to toggle source
# File lib/VMwareWebService/MiqVimClientBase.rb, line 88
def verify_callback(is_ok, ctx)
  if $DEBUG
    puts "#{is_ok ? 'ok' : 'ng'}: #{ctx.current_cert.subject}"
  end
  unless is_ok
    depth = ctx.error_depth
    code = ctx.error
    msg = ctx.error_string
    STDERR.puts "at depth #{depth} - #{code}: #{msg}" if $DEBUG
  end
  is_ok
end