vmware_web_service 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VMwareWebService/MiqHostDatastoreSystem.rb +5 -1
  3. data/lib/VMwareWebService/MiqVim.rb +58 -56
  4. data/lib/VMwareWebService/MiqVimClientBase.rb +11 -10
  5. data/lib/VMwareWebService/MiqVimCluster.rb +6 -2
  6. data/lib/VMwareWebService/MiqVimDataStore.rb +9 -6
  7. data/lib/VMwareWebService/MiqVimDump.rb +1 -1
  8. data/lib/VMwareWebService/MiqVimEventHistoryCollector.rb +5 -1
  9. data/lib/VMwareWebService/MiqVimEventMonitor.rb +22 -20
  10. data/lib/VMwareWebService/MiqVimFolder.rb +15 -11
  11. data/lib/VMwareWebService/MiqVimHost.rb +15 -13
  12. data/lib/VMwareWebService/MiqVimInventory.rb +78 -79
  13. data/lib/VMwareWebService/MiqVimPerfHistory.rb +13 -10
  14. data/lib/VMwareWebService/MiqVimUpdate.rb +50 -50
  15. data/lib/VMwareWebService/MiqVimVdlMod.rb +7 -7
  16. data/lib/VMwareWebService/MiqVimVm.rb +102 -101
  17. data/lib/VMwareWebService/VimService.rb +5 -2
  18. data/lib/VMwareWebService/VixDiskLib/VixDiskLib.rb +10 -6
  19. data/lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb +15 -13
  20. data/lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb +26 -25
  21. data/lib/VMwareWebService/exception.rb +0 -2
  22. data/lib/VMwareWebService/logging.rb +16 -0
  23. data/lib/VMwareWebService/version.rb +1 -1
  24. data/lib/vmware_web_service.rb +2 -0
  25. metadata +6 -25
  26. data/lib/VMwareWebService/DMiqVim.rb +0 -95
  27. data/lib/VMwareWebService/DMiqVimSync.rb +0 -45
  28. data/lib/VMwareWebService/MiqVimBroker.rb +0 -581
  29. data/lib/VMwareWebService/MiqVimBrokerMods.rb +0 -222
  30. data/lib/VMwareWebService/MiqVimCoreUpdater.rb +0 -269
  31. data/lib/VMwareWebService/miq_fault_tolerant_vim.rb +0 -246
@@ -1,246 +0,0 @@
1
- require 'VMwareWebService/MiqVim'
2
- require 'VMwareWebService/MiqVimBroker'
3
- require 'VMwareWebService/exception'
4
-
5
- class MiqFaultTolerantVim
6
- def initialize(*options)
7
- options = options.first if options.first.kind_of?(Hash)
8
- @vim = nil
9
-
10
- @erec = options[:ems]
11
- auth_type = options[:auth_type] || :ws
12
- ip = options[:ip] || @erec.hostname
13
- user = options[:user] || @erec.authentication_userid(auth_type)
14
- pass = options[:pass] || @erec.authentication_password(auth_type)
15
- @ems = [ip, user, pass]
16
-
17
- @use_broker = options.key?(:use_broker) ? options[:use_broker] : true
18
- if @use_broker
19
- if options[:vim_broker_drb_uri].respond_to?(:call)
20
- @vim_broker_drb_uri_method = options[:vim_broker_drb_uri]
21
- @vim_broker_drb_uri = @vim_broker_drb_uri_method.call
22
- else
23
- @vim_broker_drb_uri_method = nil
24
- @vim_broker_drb_uri = options[:vim_broker_drb_uri]
25
- end
26
- end
27
-
28
- begin
29
- _connect
30
- rescue MiqException::MiqVimBrokerUnavailable
31
- retry if _handle_broker_uri_change
32
- raise
33
- end
34
- end
35
-
36
- def execute(&block)
37
- _execute(&block)
38
- end
39
-
40
- def method_missing(m, *args)
41
- _execute(m == :disconnect ? :on_disconnect : :on_execute) { |vim| vim.send(m, *args) unless vim.nil? }
42
- end
43
-
44
- def _ems_name
45
- @erec.nil? ? _ems_address : @erec.name
46
- end
47
-
48
- def _ems_address
49
- @ems[0]
50
- end
51
-
52
- def _ems_userid
53
- @ems[1]
54
- end
55
-
56
- def _use_broker
57
- @use_broker
58
- end
59
-
60
- def _vim_broker_drb_uri
61
- @vim_broker_drb_uri
62
- end
63
-
64
- def _reconnect
65
- _disconnect
66
- _connect
67
- end
68
-
69
- private
70
-
71
- def _execute(state = :on_execute, &block)
72
- return unless block_given?
73
- $log.warn("MIQ(#{self.class.name}._execute) @vim handle is nil.") if $log && @vim.nil? && state != :on_connect
74
- meth = @use_broker ? :_execute_with_broker : :_execute_without_broker
75
- send(meth, state, &block)
76
- end
77
-
78
- def _execute_without_broker(_state)
79
- yield @vim
80
- end
81
-
82
- def _execute_with_broker(state)
83
- log_header = "MIQ(#{self.class.name}._execute_with_broker)"
84
- retries = 0
85
- begin
86
- yield @vim
87
- rescue RangeError, DRb::DRbConnError, Handsoap::Fault, Errno::EMFILE => err
88
- modified_exception = nil
89
-
90
- if err.kind_of?(Handsoap::Fault)
91
- #
92
- # Raise all SOAP Errors, if executing
93
- #
94
- raise if state == :on_execute
95
-
96
- #
97
- # Retry any SOAP Errors, except for authentication or authorization errors
98
- # 'Handsoap::FaultError: Permission to perform this operation was denied.'
99
- # 'Handsoap::FaultError: The session is not authenticated.'
100
- #
101
- raise if err.to_s !~ /Permission to perform this operation was denied/i && err.to_s !~ /^The session is not authenticated/i
102
- end
103
-
104
- #
105
- # If one of the following exceptions, broker could have been recycled and we are holding a stale object reference
106
- # 'RangeError: 0xdb1bbe8e is recycled object occurs'
107
- # 'RangeError: 0xdb4f902e is not id value'
108
- #
109
- if err.kind_of?(RangeError)
110
- raise unless err.to_s =~ /is recycled object/i || err.to_s =~ /is not id value/i
111
- modified_exception = MiqException::MiqVimBrokerStaleHandle
112
- end
113
-
114
- #
115
- # Cannot establish DRb connection to broker
116
- # 'DRb::DRbConnError: druby://localhost:9001 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>'
117
- #
118
- if err.kind_of?(DRb::DRbConnError)
119
- if _handle_broker_uri_change
120
- _connect
121
- retry
122
- end
123
- modified_exception = MiqException::MiqVimBrokerUnavailable
124
- end
125
-
126
- #
127
- # Broker is overwhelmed with too many open sockets
128
- #
129
- modified_exception = MiqException::MiqVimBrokerUnavailable if err.kind_of?(Errno::EMFILE)
130
-
131
- exception_class_name = modified_exception ? modified_exception.name : err.class.name
132
-
133
- #
134
- # When disconnecting, only warn about any errors encountered
135
- #
136
- if state == :on_disconnect
137
- $log.warn("#{log_header} The following issue was detected and skipped while disconnecting from [#{_ems_address}]: [#{exception_class_name}] [#{_classify_error(err)}]") if $log
138
- return
139
- end
140
-
141
- #
142
- # Retry once, if possible
143
- #
144
- if state == :on_execute && retries == 0
145
- $log.warn("#{log_header} Retrying communication via VimBroker to [#{_ems_address}] because [#{exception_class_name}] [#{_classify_error(err)}]") if $log
146
- _reconnect
147
- retries += 1
148
- retry
149
- end
150
-
151
- #
152
- # Log an error message
153
- #
154
- $log.error("#{log_header} Error communicating via VimBroker to [#{_ems_address}] because [#{exception_class_name}] [#{_classify_error(err)}]") if $log
155
-
156
- #
157
- # Raise the original error, if we did not modify it
158
- #
159
- raise if modified_exception.nil?
160
-
161
- #
162
- # Raise our modified error
163
- #
164
- raise modified_exception, _classify_error(err)
165
- end
166
- end
167
-
168
- def _connect
169
- log_header = "MIQ(#{self.class.name}._connect) EMS: [#{_ems_name}]"
170
- log_header << " [Broker]" if @use_broker
171
-
172
- _execute(:on_connect) do
173
- $log.info("#{log_header} Connecting with address: [#{_ems_address}], userid: [#{_ems_userid}]...") if $log
174
- @use_broker ? _connect_with_broker : _connect_without_broker
175
- $log.info("#{log_header} #{@vim.server} is #{(@vim.isVirtualCenter? ? 'VC' : 'ESX')}, API version: #{@vim.apiVersion}") if $log
176
- $log.info("#{log_header} Connected") if $log
177
- end
178
- end
179
-
180
- def _connect_without_broker
181
- @vim = MiqVim.new(*@ems)
182
- end
183
-
184
- def _connect_with_broker
185
- _connect_broker_client
186
-
187
- begin
188
- @vim = _broker_client.getMiqVim(*@ems)
189
- rescue DRb::DRbConnError, Errno::EMFILE => err
190
- # Instead of connecting directly when the broker is not available, log an error and raise the exception
191
- $log.error("MIQ(#{self.class.name}._connect) EMS: [#{_ems_name}] [Broker] Unable to connect to: [#{_ems_address}] because #{_classify_error(err)}") if $log
192
- raise MiqException::MiqVimBrokerUnavailable, _classify_error(err)
193
- end
194
- end
195
-
196
- def _disconnect
197
- @vim.disconnect if @vim.respond_to?(:disconnect) rescue nil
198
- @vim = nil
199
- end
200
-
201
- def _broker_client
202
- $vim_broker_client
203
- end
204
-
205
- def _connect_broker_client
206
- return unless $vim_broker_client.nil?
207
- raise MiqException::MiqVimBrokerUnavailable, "Broker is not available (not running)." if @vim_broker_drb_uri.blank?
208
- $vim_broker_client = MiqVimBroker.new(:client, @vim_broker_drb_uri)
209
- $vim_broker_client_uri = @vim_broker_drb_uri
210
- end
211
-
212
- def _disconnect_broker_client
213
- $vim_broker_client = nil
214
- end
215
-
216
- def _classify_error(err)
217
- if @use_broker
218
- case err
219
- when DRb::DRbConnError
220
- return "Broker is not available (connection error)."
221
- when Errno::EMFILE
222
- return "Broker is not available (too many open files)."
223
- when RangeError
224
- # If the broker is now started but our handle is no longer valid
225
- return "Broker has been restarted."
226
- end
227
- end
228
-
229
- err.to_s
230
- end
231
-
232
- def _handle_broker_uri_change
233
- log_header = "MIQ(#{self.class.name}._handle_broker_uri_change)"
234
- if @vim_broker_drb_uri_method
235
- new_uri = @vim_broker_drb_uri_method.call
236
- if new_uri != $vim_broker_client_uri
237
- $log.warn("#{log_header} Retrying communication via VimBroker to [#{_ems_address}] because [Broker DRb URI changed from #{$vim_broker_client_uri} to #{new_uri}]") if $log && !new_uri.blank?
238
- @vim_broker_drb_uri = new_uri
239
- _disconnect
240
- _disconnect_broker_client
241
- return (new_uri.blank? ? false : true)
242
- end
243
- end
244
- false
245
- end
246
- end