vmware_web_service 2.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VMwareWebService/MiqHostDatastoreSystem.rb +5 -1
  3. data/lib/VMwareWebService/MiqVim.rb +80 -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 +15 -7
  19. data/lib/VMwareWebService/VixDiskLib/VixDiskLibServer.rb +15 -15
  20. data/lib/VMwareWebService/VixDiskLib/vdl_wrapper.rb +26 -27
  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 +15 -48
  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
@@ -11,19 +11,17 @@ require 'VMwareWebService/VixDiskLib/vdl_wrapper'
11
11
  class VixDiskLibError < RuntimeError
12
12
  end
13
13
 
14
- LOG_FILE = ENV["LOG_FILE"]
15
-
16
- $vim_log = Logger.new LOG_FILE
17
-
18
14
  class VDDKFactory
19
15
  include DRb::DRbUndumped
20
16
  attr_accessor :shutdown
21
17
  attr_accessor :running
18
+ attr_reader :logger
22
19
 
23
20
  def initialize
24
21
  @shutdown = nil
25
22
  @started = nil
26
23
  @running = nil
24
+ @logger = Logger.new($stdout)
27
25
  end
28
26
 
29
27
  def init
@@ -45,14 +43,14 @@ class VDDKFactory
45
43
  thr = DRb.thread
46
44
  DRb.stop_service
47
45
  thr.join unless thr.nil?
48
- $vim_log.info "Finished shutting down DRb"
46
+ logger.info "Finished shutting down DRb"
49
47
  end
50
48
 
51
49
  def shut_down_service(msg)
52
- $vim_log.info msg.to_s
50
+ logger.info msg.to_s
53
51
  VdlWrapper.__exit__ if @started
54
52
  @running = true
55
- $vim_log.info "VdlWrapper.__exit__ finished"
53
+ logger.info "VdlWrapper.__exit__ finished"
56
54
  shut_down_drb
57
55
  end
58
56
 
@@ -95,11 +93,13 @@ begin
95
93
  STDOUT.sync = true
96
94
  STDERR.sync = true
97
95
 
96
+ logger = Logger.new($stdout)
97
+
98
98
  DRb.start_service(nil, vddk)
99
99
  DRb.primary_server.verbose = true
100
100
  uri_used = DRb.uri
101
101
  Thread.abort_on_exception = true
102
- $vim_log.info "Started DRb service on URI #{uri_used}"
102
+ logger.info "Started DRb service on URI #{uri_used}"
103
103
  #
104
104
  # Now write the URI used back to the parent (client) process to let it know which port was selected.
105
105
  #
@@ -115,21 +115,21 @@ begin
115
115
  trap('TERM') { vddk.shut_down_service("Termination Signal received"); exit }
116
116
 
117
117
  Thread.new do
118
- $vim_log.info "Monitoring Thread"
118
+ logger.info "Monitoring Thread"
119
119
  #
120
120
  # This will block until the SmartProxyWorker (our parent) exits
121
121
  #
122
122
  proc_reader.read
123
- $vim_log.info "Shutting down VixDiskLibServer - Worker has exited"
123
+ logger.info "Shutting down VixDiskLibServer - Worker has exited"
124
124
  exit
125
125
  end
126
126
  #
127
127
  # If we haven't been marked as started yet, wait for it.
128
128
  # We may return immediately because startup (and more) has already happened.
129
129
  #
130
- $vim_log.info "calling watchdog for startup"
130
+ logger.info "calling watchdog for startup"
131
131
  vddk.wait_for_status("started", 1800)
132
- $vim_log.info "startup has happened, shutdown flag is #{vddk.shutdown}"
132
+ logger.info "startup has happened, shutdown flag is #{vddk.shutdown}"
133
133
  #
134
134
  # Wait for the DRb server thread to finish before exiting.
135
135
  #
@@ -142,8 +142,8 @@ begin
142
142
  end
143
143
 
144
144
  vddk.shut_down_service("Shutting Down VixDiskLibServer")
145
- $vim_log.info "Service has stopped"
145
+ logger.info "Service has stopped"
146
146
  rescue => err
147
- $vim_log.error "VixDiskLibServer ERROR: [#{err}]"
148
- $vim_log.debug "VixDiskLibServer ERROR: [#{err.backtrace.join("\n")}]"
147
+ logger.error "VixDiskLibServer ERROR: [#{err}]"
148
+ logger.debug "VixDiskLibServer ERROR: [#{err.backtrace.join("\n")}]"
149
149
  end
@@ -2,16 +2,14 @@ require 'drb/drb'
2
2
  require 'sync'
3
3
  require 'ffi-vix_disk_lib/api_wrapper'
4
4
  require 'VMwareWebService/VimTypes'
5
+ require 'VMwareWebService/logging'
5
6
  require 'time'
6
7
 
7
- LOG_FILE = ENV["LOG_FILE"]
8
-
9
- $vim_log = Logger.new LOG_FILE
10
-
11
8
  VixDiskLibApi = FFI::VixDiskLib::ApiWrapper
12
9
  class VdlWrapper
13
10
  extend FFI::VixDiskLib::ApiWrapper
14
11
  include DRb::DRbUndumped
12
+ include VMwareWebService::Logging
15
13
 
16
14
  @initialized = false
17
15
  @server_disk_count = 0
@@ -22,9 +20,9 @@ class VdlWrapper
22
20
  @vddk = server
23
21
  end
24
22
 
25
- @info_log = ->(s) { $vim_log.info "VMware(VixDiskLib): #{s}" }
26
- @warn_log = ->(s) { $vim_log.warn "VMware(VixDiskLib): #{s}" }
27
- @error_log = ->(s) { $vim_log.error "VMware(VixDiskLib): #{s}" }
23
+ @info_log = ->(s) { logger.info "VMware(VixDiskLib): #{s}" }
24
+ @warn_log = ->(s) { logger.warn "VMware(VixDiskLib): #{s}" }
25
+ @error_log = ->(s) { logger.error "VMware(VixDiskLib): #{s}" }
28
26
 
29
27
  def self.init
30
28
  return if @initialized
@@ -34,10 +32,10 @@ class VdlWrapper
34
32
  end
35
33
 
36
34
  def self.dumpDisks(server_name)
37
- $vim_log.warn "*** Open VdlDisks for server #{server_name}" if $vim_log
35
+ logger.warn "*** Open VdlDisks for server #{server_name}"
38
36
  @connection.dumpDisks unless @connection.nil? || @connection.serverName != server_name
39
37
  @vddk.running = true
40
- $vim_log.warn "*** Open VdlDisks end" if $vim_log
38
+ logger.warn "*** Open VdlDisks end"
41
39
  end
42
40
 
43
41
  def self.inc_server_disk_count
@@ -53,7 +51,7 @@ class VdlWrapper
53
51
  end
54
52
 
55
53
  def self.connect(connect_parms)
56
- $vim_log.info "VdlWrapper.connect: #{connect_parms[:server_name]}" if $vim_log
54
+ logger.info "VdlWrapper.connect: #{connect_parms[:server_name]}"
57
55
  raise VixDiskLibError, "VixDiskLib is not initialized" unless @initialized
58
56
  raise VixDiskLibError, "Already connected to #{@connection.serverName}" if @connection
59
57
  @connection = VdlConnection.new(connect_parms, @vddk)
@@ -61,7 +59,7 @@ class VdlWrapper
61
59
  end
62
60
 
63
61
  def self.__disconnect__(conn_obj)
64
- $vim_log.info "VdlWrapper.__disconnect__: #{conn_obj.serverName}" if $vim_log
62
+ logger.info "VdlWrapper.__disconnect__: #{conn_obj.serverName}"
65
63
  raise VixDiskLibError, "VixDiskLib is not initialized" unless @initialized
66
64
  FFI::VixDiskLib::API.disconnect(conn_obj.vdl_connection)
67
65
  @connection = nil
@@ -76,7 +74,7 @@ class VdlWrapper
76
74
  # the DRb service (this process) to segfault during the exit sequence.
77
75
  #
78
76
  # super
79
- $vim_log.info "VixDiskLib has exited cleanly"
77
+ logger.info "VixDiskLib has exited cleanly"
80
78
  @vddk.running = true
81
79
  @vddk.shutdown = true
82
80
  @initialized = nil
@@ -92,7 +90,7 @@ class VdlConnection
92
90
 
93
91
  def initialize(connect_parms, vddk)
94
92
  @serverName = connect_parms[:server_name]
95
- $vim_log.info "VdlConnection.initialize: #{@serverName}" if $vim_log
93
+ logger.info "VdlConnection.initialize: #{@serverName}"
96
94
  @vdl_connection = VixDiskLibApi.connect(connect_parms)
97
95
  @disks = []
98
96
  @disk_lock = Sync.new
@@ -100,10 +98,10 @@ class VdlConnection
100
98
  end
101
99
 
102
100
  def disconnect
103
- $vim_log.info "VdlConnection.disconnect: #{@serverName}" if $vim_log
101
+ logger.info "VdlConnection.disconnect: #{@serverName}"
104
102
  @disk_lock.synchronize(:EX) do
105
103
  if !@vdl_connection
106
- $vim_log.warn "VDLConnection.disconnect: server: #{@serverName} not connected" if $vim_log
104
+ logger.warn "VDLConnection.disconnect: server: #{@serverName} not connected"
107
105
  else
108
106
  __close_disks__
109
107
  VdlWrapper.__disconnect__(self)
@@ -119,7 +117,7 @@ class VdlConnection
119
117
  @vddk.running = true
120
118
  @disk_lock.sync_lock(:SH) if (unlock = !@disk_lock.sync_locked?)
121
119
  @disks.each do |d|
122
- $vim_log.warn " VdlDisk: #{d.path}, opened: #{d.timeStamp}" if $vim_log
120
+ logger.warn " VdlDisk: #{d.path}, opened: #{d.timeStamp}"
123
121
  end
124
122
  ensure
125
123
  @disk_lock.sync_unlock if unlock
@@ -132,11 +130,11 @@ class VdlConnection
132
130
  disk = VdlDisk.new(self, path, flags)
133
131
  @disks << disk
134
132
  nd = VdlWrapper.inc_server_disk_count
135
- $vim_log.info "VdlConnection.getDisk: #{@serverName} open disks = #{nd}" if $vim_log
136
- if nd >= MAX_DISK_WARN && $vim_log
137
- $vim_log.warn "VdlConnection::getDisk: connection to server: #{@serverName}"
138
- $vim_log.warn "VdlConnection::getDisk: number of open disks = #{nd}"
139
- $vim_log.warn "VdlConnection::getDisk: subsequent open calls may fail"
133
+ logger.info "VdlConnection.getDisk: #{@serverName} open disks = #{nd}"
134
+ if nd >= MAX_DISK_WARN
135
+ logger.warn "VdlConnection::getDisk: connection to server: #{@serverName}"
136
+ logger.warn "VdlConnection::getDisk: number of open disks = #{nd}"
137
+ logger.warn "VdlConnection::getDisk: subsequent open calls may fail"
140
138
  VdlWrapper.dumpDisks(@serverName)
141
139
  end
142
140
  return disk
@@ -149,11 +147,11 @@ class VdlConnection
149
147
  @vddk.running = true
150
148
  VixDiskLibApi.close(diskObj.handle)
151
149
  if !@vdl_connection
152
- $vim_log.warn "VDLConnection.disconnect: server: #{@serverName} not connected" if $vim_log
150
+ logger.warn "VDLConnection.disconnect: server: #{@serverName} not connected"
153
151
  else
154
152
  @disks.delete(diskObj)
155
153
  nd = VdlWrapper.dec_server_disk_count
156
- $vim_log.warn "VdlConnection.__close_disk__: #{@serverName} open disks = #{nd}" if $vim_log
154
+ logger.warn "VdlConnection.__close_disk__: #{@serverName} open disks = #{nd}"
157
155
  end
158
156
  ensure
159
157
  @disk_lock.sync_unlock if unlock
@@ -163,7 +161,7 @@ class VdlConnection
163
161
  raise VixDiskLibError,
164
162
  "VdlConnection::__close_disks__: exclusive disk lock not held" unless @disk_lock.sync_exclusive?
165
163
  if !@vdl_connection
166
- $vim_log.warn "VDLConnection.disconnect: server: #{@serverName} not connected" if $vim_log
164
+ logger.warn "VDLConnection.disconnect: server: #{@serverName} not connected"
167
165
  else
168
166
  @disks.each(&:close)
169
167
  end
@@ -173,6 +171,7 @@ end # class VdlConnection
173
171
 
174
172
  class VdlDisk
175
173
  include DRb::DRbUndumped
174
+ include VMwareWebService::Logging
176
175
 
177
176
  attr_reader :path, :flags, :handle, :sectorSize, :timeStamp, :info
178
177
 
@@ -180,7 +179,7 @@ class VdlDisk
180
179
 
181
180
  def initialize(conn_obj, path, flags)
182
181
  @time_stamp = Time.now
183
- $vim_log.debug "VdlDisk.new <#{object_id}>: opening #{path}" if $vim_log && $vim_log.debug?
182
+ logger.debug { "VdlDisk.new <#{object_id}>: opening #{path}" }
184
183
  @connection = conn_obj
185
184
  @handle = VixDiskLibApi.open(@connection.vdl_connection, path, flags)
186
185
  @path = path
@@ -196,11 +195,11 @@ class VdlDisk
196
195
  end
197
196
 
198
197
  def close
199
- $vim_log.debug "VdlDisk.close <#{ssId}>: closing #{@path}" if $vim_log && $vim_log.debug?
198
+ logger.debug { "VdlDisk.close <#{ssId}>: closing #{@path}" }
200
199
  @vddk.running = true
201
200
  @handle_lock.synchronize(:EX) do
202
201
  if !@handle
203
- $vim_log.debug "VdlDisk.close: #{@path} not open" if $vim_log && $vim_log.debug?
202
+ logger.debug { "VdlDisk.close: #{@path} not open" }
204
203
  else
205
204
  @connection.__close_disk__(self)
206
205
  @handle = nil
@@ -2,8 +2,6 @@ module MiqException
2
2
  class Error < RuntimeError; end
3
3
 
4
4
  class MiqVimError < Error; end
5
- class MiqVimBrokerStaleHandle < MiqVimError; end
6
- class MiqVimBrokerUnavailable < MiqVimError; end
7
5
  # MiqVimResourceNotFound is derived from RuntimeError to ensure it gets marshalled over DRB properly.
8
6
  # TODO: Rename MiqException::Error class to avoid issues returning derived error classes over DRB.
9
7
  # Then change MiqVimResourceNotFound to derive from MiqVimError
@@ -0,0 +1,16 @@
1
+ module VMwareWebService
2
+ class << self
3
+ attr_writer :logger
4
+ end
5
+
6
+ def self.logger
7
+ require "logger"
8
+ @logger ||= Logger.new(nil)
9
+ end
10
+
11
+ module Logging
12
+ def logger
13
+ VMwareWebService.logger
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module VMwareWebService
2
- VERSION = '2.0.3'.freeze
2
+ VERSION = '3.1.0'.freeze
3
3
  end
@@ -5,3 +5,5 @@ autoload :VimArray, 'VMwareWebService/VimTypes'
5
5
  autoload :VimString, 'VMwareWebService/VimTypes'
6
6
  autoload :VimFault, 'VMwareWebService/VimTypes'
7
7
  autoload :VimClass, 'VMwareWebService/VimTypes'
8
+
9
+ require "VMwareWebService/logging"
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: 2.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-15 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 5.2.4.3
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '7.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 5.2.4.3
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: ffi-vix_disk_lib
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -107,21 +107,7 @@ dependencies:
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
- name: codeclimate-test-reporter
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: 1.0.0
116
- type: :development
117
- prerelease: false
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - "~>"
121
- - !ruby/object:Gem::Version
122
- version: 1.0.0
123
- - !ruby/object:Gem::Dependency
124
- name: manageiq-password
110
+ name: manageiq-style
125
111
  requirement: !ruby/object:Gem::Requirement
126
112
  requirements:
127
113
  - - ">="
@@ -162,42 +148,26 @@ dependencies:
162
148
  - - "~>"
163
149
  - !ruby/object:Gem::Version
164
150
  version: '3.0'
165
- - !ruby/object:Gem::Dependency
166
- name: rubocop
167
- requirement: !ruby/object:Gem::Requirement
168
- requirements:
169
- - - "~>"
170
- - !ruby/object:Gem::Version
171
- version: '0.52'
172
- type: :development
173
- prerelease: false
174
- version_requirements: !ruby/object:Gem::Requirement
175
- requirements:
176
- - - "~>"
177
- - !ruby/object:Gem::Version
178
- version: '0.52'
179
151
  - !ruby/object:Gem::Dependency
180
152
  name: simplecov
181
153
  requirement: !ruby/object:Gem::Requirement
182
154
  requirements:
183
155
  - - ">="
184
156
  - !ruby/object:Gem::Version
185
- version: '0'
157
+ version: 0.21.2
186
158
  type: :development
187
159
  prerelease: false
188
160
  version_requirements: !ruby/object:Gem::Requirement
189
161
  requirements:
190
162
  - - ">="
191
163
  - !ruby/object:Gem::Version
192
- version: '0'
164
+ version: 0.21.2
193
165
  description: A ruby interface to Vmware Web Services SDK
194
- email:
166
+ email:
195
167
  executables: []
196
168
  extensions: []
197
169
  extra_rdoc_files: []
198
170
  files:
199
- - lib/VMwareWebService/DMiqVim.rb
200
- - lib/VMwareWebService/DMiqVimSync.rb
201
171
  - lib/VMwareWebService/MiqCustomFieldsManager.rb
202
172
  - lib/VMwareWebService/MiqHostAdvancedOptionManager.rb
203
173
  - lib/VMwareWebService/MiqHostDatastoreSystem.rb
@@ -209,11 +179,8 @@ files:
209
179
  - lib/VMwareWebService/MiqHostVirtualNicManager.rb
210
180
  - lib/VMwareWebService/MiqVim.rb
211
181
  - lib/VMwareWebService/MiqVimAlarmManager.rb
212
- - lib/VMwareWebService/MiqVimBroker.rb
213
- - lib/VMwareWebService/MiqVimBrokerMods.rb
214
182
  - lib/VMwareWebService/MiqVimClientBase.rb
215
183
  - lib/VMwareWebService/MiqVimCluster.rb
216
- - lib/VMwareWebService/MiqVimCoreUpdater.rb
217
184
  - lib/VMwareWebService/MiqVimCustomizationSpecManager.rb
218
185
  - lib/VMwareWebService/MiqVimDataStore.rb
219
186
  - lib/VMwareWebService/MiqVimDump.rb
@@ -238,7 +205,7 @@ files:
238
205
  - lib/VMwareWebService/broker_timeout.rb
239
206
  - lib/VMwareWebService/esx_thumb_print.rb
240
207
  - lib/VMwareWebService/exception.rb
241
- - lib/VMwareWebService/miq_fault_tolerant_vim.rb
208
+ - lib/VMwareWebService/logging.rb
242
209
  - lib/VMwareWebService/thumb_print.rb
243
210
  - lib/VMwareWebService/vcenter_thumb_print.rb
244
211
  - lib/VMwareWebService/version.rb
@@ -4445,23 +4412,23 @@ homepage: https://github.com/ManageIQ/vmware_web_service
4445
4412
  licenses:
4446
4413
  - Apache-2.0
4447
4414
  metadata: {}
4448
- post_install_message:
4415
+ post_install_message:
4449
4416
  rdoc_options: []
4450
4417
  require_paths:
4451
4418
  - lib
4452
4419
  required_ruby_version: !ruby/object:Gem::Requirement
4453
4420
  requirements:
4454
- - - ">"
4421
+ - - ">="
4455
4422
  - !ruby/object:Gem::Version
4456
- version: '2.4'
4423
+ version: 2.5.0
4457
4424
  required_rubygems_version: !ruby/object:Gem::Requirement
4458
4425
  requirements:
4459
4426
  - - ">="
4460
4427
  - !ruby/object:Gem::Version
4461
4428
  version: '0'
4462
4429
  requirements: []
4463
- rubygems_version: 3.2.0.rc.2
4464
- signing_key:
4430
+ rubygems_version: 3.3.5
4431
+ signing_key:
4465
4432
  specification_version: 4
4466
4433
  summary: A ruby interface to Vmware Web Services SDK
4467
4434
  test_files: []
@@ -1,95 +0,0 @@
1
- require 'VMwareWebService/MiqVim'
2
- require 'VMwareWebService/DMiqVimSync'
3
-
4
- #
5
- # Class used to wrap locked object and return it through DRB.
6
- #
7
- class MiqDrbReturn
8
- attr_accessor :obj, :lock
9
-
10
- def initialize(obj, lock = nil)
11
- @obj = obj
12
- @lock = lock
13
- end
14
- end
15
-
16
- class DMiqVim < MiqVim
17
- alias_method :serverPrivateConnect, :connect
18
- alias_method :serverPrivateDisconnect, :disconnect
19
- alias_method :conditionalCopy, :deepClone
20
-
21
- include DRb::DRbUndumped
22
- include DMiqVimSync
23
-
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)
34
- def initialize(server, username, password, broker, preLoad = false, debugUpdates = false, notifyMethod = nil, cacheScope = nil, maxWait = 60, maxObjects = 250)
35
- super(server, username, password, cacheScope, monitor_updates = true, preLoad, debugUpdates, notifyMethod, maxWait, maxObjects)
36
-
37
- @broker = broker
38
- @connectionShuttingDown = false
39
- @connectionRemoved = false
40
- end
41
-
42
- def monitor(preLoad)
43
- log_prefix = "DMiqVim.monitor (#{@connId})"
44
- begin
45
- monitorUpdates(preLoad)
46
- rescue Exception => err
47
- # if handleSessionNotAuthenticated(err)
48
- # $vim_log.info "#{log_prefix}: Restarting Update Monitor" if $vim_log
49
- # retry
50
- # end
51
- $vim_log.info "#{log_prefix}: returned from monitorUpdates via #{err.class} exception" if $vim_log
52
- @error = err
53
- ensure
54
- $vim_log.info "#{log_prefix}: returned from monitorUpdates" if $vim_log
55
- if @updateMonitorReady && !@broker.shuttingDown
56
- @broker.connTrySync(:EX, server, username) do |key|
57
- @broker.removeMiqVimSS(key, self)
58
- end
59
-
60
- if @notifyMethod
61
- @notifyMethod.call(:server => @server,
62
- :username => @username,
63
- :op => 'MiqVimRemoved',
64
- :error => @error
65
- )
66
- end
67
- end
68
- end
69
- end
70
-
71
- def shutdownConnection
72
- return if @connectionShuttingDown
73
- log_prefix = "DMiqVim.shutdownConnection (#{@connId})"
74
- $vim_log.info "#{log_prefix}: for address=<#{@server}>, username=<#{@username}>...Starting" if $vim_log
75
- @connectionShuttingDown = true
76
- serverPrivateDisconnect if self.isAlive?
77
- $vim_log.info "#{log_prefix}: for address=<#{@server}>, username=<#{@username}>...Complete" if $vim_log
78
- end
79
-
80
- def connectionRemoved?
81
- @connectionRemoved
82
- end
83
-
84
- def connectionRemoved
85
- @connectionRemoved = true
86
- end
87
-
88
- def connect
89
- (true)
90
- end
91
-
92
- def disconnect
93
- (true)
94
- end
95
- end # class DMiqVim
@@ -1,45 +0,0 @@
1
-
2
- module DMiqVimSync
3
- #
4
- # This method is called - with the cacheLock held - when returning an object from the cache to the client.
5
- # It used to produce a full recursive copy of the object before releasing the lock.
6
- # When used in the broker, the DRB layer would then marshal the copy of the object to return it to the remote client.
7
- # This new scheme enables us to hold the cacheLock until after DRB marshals the object, eliminating the need
8
- # for this method to produce a full recursive copy.
9
- #
10
- # The lock count of the cacheLock is incremented, so when this method's caller releases the lock, the lock
11
- # will still be held. The object to be returned and the cacheLock are wraped in a MiqDrbReturn object
12
- # and returned to the DRB layer, which will marshal the object and release the lock. See below.
13
- #
14
- def dupObj(obj)
15
- return(obj) unless @cacheLock.sync_locked?
16
- $vim_log.debug "DMiqVim::dupObj: LOCKING [#{Thread.current.object_id}] <#{obj.object_id}>" if $vim_log.debug?
17
- @cacheLock.sync_lock(:SH)
18
- (MiqDrbReturn.new(obj, @cacheLock))
19
- end
20
- end # module DMiqVimSync
21
-
22
- class DRb::DRbMessage
23
- alias_method :dump_original, :dump
24
-
25
- #
26
- # This is the DRB half of the dupObj locking scheme. If we get a MiqDrbReturn object,
27
- # we marshal the object it wraps and release the lock.
28
- #
29
- def dump(obj, error = false)
30
- #
31
- # Place a temp hold on the object until the client registers it.
32
- #
33
- obj.holdBrokerObj if obj.respond_to?(:holdBrokerObj)
34
-
35
- return(dump_original(obj, error)) unless obj.kind_of?(MiqDrbReturn)
36
- begin
37
- return(dump_original(obj.obj, error))
38
- ensure
39
- if obj.lock && obj.lock.sync_locked?
40
- $vim_log.debug "DRb::DRbMessage.dump: UNLOCKING [#{Thread.current.object_id}] <#{obj.obj.object_id}>" if $vim_log.debug?
41
- obj.lock.sync_unlock
42
- end
43
- end
44
- end
45
- end # class DRb::DRbMessage