vmware_web_service 0.4.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55282eac83a1152907a531201ac903f05f0c282cdcb60cd807ab4e695fc3e945
4
- data.tar.gz: 1dd7bb1f11ed5121ae33989e09a0fb4abebb1c4efc4125d4e964a7ba433d99cb
3
+ metadata.gz: 9a3fda957a5c3f40ee4cb771e4dfb68ffcabaec2b511c3088a9070de7c816e96
4
+ data.tar.gz: 2f411a8da658bf1112f7f589909c10ada57265e9f9f230acb346dffcf7199b93
5
5
  SHA512:
6
- metadata.gz: 5d762d75ce5e3590b078fe64c813b8a9d7bd6865017f1fde052d52003e6b0a1986bcf72d9888ca78a47544b899f1f8cc16383e68222b35d0a8716af8c1463dc1
7
- data.tar.gz: 1f4eb2f599c2c35ea2d7f8f5d9dc7e9b0ef14b8298596501c27acbd38e878705683c28459f82c1dad42eac6cab12cdd8433b360361019a26cdd2e067312289f4
6
+ metadata.gz: 72ffcec7bdefef9325d1f28f2fa80ea9ee75585d69523ad852adeec32a836bd505fa1fdfeb80572f52963762c63852970d100d1e6c313909eda1a3fece8cf618
7
+ data.tar.gz: 3aaf49a620c290efc30a14171c052e8cccfc900a82c7d386b627a92a124c28cdfb4a705e86e4f483faac174bfe24a9a169bdc7e459692cda04f3954bac56be76
@@ -1,5 +1,4 @@
1
1
  require 'VMwareWebService/MiqVim'
2
- require 'VMwareWebService/MiqVimUpdate'
3
2
  require 'VMwareWebService/DMiqVimSync'
4
3
 
5
4
  #
@@ -20,66 +19,24 @@ class DMiqVim < MiqVim
20
19
  alias_method :conditionalCopy, :deepClone
21
20
 
22
21
  include DRb::DRbUndumped
23
- include MiqVimUpdate
24
22
  include DMiqVimSync
25
23
 
26
- attr_reader :updateThread
27
-
24
+ # @param server [String] DNS name or IP address of the vCenter Server
25
+ # @param username [String] Username to connect to the vCenter Server
26
+ # @param password [String] Password to connect to the vCenter Server
27
+ # @param broker [MiqVimBroker] Instance of the broker worker this connection belongs to
28
+ # @param preLoad [Bool] Should the cache be built before returning the connection (default: false)
29
+ # @param debugUpdates [Bool] Should we print debug info for each update (default: false)
30
+ # @param notifyMethod [Method] A optional method to call for each update (default: nil)
31
+ # @param cacheScope [Symbol] A pre-defined set of properties to cache (default: nil)
32
+ # @param maxWait [Integer] How many seconds to wait before breaking out of WaitForUpdates (default: 60)
33
+ # @param maxObjects [Integer] How many objects to return from each WaitForUpdates page (default: 250)
28
34
  def initialize(server, username, password, broker, preLoad = false, debugUpdates = false, notifyMethod = nil, cacheScope = nil, maxWait = 60, maxObjects = 250)
29
- super(server, username, password, cacheScope)
35
+ super(server, username, password, cacheScope, monitor_updates = true, preLoad, debugUpdates, notifyMethod, maxWait, maxObjects)
30
36
 
31
- log_prefix = "DMiqVim.initialize (#{@connId})"
32
- @broker = broker
33
- @updateMonitorReady = false
34
- @error = nil
35
- @notifyMethod = notifyMethod
37
+ @broker = broker
36
38
  @connectionShuttingDown = false
37
- @connectionRemoved = false
38
- @debugUpdates = debugUpdates
39
- @maxWait = maxWait
40
- @maxObjects = maxObjects
41
-
42
- checkForOrphanedMonitors
43
- $vim_log.info "#{log_prefix}: starting update monitor thread" if $vim_log
44
- @updateThread = Thread.new { monitor(preLoad) }
45
- @updateThread[:vim_connection_id] = connId
46
- $vim_log.info "#{log_prefix}: waiting for update monitor to become ready" if $vim_log
47
- until @updateMonitorReady
48
- raise @error unless @error.nil?
49
- break unless @updateThread.alive?
50
- Thread.pass
51
- end
52
- $vim_log.info "#{log_prefix}: update monitor ready" if $vim_log
53
- end
54
-
55
- # VC sometimes throws: Handsoap::Fault { :code => 'ServerFaultCode', :reason => 'The session is not authenticated.' }
56
- # Handle this condition by reconnecting and monitoring again
57
- # See http://communities.vmware.com/thread/190531
58
- def handleSessionNotAuthenticated(err)
59
- return false unless err.respond_to?(:reason) && err.reason == 'The session is not authenticated.'
60
-
61
- log_prefix = "DMiqVim.handleSessionNotAuthenticated (#{@connId})"
62
- $vim_log.error "#{log_prefix}: Reconnecting Session because '#{err.reason}'" if $vim_log
63
- $vim_log.info "#{log_prefix}: Session(server=#{server}, username=#{username}) isAlive? => #{self.isAlive?.inspect}" if $vim_log
64
-
65
- begin
66
- $vim_log.info "#{log_prefix}: Disconnecting Session" if $vim_log
67
- serverPrivateDisconnect
68
- $vim_log.info "#{log_prefix}: Disconnecting Session...Complete" if $vim_log
69
- rescue => disconnect_err
70
- $vim_log.error "#{log_prefix}: Disconnecting Session...Error #{disconnect_err}" if $vim_log
71
- end
72
-
73
- begin
74
- $vim_log.info "#{log_prefix}: Connecting Session" if $vim_log
75
- serverPrivateConnect
76
- $vim_log.info "#{log_prefix}: Connecting Session...Complete" if $vim_log
77
- rescue => connect_err
78
- $vim_log.error "#{log_prefix}: Connecting Session...Error #{connect_err}" if $vim_log
79
- @error = err
80
- end
81
-
82
- @error.nil?
39
+ @connectionRemoved = false
83
40
  end
84
41
 
85
42
  def monitor(preLoad)
@@ -116,31 +73,10 @@ class DMiqVim < MiqVim
116
73
  log_prefix = "DMiqVim.shutdownConnection (#{@connId})"
117
74
  $vim_log.info "#{log_prefix}: for address=<#{@server}>, username=<#{@username}>...Starting" if $vim_log
118
75
  @connectionShuttingDown = true
119
- stopUpdateMonitor
120
- begin
121
- if @updateThread != Thread.current && @updateThread.alive?
122
- $vim_log.info "#{log_prefix}: waiting for Update Monitor Thread...Starting" if $vim_log
123
- @updateThread.join
124
- $vim_log.info "#{log_prefix}: waiting for Update Monitor Thread...Complete" if $vim_log
125
- end
126
- rescue => err
127
- end
128
76
  serverPrivateDisconnect if self.isAlive?
129
77
  $vim_log.info "#{log_prefix}: for address=<#{@server}>, username=<#{@username}>...Complete" if $vim_log
130
78
  end
131
79
 
132
- def checkForOrphanedMonitors
133
- log_prefix = "DMiqVim.checkForOrphanedMonitors (#{@connId})"
134
- $vim_log.debug "#{log_prefix}: called..."
135
- Thread.list.each do |thr|
136
- next unless thr[:vim_connection_id] == connId
137
- $vim_log.error "#{log_prefix}: Terminating orphaned update monitor <#{thr.object_id}>"
138
- thr.raise "Orphaned update monitor (#{@connId}) <#{thr.object_id}>, terminated by <#{Thread.current.object_id}>"
139
- thr.wakeup
140
- end
141
- $vim_log.debug "#{log_prefix}: done."
142
- end
143
-
144
80
  def connectionRemoved?
145
81
  @connectionRemoved
146
82
  end
@@ -13,15 +13,39 @@ require 'VMwareWebService/MiqVimEventHistoryCollector'
13
13
  require 'VMwareWebService/MiqCustomFieldsManager'
14
14
  require 'VMwareWebService/MiqVimAlarmManager'
15
15
  require 'VMwareWebService/MiqVimCustomizationSpecManager'
16
+ require 'VMwareWebService/MiqVimUpdate'
16
17
 
17
18
  class MiqVim < MiqVimInventory
18
19
  include MiqVimVdlConnectionMod
19
20
  include MiqPbmInventory
21
+ include MiqVimUpdate
20
22
 
21
- def initialize(server, username, password, cacheScope = nil)
22
- super
23
+ attr_reader :updateThread, :monitor_updates
24
+
25
+ # @param server [String] DNS name or IP address of the vCenter Server
26
+ # @param username [String] Username to connect to the vCenter Server
27
+ # @param password [String] Password to connect to the vCenter Server
28
+ # @param cacheScope [Symbol] A pre-defined set of properties to cache (default: nil)
29
+ # @param monitor_updates [Bool] Should a thread be started to monitor updates (default: false)
30
+ # @param preLoad [Bool] Should the cache be built before returning the connection (default: false)
31
+ # @param debugUpdates [Bool] Should we print debug info for each update (default: false)
32
+ # @param notifyMethod [Method] A optional method to call for each update (default: nil)
33
+ # @param maxWait [Integer] How many seconds to wait before breaking out of WaitForUpdates (default: 60)
34
+ # @param maxObjects [Integer] How many objects to return from each WaitForUpdates page (default: 250)
35
+ def initialize(server, username, password, cacheScope = nil, monitor_updates = false, preLoad = false, debugUpdates = false, notifyMethod = nil, maxWait = 60, maxObjects = 250)
36
+ super(server, username, password, cacheScope)
23
37
 
24
38
  pbm_initialize(self)
39
+
40
+ @monitor_updates = monitor_updates
41
+ @updateMonitorReady = false
42
+ @error = nil
43
+ @notifyMethod = notifyMethod
44
+ @debugUpdates = debugUpdates
45
+ @maxWait = maxWait
46
+ @maxObjects = maxObjects
47
+
48
+ start_monitor_updates_thread(preLoad) if @monitor_updates
25
49
  end
26
50
 
27
51
  def getVimVm(path)
@@ -227,6 +251,60 @@ class MiqVim < MiqVimInventory
227
251
  end
228
252
 
229
253
  def disconnect
254
+ shutdown_monitor_updates_thread if @monitor_updates
255
+
230
256
  super
231
257
  end
258
+
259
+ private
260
+
261
+ def start_monitor_updates_thread(preLoad)
262
+ checkForOrphanedMonitors
263
+ log_prefix = "MiqVim.initialize (#{@connId})"
264
+ $vim_log.info "#{log_prefix}: starting update monitor thread" if $vim_log
265
+ @updateThread = Thread.new { monitor(preLoad) }
266
+ @updateThread[:vim_connection_id] = connId
267
+ $vim_log.info "#{log_prefix}: waiting for update monitor to become ready" if $vim_log
268
+ until @updateMonitorReady
269
+ raise @error unless @error.nil?
270
+ break unless @updateThread.alive?
271
+ Thread.pass
272
+ end
273
+ $vim_log.info "#{log_prefix}: update monitor ready" if $vim_log
274
+ end
275
+
276
+ def checkForOrphanedMonitors
277
+ log_prefix = "MiqVim.checkForOrphanedMonitors (#{@connId})"
278
+ $vim_log.debug "#{log_prefix}: called..."
279
+ Thread.list.each do |thr|
280
+ next unless thr[:vim_connection_id] == connId
281
+ $vim_log.error "#{log_prefix}: Terminating orphaned update monitor <#{thr.object_id}>"
282
+ thr.raise "Orphaned update monitor (#{@connId}) <#{thr.object_id}>, terminated by <#{Thread.current.object_id}>"
283
+ thr.wakeup
284
+ end
285
+ $vim_log.debug "#{log_prefix}: done."
286
+ end
287
+
288
+ def monitor(preLoad)
289
+ log_prefix = "MiqVim.monitor (#{@connId})"
290
+ begin
291
+ monitorUpdates(preLoad)
292
+ rescue Exception => err
293
+ $vim_log.info "#{log_prefix}: returned from monitorUpdates via #{err.class} exception" if $vim_log
294
+ @error = err
295
+ end
296
+ end
297
+
298
+ def shutdown_monitor_updates_thread
299
+ log_prefix = "MiqVim.disconnect (#{@connId})"
300
+ stopUpdateMonitor
301
+ begin
302
+ if @updateThread != Thread.current && @updateThread.alive?
303
+ $vim_log.info "#{log_prefix}: waiting for Update Monitor Thread...Starting" if $vim_log
304
+ @updateThread.join
305
+ $vim_log.info "#{log_prefix}: waiting for Update Monitor Thread...Complete" if $vim_log
306
+ end
307
+ rescue
308
+ end
309
+ end
232
310
  end # module MiqVim
@@ -1,3 +1,3 @@
1
1
  module VMwareWebService
2
- VERSION = '0.4.10'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmware_web_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport