vmware_web_service 2.1.1 → 3.0.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 +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,222 +0,0 @@
1
- require 'VMwareWebService/DMiqVim'
2
- require 'VMwareWebService/MiqVimVm'
3
- require 'VMwareWebService/MiqVimHost'
4
- require 'VMwareWebService/MiqVimDataStore'
5
- require 'VMwareWebService/MiqVimPerfHistory'
6
- require 'VMwareWebService/MiqVimFolder'
7
- require 'VMwareWebService/MiqVimEventHistoryCollector'
8
- require 'VMwareWebService/MiqCustomFieldsManager'
9
- require 'VMwareWebService/MiqVimAlarmManager'
10
- require 'VMwareWebService/MiqVimCustomizationSpecManager'
11
-
12
- # begin
13
- # require 'VixDiskLib'
14
- # class VdlConnection
15
- # alias :release :disconnect
16
- # end
17
- # rescue LoadError
18
- # # Ignore on systems that don't have VixDiskLib
19
- # class VdlConnection
20
- # def release
21
- # end
22
- # end
23
-
24
- require 'drb'
25
-
26
- $miqBrokerObjRegistry = Hash.new { |h, k| h[k] = [] }
27
- $miqBrokerObjRegistryByConn = Hash.new { |h, k| h[k] = [] }
28
- $miqBrokerObjIdMap = {}
29
- $miqBrokerObjCounts = {}
30
- $miqBrokerObjHold = {}
31
- $miqBrokerObjRegistryLock = Sync.new
32
-
33
- module MiqBrokerObjRegistry
34
- def holdBrokerObj
35
- $vim_log.info "MiqBrokerObjRegistry.holdBrokerObj: #{self.class} object_id: #{object_id} TEMP HOLD"
36
- $miqBrokerObjRegistryLock.synchronize(:EX) do
37
- $miqBrokerObjHold[object_id] = self
38
- end
39
- nil
40
- end
41
-
42
- def registerBrokerObj(id)
43
- $vim_log.info "MiqBrokerObjRegistry.registerBrokerObj: #{self.class} object_id: #{object_id} => SessionId: #{id}"
44
- $miqBrokerObjRegistryLock.synchronize(:EX) do
45
- $miqBrokerObjRegistry[id] << self
46
-
47
- if $miqBrokerObjHold.key?(object_id)
48
- $vim_log.info "MiqBrokerObjRegistry.registerBrokerObj: #{self.class} object_id: #{object_id} TEMP HOLD RELEASE"
49
- $miqBrokerObjHold.delete(object_id)
50
- end
51
-
52
- if defined? @invObj
53
- connKey = "#{@invObj.server}_#{@invObj.username}"
54
- $vim_log.info "MiqBrokerObjRegistry.registerBrokerObj: #{self.class} object_id: #{object_id} => Connection: #{connKey}"
55
- $miqBrokerObjRegistryByConn[connKey] << self
56
- end
57
-
58
- $miqBrokerObjIdMap[object_id] = id
59
- $miqBrokerObjCounts[self.class.to_s] = 0 unless $miqBrokerObjCounts[self.class.to_s]
60
- $miqBrokerObjCounts[self.class.to_s] += 1
61
- end
62
- nil
63
- end
64
-
65
- def unregisterBrokerObj
66
- $miqBrokerObjRegistryLock.synchronize(:EX) do
67
- return unless (id = $miqBrokerObjIdMap[object_id])
68
- $vim_log.info "MiqBrokerObjRegistry.unregisterBrokerObj: #{self.class} object_id: #{object_id} => SessionId: #{id}"
69
- $miqBrokerObjRegistry[id].delete(self)
70
- $miqBrokerObjRegistry.delete(id) if $miqBrokerObjRegistry[id].empty?
71
- if defined? @invObj
72
- connKey = "#{@invObj.server}_#{@invObj.username}"
73
- $vim_log.info "MiqBrokerObjRegistry.unregisterBrokerObj: #{self.class} object_id: #{object_id} => Connection: #{connKey}"
74
- $miqBrokerObjRegistryByConn[connKey].delete(self)
75
- $miqBrokerObjRegistryByConn.delete(connKey) if $miqBrokerObjRegistryByConn[connKey].empty?
76
- end
77
- $miqBrokerObjIdMap.delete(object_id)
78
- $miqBrokerObjCounts[self.class.to_s] -= 1
79
- end
80
- nil
81
- end
82
-
83
- def release
84
- $vim_log.info "MiqBrokerObjRegistry.release: #{self.class} object_id: #{object_id}"
85
- unregisterBrokerObj
86
- release_orig
87
- end
88
- end
89
-
90
- module MiqBrokerVimConnectionCheck
91
- def connectionRemoved?
92
- return false unless self.respond_to?(:invObj)
93
- return false unless invObj.respond_to?(:connectionRemoved?)
94
- invObj.connectionRemoved?
95
- end
96
- end
97
-
98
- # class VdlConnection
99
- # alias :release_orig :release
100
- # remove_method :release
101
- # include MiqBrokerObjRegistry
102
- # end
103
-
104
- class MiqVimVm
105
- alias_method :release_orig, :release
106
- remove_method :release
107
- include DRb::DRbUndumped
108
- include MiqBrokerObjRegistry
109
- include MiqBrokerVimConnectionCheck
110
- end
111
-
112
- class MiqVimHost
113
- alias_method :release_orig, :release
114
- remove_method :release
115
- include DRb::DRbUndumped
116
- include MiqBrokerObjRegistry
117
- include MiqBrokerVimConnectionCheck
118
- end
119
-
120
- class MiqVimDataStore
121
- alias_method :release_orig, :release
122
- remove_method :release
123
- include DRb::DRbUndumped
124
- include MiqBrokerObjRegistry
125
- include DMiqVimSync
126
- include MiqBrokerVimConnectionCheck
127
- end
128
-
129
- class MiqVimPerfHistory
130
- alias_method :release_orig, :release
131
- remove_method :release
132
- include DRb::DRbUndumped
133
- include MiqBrokerObjRegistry
134
- include MiqBrokerVimConnectionCheck
135
- end
136
-
137
- class MiqVimFolder
138
- alias_method :release_orig, :release
139
- remove_method :release
140
- include DRb::DRbUndumped
141
- include MiqBrokerObjRegistry
142
- include MiqBrokerVimConnectionCheck
143
- end
144
-
145
- class MiqVimCluster
146
- alias_method :release_orig, :release
147
- remove_method :release
148
- include DRb::DRbUndumped
149
- include MiqBrokerObjRegistry
150
- include MiqBrokerVimConnectionCheck
151
- end
152
-
153
- class MiqVimEventHistoryCollector
154
- alias_method :release_orig, :release
155
- remove_method :release
156
- include DRb::DRbUndumped
157
- include MiqBrokerObjRegistry
158
- include MiqBrokerVimConnectionCheck
159
- end
160
-
161
- class MiqCustomFieldsManager
162
- alias_method :release_orig, :release
163
- remove_method :release
164
- include DRb::DRbUndumped
165
- include MiqBrokerObjRegistry
166
- include MiqBrokerVimConnectionCheck
167
- end
168
-
169
- class MiqVimAlarmManager
170
- alias_method :release_orig, :release
171
- remove_method :release
172
- include DRb::DRbUndumped
173
- include MiqBrokerObjRegistry
174
- include MiqBrokerVimConnectionCheck
175
- end
176
-
177
- class MiqVimCustomizationSpecManager
178
- alias_method :release_orig, :release
179
- remove_method :release
180
- include DRb::DRbUndumped
181
- include MiqBrokerObjRegistry
182
- include MiqBrokerVimConnectionCheck
183
- end
184
-
185
- #
186
- # Instances of the following classes are maintained in MiqVimHost objects,
187
- # so there's no need to include it in the MiqBrokerObjRegistry.
188
- #
189
- class MiqHostFirewallSystem
190
- include DRb::DRbUndumped
191
- include MiqBrokerVimConnectionCheck
192
- end
193
-
194
- class MiqHostAdvancedOptionManager
195
- include DRb::DRbUndumped
196
- include MiqBrokerVimConnectionCheck
197
- end
198
-
199
- class MiqHostDatastoreSystem
200
- include DRb::DRbUndumped
201
- include MiqBrokerVimConnectionCheck
202
- end
203
-
204
- class MiqHostStorageSystem
205
- include DRb::DRbUndumped
206
- include MiqBrokerVimConnectionCheck
207
- end
208
-
209
- class MiqHostServiceSystem
210
- include DRb::DRbUndumped
211
- include MiqBrokerVimConnectionCheck
212
- end
213
-
214
- class MiqHostNetworkSystem
215
- include DRb::DRbUndumped
216
- include MiqBrokerVimConnectionCheck
217
- end
218
-
219
- class MiqHostVirtualNicManager
220
- include DRb::DRbUndumped
221
- include MiqBrokerVimConnectionCheck
222
- end
@@ -1,269 +0,0 @@
1
- require 'VMwareWebService/MiqVimClientBase'
2
- require 'VMwareWebService/MiqVimDump'
3
- require 'VMwareWebService/VimPropMaps'
4
- require 'VMwareWebService/MiqVimObjectSet'
5
-
6
- class MiqVimCoreUpdater < MiqVimClientBase
7
- include VimPropMaps
8
- include MiqVimDump
9
- include MiqVimObjectSet
10
-
11
- def initialize(server, username, password, propMap = nil, maxWait = 60)
12
- super(server, username, password)
13
-
14
- @propMap = propMap || VimCoreUpdaterPropMap
15
- if @v4
16
- @propMap = dupProps(@propMap)
17
- addProperty(:VirtualMachine, "runtime.memoryOverhead")
18
- end
19
-
20
- @propCol = @sic.propertyCollector
21
- @rootFolder = @sic.rootFolder
22
- @objectSet = objectSet
23
- @updateSpec = updateSpec
24
- @maxWait = maxWait
25
-
26
- @debugUpdates = false
27
-
28
- connect
29
-
30
- @alive = true
31
- end
32
-
33
- def addProperty(key, property)
34
- return if (pm = @propMap[key]).nil?
35
- property.split('.').each { |p| return if pm.include?(p) }
36
- @propMap[key][:props] << property
37
- end
38
-
39
- def updateSpec
40
- VimHash.new("PropertyFilterSpec") do |pfs|
41
- pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa|
42
- @propMap.each do |type, h|
43
- psa << VimHash.new("PropertySpec") do |ps|
44
- ps.type = type
45
- ps.all = h[:props].nil?.to_s
46
- ps.pathSet = h[:props] if h[:props]
47
- end
48
- end
49
- end
50
- pfs.objectSet = @objectSet
51
- end
52
- end
53
-
54
- def monitorUpdates(&block)
55
- log_prefix = "#{self.class.name}.monitorUpdates"
56
- @umPropCol = nil
57
- @filterSpecRef = nil
58
- @monitor = true
59
- @debugUpdates = false if @debugUpdates.nil?
60
- @dumpToLog = true if @debugUpdates
61
-
62
- $vim_log.debug "#{log_prefix}: debugUpdates = #{@debugUpdates}"
63
-
64
- begin
65
- @umPropCol = @sic.propertyCollector
66
- @filterSpecRef = createFilter(@umPropCol, @updateSpec, "true")
67
-
68
- version = nil
69
-
70
- while @monitor
71
- updates_version = doUpdate(version, @maxWait, &block)
72
- next if updates_version.nil?
73
- version = updates_version
74
- sleep @updateDelay if @updateDelay
75
- end # while @monitor
76
- rescue SignalException => err
77
- # Ignore signals, except TERM
78
- rescue => herr
79
- if herr.respond_to?(:reason) && herr.reason == 'The task was canceled by a user.'
80
- $vim_log.info "#{log_prefix}: waitForUpdates canceled"
81
- else
82
- $vim_log.error "******* #{herr.class}"
83
- $vim_log.error herr.to_s
84
- $vim_log.error herr.backtrace.join("\n") unless herr.kind_of?(HTTPClient::ReceiveTimeoutError) # already logged in monitorUpdatesInitial or monitorUpdatesSince
85
- raise herr
86
- end
87
- ensure
88
- if isAlive?
89
- if @filterSpecRef
90
- $vim_log.info "#{log_prefix}: calling destroyPropertyFilter...Starting"
91
- destroyPropertyFilter(@filterSpecRef)
92
- $vim_log.info "#{log_prefix}: calling destroyPropertyFilter...Complete"
93
- end
94
- $vim_log.info "#{log_prefix}: disconnecting..."
95
- disconnect
96
- $vim_log.info "#{log_prefix}: disconnected"
97
- end
98
- @filterSpecRef = nil
99
- # @umPropCol = nil
100
- end
101
- end # def monitorUpdates
102
-
103
- def doUpdate(version, max_wait, &block)
104
- log_prefix = "#{self.class.name}.doUpdate"
105
- begin
106
- $vim_log.info "#{log_prefix}: call to waitForUpdates...Starting" if $vim_log
107
- updateSet = waitForUpdatesEx(@umPropCol, version, :max_wait => max_wait)
108
- $vim_log.info "#{log_prefix}: call to waitForUpdates...Complete" if $vim_log
109
- return version if updateSet.nil?
110
-
111
- version = updateSet.version
112
-
113
- return if updateSet.filterSet.nil? || updateSet.filterSet.empty?
114
-
115
- updateSet.filterSet.each do |fu|
116
- next if fu.filter != @filterSpecRef
117
- fu.objectSet.each do |objUpdate|
118
- updateObject(objUpdate, &block)
119
- end
120
- end # updateSet.filterSet.each
121
- # Help out the Ruby Garbage Collector by resetting variables pointing to large objects back to nil
122
- updateSet = nil
123
- return version
124
- rescue HTTPClient::ReceiveTimeoutError => terr
125
- $vim_log.info "#{log_prefix}: call to waitForUpdates...Timeout" if $vim_log
126
- retry if isAlive?
127
- $vim_log.warn "#{log_prefix}: connection lost"
128
- raise terr
129
- end
130
- end
131
-
132
- def updateObject(objUpdate)
133
- log_prefix = "#{self.class.name}.updateObject"
134
-
135
- case objUpdate.kind
136
- when 'enter'
137
- yield(objUpdate.obj, propUpdate(objUpdate.changeSet))
138
- when 'leave'
139
- yield(objUpdate.obj, nil)
140
- when 'modify'
141
- yield(objUpdate.obj, propUpdate(objUpdate.changeSet))
142
- else
143
- $vim_log.warn "#{log_prefix}: unrecognized operation: #{objUpdate.kind}"
144
- end
145
- end
146
-
147
- def propUpdate(changeSet)
148
- changedProps = {}
149
- changeSet.each do |propChange|
150
- if @debugUpdates
151
- $vim_log.debug "\tpropChange name (path): #{propChange.name}"
152
- $vim_log.debug "\tpropChange op: #{propChange.op}"
153
- $vim_log.debug "\tpropChange val (type): #{propChange.val.class}"
154
-
155
- $vim_log.debug "\t*** propChange val START:"
156
- oGi = @globalIndent
157
- @globalIndent = "\t\t"
158
- dumpObj(propChange.val)
159
- @globalIndent = oGi
160
- $vim_log.debug "\t*** propChange val END"
161
- $vim_log.debug "\t***"
162
- end
163
-
164
- changedProps[propChange.name] = propChange.val
165
- end unless changeSet.nil?
166
- changedProps
167
- end
168
-
169
- def stop
170
- log_prefix = "#{self.class.name}.stop"
171
- $vim_log.info "#{log_prefix}: stopping..."
172
- @monitor = false
173
- if @propCol
174
- $vim_log.info "#{log_prefix}: calling cancelWaitForUpdates"
175
- cancelWaitForUpdates(@propCol)
176
- $vim_log.info "#{log_prefix}: returned from cancelWaitForUpdates"
177
- end
178
- end
179
-
180
- def isAlive?
181
- return false unless @alive
182
- log_prefix = "#{self.class.name}.isAlive?"
183
- begin
184
- unless currentSession
185
- $vim_log.info "#{log_prefix}: Current session no longer exists."
186
- @alive = false
187
- end
188
- rescue Exception => err
189
- $vim_log.info "#{log_prefix}: Could not access connection - #{err}"
190
- @alive = false
191
- end
192
- @alive
193
- end
194
-
195
- def currentSession
196
- getMoProp(@sic.sessionManager, "currentSession")
197
- end
198
-
199
- def getMoProp(mo, path = nil)
200
- pfSpec = VimHash.new("PropertyFilterSpec") do |pfs|
201
- pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa|
202
- psa << VimHash.new("PropertySpec") do |ps|
203
- ps.type = mo.vimType
204
- if !path
205
- ps.all = "true"
206
- else
207
- ps.all = "false"
208
- ps.pathSet = path
209
- end
210
- end
211
- end
212
- pfs.objectSet = VimArray.new("ArrayOfObjectSpec") do |osa|
213
- osa << VimHash.new("ObjectSpec") do |os|
214
- os.obj = mo
215
- end
216
- end
217
- end
218
-
219
- oca = retrievePropertiesCompat(@propCol, pfSpec)
220
-
221
- return nil if !oca || !oca[0] || !oca[0].propSet
222
-
223
- oc = oca[0]
224
- oc.delete('obj')
225
-
226
- oc.propSet = [oc.propSet] unless oc.propSet.kind_of?(Array)
227
- oc.propSet.each do |ps|
228
- #
229
- # Here, ps.name can be a property path in the form: a.b.c
230
- # If that's the case, we should set the target to: propHash['a']['b']['c']
231
- # creating intermediate nodes as needed.
232
- #
233
- h, k = hashTarget(oc, ps.name)
234
- if !h[k]
235
- h[k] = ps.val
236
- elsif h[k].kind_of? Array
237
- h[k] << ps.val
238
- else
239
- h[k] = VimArray.new do |arr|
240
- arr << h[k]
241
- arr << ps.val
242
- end
243
- end
244
- end # oc.propSet.each
245
- oc.delete('propSet')
246
-
247
- (oc)
248
- end
249
-
250
- def hashTarget(baseHash, keyString, create = false)
251
- return baseHash, keyString unless keyString.index('.')
252
-
253
- h = baseHash
254
- ka = splitPropPath(keyString)
255
- ka[0...-1].each do |k|
256
- k, arrayKey = tagAndKey(k)
257
- if arrayKey
258
- array, idx = getVimArrayEnt(h[k], arrayKey, create)
259
- raise "hashTarget: Could not traverse tree through array element #{k}[#{arrayKey}] in #{keyString}" unless array
260
- h = array[idx]
261
- else
262
- h[k] = VimHash.new unless h[k]
263
- h = h[k]
264
- end
265
- end
266
- return h, ka[-1]
267
- end
268
- private :hashTarget
269
- end