Class: MiqFaultTolerantVim

Inherits:
Object
  • Object
show all
Defined in:
lib/VMwareWebService/miq_fault_tolerant_vim.rb

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ MiqFaultTolerantVim

Returns a new instance of MiqFaultTolerantVim.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 6

def initialize(*options)
  options = options.first if options.first.kind_of?(Hash)
  @vim = nil

  @erec     = options[:ems]
  auth_type = options[:auth_type] || :ws
  ip        = options[:ip] || @erec.hostname
  user      = options[:user] || @erec.authentication_userid(auth_type)
  pass      = options[:pass] || @erec.authentication_password(auth_type)
  @ems      = [ip, user, pass]

  @use_broker = options.key?(:use_broker) ? options[:use_broker] : true
  if @use_broker
    if options[:vim_broker_drb_uri].respond_to?(:call)
      @vim_broker_drb_uri_method = options[:vim_broker_drb_uri]
      @vim_broker_drb_uri        = @vim_broker_drb_uri_method.call
    else
      @vim_broker_drb_uri_method = nil
      @vim_broker_drb_uri        = options[:vim_broker_drb_uri]
    end
  end

  begin
    _connect
  rescue MiqException::MiqVimBrokerUnavailable
    retry if _handle_broker_uri_change
    raise
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



40
41
42
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 40

def method_missing(m, *args)
  _execute(m == :disconnect ? :on_disconnect : :on_execute) { |vim| vim.send(m, *args) unless vim.nil? }
end

Instance Method Details

#_ems_addressObject



48
49
50
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 48

def _ems_address
  @ems[0]
end

#_ems_nameObject



44
45
46
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 44

def _ems_name
  @erec.nil? ? _ems_address : @erec.name
end

#_ems_useridObject



52
53
54
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 52

def _ems_userid
  @ems[1]
end

#_reconnectObject



64
65
66
67
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 64

def _reconnect
  _disconnect
  _connect
end

#_use_brokerObject



56
57
58
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 56

def _use_broker
  @use_broker
end

#_vim_broker_drb_uriObject



60
61
62
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 60

def _vim_broker_drb_uri
  @vim_broker_drb_uri
end

#execute(&block) ⇒ Object



36
37
38
# File 'lib/VMwareWebService/miq_fault_tolerant_vim.rb', line 36

def execute(&block)
  _execute(&block)
end