class MiqVimInventory
Constants
- MOR
Attributes
Public Class Methods
# File lib/VMwareWebService/MiqVimInventory.rb, line 74 def self.cacheScope @@cacheScope end
# File lib/VMwareWebService/MiqVimInventory.rb, line 78 def self.cacheScope=(val) @@cacheScope = val end
Datastore/path utility methods.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2020 def self.dsPath?(p) return true if p =~ /^\[[^\]]*\].*/ false end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2064 def self.dsRelativePath(p) raise "dsRelativePath: #{p} is not a datastore path" unless dsPath?(p) p.gsub(/^.*\]\s*/, '') end
MiqVimClientBase::new
# File lib/VMwareWebService/MiqVimInventory.rb, line 20 def initialize(server:, username:, password:, port: 443, ssl_options: {}, cache_scope: nil) super(:server => server, :port => port, :ssl_options => ssl_options, :username => username, :password => password) cache_scope ||= @@cacheScope case cache_scope when :cache_scope_full @propMap = FullPropMap logger.info "MiqVimInventory: using property map FullPropMap" when :cache_scope_ems_refresh @propMap = EmsRefreshPropMap logger.info "MiqVimInventory: using property map EmsRefreshPropMap" when :cache_scope_core @propMap = CorePropMap logger.info "MiqVimInventory: using property map CorePropMap" when :cache_scope_event_monitor @propMap = EventMonitorPropMap logger.info "MiqVimInventory: using property map EventMonitorPropMap" else @propMap = FullPropMap logger.info "MiqVimInventory: unrecognized cache scope #{cacheScope}, using FullPropMap" end # If we are connected to a virtual center then we can access additional properties @propMap.merge!(PropMapVCenter) if isVirtualCenter && cache_scope != :cache_scope_event_monitor @propCol = @sic.propertyCollector @rootFolder = @sic.rootFolder @objectSet = objectSet @spec = spec @updateSpec = updateSpec @globalIndent = "" @selectorHash = @@selectorHash @selectorPropPathHash = {} @cacheLock = Sync.new @configLock = Sync.new resetCache __connect @alive = true end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2029 def self.path2dsName(p) return nil unless MiqVimInventory.dsPath?(p) p.gsub(/^\[([^\]]*)\].*/, '\1') end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2465 def self.removeSelector(selName) remKeys = nil if selName.kind_of?(Symbol) remKeys = [selName] elsif selName.kind_of?(Hash) remKeys = selName.keys elsif selName.kind_of?(Array) remKeys = selName else raise "MiqVimInventory.removeSelector: selName must be a symbol, hash or array, received #{selName.class}" end remKeys.each do |rk| raise "MiqVimInventory.removeSelector: keys must be symbols, received #{rk.class}" unless rk.kind_of?(Symbol) end remKeys.each do |rk| @@selectorHash.delete(rk) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2443 def self.setSelector(selSpec) raise "MiqVimInventory.setSelector: selSpec must be a hash, received #{selSpec.class}" unless selSpec.kind_of?(Hash) selSpec.each_key do |k| raise "MiqVimInventory.setSelector: selSpec keys must be symbols, received #{k.class}" unless k.kind_of?(Symbol) end ov = nil selSpec.each_value do |v| if v.kind_of?(Array) v.each do |vv| unless vv.kind_of?(String) ov = vv break end end else ov = v unless v.kind_of?(String) end raise "MiqVimInventory.setSelector: selSpec values must be strings or arrays of strings, received #{ov.class}" unless ov.nil? end @@selectorHash.merge!(selSpec) end
Public Instance Methods
# File lib/VMwareWebService/MiqVimInventory.rb, line 1565 def addDVPObj(dvpObj) addObjHash(:DistributedVirtualPortgroup, dvpObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1659 def addDVSObj(dvsObj) addObjHash(:DistributedVirtualSwitch, dvsObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1471 def addDataStore(dsMor) @cacheLock.synchronize(:EX) do addObjByMor(dsMor) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1477 def addDataStoreObj(dsObj) addObjHash(:Datastore, dsObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1947 def addExtensionManager(extensionManagerMor) @cacheLock.synchronize(:EX) do return(addObjByMor(extensionManagerMor)) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1348 def addHostSystem(hsMor) @cacheLock.synchronize(:EX) do addObjByMor(hsMor) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1354 def addHostSystemObj(hsObj) addObjHash(:HostSystem, hsObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1837 def addLicenseManager(licenseManagerMor) @cacheLock.synchronize(:EX) do return(addObjByMor(licenseManagerMor)) end end
Extract the properties for the VIM object represented by objMor and hash them. Add the resulting property hash to the appropriate inventory hashes.
# File lib/VMwareWebService/MiqVimInventory.rb, line 393 def addObjByMor(objMor) raise "addObjByMor: exclusive cache lock not held" unless @cacheLock.sync_exclusive? objType = objMor.vimBaseType.to_sym raise "addObjByMor: Unknown VIM object type: #{objType}" unless (pmap = @propMap[objType]) objHash = getMoProp_local(objMor, pmap[:props]) return nil unless objHash addObjHash(objType, objHash) objHash end
Add the property hash for the VIM object to the appropriate inventory hashes.
# File lib/VMwareWebService/MiqVimInventory.rb, line 305 def addObjHash(objType, objHash) raise "addObjHash: exclusive cache lock not held" unless @cacheLock.sync_exclusive? objHash = hashObj(objType, objHash) objFixUp(objType, objHash) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 64 def addProperty(key, property) return if (pm = @propMap[key]).nil? property.split('.').each { |p| return if pm.include?(p) } @propMap[key][:props] << property end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1746 def addStoragePodObj(spObj) addObjHash(:StoragePod, spObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2771 def addToCollection(hash, tag, val) unless (array = hash[tag]) array = VimArray.new if (type = val.xsiType) nh = VimHash.new array.xsiType = "ArrayOf#{type}" nh[type] = array hash[tag] = nh end hash[tag] = array end array << val end
# File lib/VMwareWebService/MiqVimInventory.rb, line 583 def addVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do return(addObjByMor(vmMor)) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 441 def allPropsFromCache(hashName, props) props = [props] if props.kind_of?(String) @cacheLock.synchronize(:SH) do ret = {} send((hashName + "_locked").to_sym).each do |key, cv| props.each do |pn| cv = cv[pn] break unless cv end ret[key] = cv end return(dupObj(ret)) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2631 def applyFilter(objArr, propFilter) retArr = [] objArr.each do |obj| match = true propFilter.each do |pn, pv| pVal = propValue(obj, pn) if pVal.kind_of?(Array) nxt = false pVal.each do |v| if pv === v nxt = true break end end next if nxt else next if pv === pVal end match = false break end retArr << obj if match end retArr end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2601 def applySelSpec(topObj, retObj, pa) prop, arrayKey = tagAndKey(pa.first) return unless topObj.kind_of?(Hash) && topObj.key?(prop) nextTopObj = topObj[prop] return if nextTopObj.nil? if pa.length == 1 retObj[prop] = nextTopObj return end nextpa = pa[1..-1] if arrayKey == "*" raise "applySelSpec: #{pa.first} is not an array." unless nextTopObj.kind_of?(Array) retObj[prop] = VimArray.new(nextTopObj.xsiType, nextTopObj.vimType) if retObj[prop].nil? nextRetObj = retObj[prop] nextTopObj.each_with_index do |ntoe, i| if (nroe = nextRetObj[i]).nil? nroe = nextRetObj[i] = VimHash.new(ntoe.xsiType, ntoe.vimType) end applySelSpec(ntoe, nroe, nextpa) end else retObj[prop] = VimHash.new(nextTopObj.xsiType, nextTopObj.vimType) if retObj[prop].nil? applySelSpec(nextTopObj, retObj[prop], nextpa) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2572 def applySelector(topObj, selSpec) selSpec = getSelSpec(selSpec) if topObj.kind_of?(VimHash) retObj = VimHash.new(topObj.xsiType, topObj.vimType) selSpec.each do |cs| applySelSpec(topObj, retObj, splitPropPath(cs)) end # # When passed a collection of objects at the top level, apply # the selSpec to each object in the collection, returning a # new collection of new objects. # elsif topObj.kind_of?(Hash) retObj = {} topObj.each do |k, v| retObj[k] = applySelector(v, selSpec) end elsif topObj.kind_of?(VimArray) retObj = VimArray.new(topObj.xsiType, topObj.vimType) topObj.each do |v| retObj << applySelector(v, selSpec) end end retObj end
# File lib/VMwareWebService/MiqVimInventory.rb, line 202 def assert_no_locks return unless @lock_debug return unless @cacheLock.sync_locked? msg = "" msg += "Exclusive cache lock held\n" if @cacheLock.sync_exclusive? msg += "Shared cache lock held\n" if @cacheLock.sync_shared? msg += Kernel.caller.join("\n") raise msg end
VimService#browseDiagnosticLog
# File lib/VMwareWebService/MiqVimInventory.rb, line 2131 def browseDiagnosticLog(key, start = nil, lines = nil, host = nil) super(@sic.diagnosticManager, host, key, start, lines) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2135 def browseDiagnosticLogEx(key, start = nil, lines = nil, host = nil) # Continually loop over the browseDiagnosticLog to get the number of lines # requested, since it returns 1000 lines by default, even if specified # to be higher. Setting lines to nil returns all lines, as per the # documentation. rv = nil next_start = (start || 1) lines_left = lines loop do l = browseDiagnosticLog(key, next_start, lines_left, host) l['lineText'] ||= [] unless rv.nil? rv['lineText'] += l['lineText'] else rv = l rv['lineStart'] = rv['lineStart'].to_i end read_lines = l['lineText'].length break if read_lines != 1000 if lines lines_left -= read_lines break if lines_left <= 0 end next_start += read_lines end rv['lineText'] = rv['lineText'][0..lines - 1] if lines && rv['lineText'].length > lines rv['lineEnd'] = rv['lineStart'] + rv['lineText'].length - 1 rv end
# File lib/VMwareWebService/MiqVimInventory.rb, line 100 def cacheStats(pref) totalCacheSz = 0 @cacheLock.synchronize(:SH) do @propMap.each_value do |pm| hn = pm[:baseName] hnm = pm[:baseName] + "ByMor" hashByMor = instance_variable_get(hnm) hashByKey = pm[:keyPath] ? instance_variable_get(hn) : nil if hashByMor.nil? logger.info "#{pref}#{hnm}: is nil" next end keya = hashByMor.keys obja = hashByMor.values logger.info "#{pref}#{hnm}: #keys = #{keya.length}" logger.info "#{pref}#{hnm}: #objects = #{obja.length}" obja.compact! obja.uniq! logger.info "#{pref}#{hnm}: #unique non-nill objects = #{obja.length}" unless hashByKey.nil? keyb = hashByKey.keys objb = hashByKey.values logger.info "#{pref}#{hn}: #keys = #{keyb.length}" logger.info "#{pref}#{hn}: #objects = #{objb.length}" objb.compact! objb.uniq! logger.info "#{pref}#{hn}: #unique non-nill objects = #{objb.length}" obja.concat(objb).uniq! end logger.info "#{pref}TOTAL: #unique non-nill objects = #{obja.length}" cacheSz = Marshal.dump(obja).length logger.info "#{pref}TOTAL: size of objects = #{cacheSz}" logger.info "#{pref}****" totalCacheSz += cacheSz end logger.info "#{pref}****************" logger.info "#{pref}TOTAL: cache size = #{totalCacheSz}" logger.info "#{pref}****************" end totalCacheSz end
VimService#cancelTask
# File lib/VMwareWebService/MiqVimInventory.rb, line 2200 def cancelTask(tmor) super(getTaskMor(tmor)) end
Return a single clusterComputeResource object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 790 def clusterComputeResourceByMor(ccrMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(clusterComputeResourcesByMor_locked[ccrMor])) if selSpec.nil? return(applySelector(clusterComputeResourcesByMor_locked[ccrMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 758 def clusterComputeResources(selSpec = nil) ccrs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? ccrs = dupObj(clusterComputeResources_locked) else ccrs = applySelector(clusterComputeResources_locked, selSpec) end end assert_no_locks ccrs end
Public accessor
Return an array of cluster compute resource objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 802 def clusterComputeResourcesByFilter(filter) crs = nil @cacheLock.synchronize(:SH) do crs = applyFilter(clusterComputeResourcesByMor_locked.values, filter) crs = dupObj(crs) end assert_no_locks crs end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 774 def clusterComputeResourcesByMor(selSpec = nil) ccrs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? ccrs = dupObj(clusterComputeResourcesByMor_locked) else ccrs = applySelector(clusterComputeResourcesByMor_locked, selSpec) end end assert_no_locks ccrs end
Return a single computeResource object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 687 def computeResourceByMor(crMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(computeResourcesByMor_locked[crMor])) if selSpec.nil? return(applySelector(computeResourcesByMor_locked[crMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 655 def computeResources(selSpec = nil) crs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? crs = dupObj(computeResources_locked) else crs = applySelector(computeResources_locked, selSpec) end end assert_no_locks crs end
Public accessor
Return an array of compute resource objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 699 def computeResourcesByFilter(filter) crs = nil @cacheLock.synchronize(:SH) do crs = applyFilter(computeResourcesByMor_locked.values, filter) crs = dupObj(crs) end assert_no_locks crs end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 671 def computeResourcesByMor(selSpec = nil) crs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? crs = dupObj(computeResourcesByMor_locked) else crs = applySelector(computeResourcesByMor_locked, selSpec) end end assert_no_locks crs end
When used in the broker - DRB - this method is redefined to create a deep clone of the object.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2838 def conditionalCopy(obj) obj end
# File lib/VMwareWebService/MiqVimInventory.rb, line 233 def currentSession getMoProp(@sic.sessionManager, "currentSession") end
Return a single hostSystem object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1439 def dataStoreByMor(dsMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(dataStoresByMor_locked[dsMor])) if selSpec.nil? return(applySelector(dataStoresByMor_locked[dsMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1407 def dataStores(selSpec = nil) ds = nil @cacheLock.synchronize(:SH) do if selSpec.nil? ds = dupObj(dataStores_locked) else ds = applySelector(dataStores_locked, selSpec) end end assert_no_locks ds end
Public accessor
Return an array of data store objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1451 def dataStoresByFilter(filter) ds = nil @cacheLock.synchronize(:SH) do ds = applyFilter(dataStoresByMor_locked.values, filter) ds = dupObj(ds) end assert_no_locks ds end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1461 def dataStoresByFilter_local(filter) ds = nil @cacheLock.synchronize(:SH) do ds = applyFilter(dataStoresByMor_locked.values, filter) ds = deepClone(ds) end assert_no_locks ds end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1423 def dataStoresByMor(selSpec = nil) ds = nil @cacheLock.synchronize(:SH) do if selSpec.nil? ds = dupObj(dataStoresByMor_locked) else ds = applySelector(dataStoresByMor_locked, selSpec) end end assert_no_locks ds end
Return a single datacenter object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1211 def datacenterByMor(dcMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(datacentersByMor_locked[dcMor])) if selSpec.nil? return(applySelector(datacentersByMor_locked[dcMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1179 def datacenters(selSpec = nil) dc = nil @cacheLock.synchronize(:SH) do if selSpec.nil? dc = dupObj(datacenters_locked) else dc = applySelector(datacenters_locked, selSpec) end end assert_no_locks dc end
Public accessor
Return an array of datacenter objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1223 def datacentersByFilter(filter) dc = nil @cacheLock.synchronize(:SH) do dc = applyFilter(datacentersByMor_locked.values, filter) dc = dupObj(dc) end assert_no_locks dc end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1195 def datacentersByMor(selSpec = nil) dc = nil @cacheLock.synchronize(:SH) do if selSpec.nil? dc = dupObj(datacentersByMor_locked) else dc = applySelector(datacentersByMor_locked, selSpec) end end assert_no_locks dc end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2089 def datastorePath(p) return p if dsPath?(p) drp = nil @cacheLock.synchronize(:SH) do dataStores_locked.each do |n, o| if p[o['summary']['url']] drp = p.dup drp[o['summary']['url']] = "[#{n}] " break end end end raise "datastorePath: Could not find datastore for path #{p}" unless drp drp end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2842 def deepClone(obj) return nil unless obj nObj = obj.class.new nObj.vimType = obj.vimType if obj.respond_to?(:vimType) nObj.xsiType = obj.xsiType if obj.respond_to?(:xsiType) if obj.kind_of?(Hash) obj.each { |k, v| nObj[k] = deepClone(v) } elsif obj.kind_of?(Array) obj.each { |v| nObj << deepClone(v) } elsif obj.kind_of?(String) nObj.replace(obj) else raise "deepClone: unexpected object #{obj.class}" end nObj end
# File lib/VMwareWebService/MiqVimInventory.rb, line 70 def deleteProperty(key, property) @propMap[key][:props].delete(property) unless @propMap[key].nil? end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2046 def dsName2mo(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dupObj(dataStores_locked[dsn]['summary']["datastore"]) end assert_no_locks ret end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2055 def dsName2mo_local(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dataStores_locked[dsn]['summary']["datastore"] end assert_no_locks ret end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2038 def dsName2path(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dataStores_locked[dsn]['summary']["url"] end ret end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2025 def dsPath?(p) MiqVimInventory.dsPath?(p) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2069 def dsRelativePath(p) MiqVimInventory.dsRelativePath(p) end
When used in the broker - DRB - this method is redefined to carry the cacheLock into the DRB dump method.
When not used in the broker, there is no need to copy the object.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2830 def dupObj(obj) obj end
Return a single storagePod object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1558 def dvPortgroupByMor(dvpMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(dvPortgroupsByMor_locked[dvpMor])) if selSpec.nil? return(applySelector(dvPortgroupsByMor_locked[dvpMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1526 def dvPortgroups(selSpec = nil) dvp = nil @cacheLock.synchronize(:SH) do dvp = if selSpec.nil? dupObj(dvPortgroups_locked) else applySelector(dvPortgroups_locked, selSpec) end end assert_no_locks dvp end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1542 def dvPortgroupsByMor(selSpec = nil) dvp = nil @cacheLock.synchronize(:SH) do dvp = if selSpec.nil? dupObj(dvPortgroupsByMor_locked) else applySelector(dvPortgroupsByMor_locked, selSpec) end end assert_no_locks dvp end
Return a single DV Switch object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1652 def dvSwitchByMor(dvsMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(dvSwitchesByMor_locked[dvsMor])) if selSpec.nil? return(applySelector(dvSwitchesByMor_locked[dvsMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1620 def dvSwitches(selSpec = nil) dvs = nil @cacheLock.synchronize(:SH) do dvs = if selSpec.nil? dupObj(dvSwitches_locked) else applySelector(dvSwitches_locked, selSpec) end end assert_no_locks dvs end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1636 def dvSwitchesByMor(selSpec = nil) dvs = nil @cacheLock.synchronize(:SH) do dvs = if selSpec.nil? dupObj(dvSwitchesByMor_locked) else applySelector(dvSwitchesByMor_locked, selSpec) end end assert_no_locks dvs end
Return a single Extension Manager object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1925 def extensionManagerByMor(extensionManagerMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(extensionManagersByMor_locked[extensionManagerMor])) if selSpec.nil? return(applySelector(extensionManagersByMor_locked[extensionManagerMor], selSpec)) end end
Public accessor
Return an array of extension manager objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1937 def extensionManagersByFilter(filter) extension_managers = nil @cacheLock.synchronize(:SH) do extension_managers = applyFilter(extensionManagersByMor_locked.values, filter) extension_managers = dupObj(extension_managers) end assert_no_locks extension_managers end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1909 def extensionManagersByMor(selSpec = nil) extension_managers = nil @cacheLock.synchronize(:SH) do if selSpec.nil? extension_managers = dupObj(extensionManagersByMor_locked) else extension_managers = applySelector(extensionManagersByMor_locked, selSpec) end end assert_no_locks extension_managers end
Return a single folder object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1108 def folderByMor(fMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(foldersByMor_locked[fMor])) if selSpec.nil? return(applySelector(foldersByMor_locked[fMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1076 def folders(selSpec = nil) f = nil @cacheLock.synchronize(:SH) do if selSpec.nil? f = dupObj(folders_locked) else f = applySelector(folders_locked, selSpec) end end assert_no_locks f end
Public accessor
Return an array of folder objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1120 def foldersByFilter(filter) f = nil @cacheLock.synchronize(:SH) do f = applyFilter(foldersByMor_locked.values, filter) f = dupObj(f) end assert_no_locks f end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1092 def foldersByMor(selSpec = nil) f = nil @cacheLock.synchronize(:SH) do if selSpec.nil? f = dupObj(foldersByMor_locked) else f = applySelector(foldersByMor_locked, selSpec) end end assert_no_locks f end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 2363 def getMoProp(mo, path = nil) getMoProp_local(mo, path) end
Retrieve the properties for multiple objects of the same type, given an array of managed object references.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2371 def getMoPropMulti(moa, path = nil) return [] if !moa || moa.empty? tmor = moa.first raise "getMoPropMulti: item is not a managed object reference" unless tmor.respond_to? :vimType args = VimArray.new("ArrayOfPropertyFilterSpec") do |pfsa| pfsa << VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa| psa << VimHash.new("PropertySpec") do |ps| ps.type = tmor.vimType if !path ps.all = "true" else ps.all = "false" ps.pathSet = path end end end pfs.objectSet = VimArray.new("ArrayOfObjectSpec") do |osa| moa.each do |mor| VimHash.new("ObjectSpec") do |os| os.obj = mor osa << os end end end end end oca = VimArray.new('ArrayOfObjectContent') retrievePropertiesIter(@propCol, args) do |oc| oc.MOR = oc.obj oc.delete('obj') oc.propSet = Array(oc.propSet) unless oc.propSet.kind_of?(Array) oc.propSet.each do |ps| # # Here, ps.name can be a property path in the form: a.b.c # If that's the case, we should set the target to: propHash['a']['b']['c'] # creating intermediate nodes as needed. # h, k = hashTarget(oc, ps.name) if !h[k] h[k] = ps.val elsif h[k].kind_of? Array h[k] << ps.val else h[k] = VimArray.new do |arr| arr << h[k] arr << ps.val end end end # oc.propSet.each oc.delete('propSet') oca << oc end oca end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2434 def getMoPropMultiIter(moa, path = nil) oca = [] moa.each do |mo| oc = getMoProp_local(mo, path) oca << oc if oc end oca end
Retrieve the properties for a single object, given its managed object reference.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2306 def getMoProp_local(mo, path = nil) pfSpec = VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa| psa << VimHash.new("PropertySpec") do |ps| ps.type = mo.vimType if !path ps.all = "true" else ps.all = "false" ps.pathSet = path end end end pfs.objectSet = VimArray.new("ArrayOfObjectSpec") do |osa| osa << VimHash.new("ObjectSpec") do |os| os.obj = mo end end end logger.info "MiqVimInventory(#{@server}, #{@username}).getMoProp_local: calling retrieveProperties(#{mo.vimType})" oca = retrievePropertiesCompat(@propCol, pfSpec) logger.info "MiqVimInventory(#{@server}, #{@username}).getMoProp_local: return from retrieveProperties(#{mo.vimType})" return nil if !oca || !oca[0] || !oca[0].propSet oc = oca[0] oc.MOR = oc.obj oc.delete('obj') oc.propSet = Array(oc.propSet) unless oc.propSet.kind_of?(Array) oc.propSet.each do |ps| # # Here, ps.name can be a property path in the form: a.b.c # If that's the case, we should set the target to: propHash['a']['b']['c'] # creating intermediate nodes as needed. # h, k = hashTarget(oc, ps.name) if !h[k] h[k] = ps.val elsif h[k].kind_of? Array h[k] << ps.val else h[k] = VimArray.new do |arr| arr << h[k] arr << ps.val end end end # oc.propSet.each oc.delete('propSet') oc end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2541 def getSelSpec(selSpec) ss = selSpec if ss.kind_of?(Symbol) ss = getSelector(ss) raise "getSelSpec: selector #{selSpec} not found" if ss.nil? end ss = [] if ss.nil? ss.kind_of?(Array) ? ss : [ss] end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2510 def getSelector(selName) raise "getSelector: selName must be a symbol, received #{selName.class}" unless selName.kind_of?(Symbol) @configLock.synchronize(:SH) do return @selectorHash[selName] end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2184 def getTaskMor(tmor) if tmor.respond_to?(:vimType) logger.debug "getTaskMor: returning #{tmor}, no search" return tmor else logger.debug "getTaskMor: searching for task #{tmor}" getTasks.each do |tmo| if tmo.to_str == tmor logger.debug "getTaskMor: returning #{tmo} (#{tmo.vimType})" return tmo end end raise "getTaskMor: task #{tmor} not found." end end
Task utility methods.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2174 def getTasks getMoProp_local(@sic.taskManager, "recentTask")['recentTask'] end
private :getTasks
# File lib/VMwareWebService/MiqVimInventory.rb, line 2179 def getTasksByFilter(filter) ta = applyFilter(getMoPropMulti(getTasks, 'info'), filter) dupObj(ta) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2678 def hasProp?(baseHash, prop) return baseHash.key?(prop) unless prop.index('.') h = baseHash ka = splitPropPath(prop) ka[0...-1].each do |k| k, arrayKey = tagAndKey(k) if arrayKey array, idx = getVimArrayEnt(h[k], arrayKey, false) return(false) unless array h = array[idx] else return(false) unless h[k] h = h[k] end end h.key?(ka[-1]) end
Return a single hostSystem object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1314 def hostSystemByMor(hsMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(hostSystemsByMor_locked[hsMor])) if selSpec.nil? return(applySelector(hostSystemsByMor_locked[hsMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1282 def hostSystems(selSpec = nil) hs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? hs = dupObj(hostSystems_locked) else hs = applySelector(hostSystems_locked, selSpec) end end assert_no_locks hs end
Public accessor
Return an array of host system objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1326 def hostSystemsByFilter(filter) hs = nil @cacheLock.synchronize(:SH) do hs = applyFilter(hostSystemsByMor_locked.values, filter) hs = dupObj(hs) end assert_no_locks hs end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1298 def hostSystemsByMor(selSpec = nil) hs = nil @cacheLock.synchronize(:SH) do if selSpec.nil? hs = dupObj(hostSystemsByMor_locked) else hs = applySelector(hostSystemsByMor_locked, selSpec) end end assert_no_locks hs end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1336 def hostSystemsStorageDevice(hostMors, selSpec = nil) if selSpec.nil? sd = getMoPropMulti(hostMors, "config.storageDevice") else pp = selSpecToPropPath(selSpec) sd = getMoPropMulti(hostMors, pp) sd = applySelector(sd, selSpec) end sd end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1999 def inventoryHash ih = nil @cacheLock.synchronize(:SH) do ih = dupObj(inventoryHash_locked) end ih end
A hash of managed object references for all the objects we care about.
For internal use. Locking handled by caller
# File lib/VMwareWebService/MiqVimInventory.rb, line 1975 def inventoryHash_locked raise "inventoryHash_locked: cache lock not held" unless @cacheLock.sync_locked? return(@inventoryHash) if @inventoryHash logger.info "MiqVimInventory.inventoryHash_locked: loading inventoryHash for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) logger.info "MiqVimInventory(#{@server}, #{@username}).inventoryHash_locked: calling retrieveProperties" @inventoryHash = {} retrievePropertiesIter(@propCol, @spec) do |oc| (@inventoryHash[oc.obj.vimType] ||= []) << oc.obj end logger.info "MiqVimInventory(#{@server}, #{@username}).inventoryHash_locked: returned from retrieveProperties" ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.inventoryHash_locked: loaded inventoryHash for #{@connId}" @inventoryHash end
# File lib/VMwareWebService/MiqVimInventory.rb, line 237 def isAlive? return false unless @alive begin unless currentSession logger.info "MiqVimInventory.isAlive?: Current session no longer exists." @alive = false end rescue Exception => err logger.info "MiqVimInventory.isAlive?: Could not access connection - #{err}" @alive = false end @alive end
For testing
# File lib/VMwareWebService/MiqVimInventory.rb, line 254 def isDead @alive = false end
# File lib/VMwareWebService/MiqVimInventory.rb, line 262 def isHostAgent? !@isVirtualCenter end
# File lib/VMwareWebService/MiqVimInventory.rb, line 258 def isVirtualCenter? @isVirtualCenter end
# File lib/VMwareWebService/MiqVimInventory.rb, line 474 def keyExistsInCache?(hashName, key) @cacheLock.synchronize(:SH) do return send((hashName + "_locked").to_sym).key?(key) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 456 def keyFromCache(hashName, props, value = nil) raise "no block given" if value.nil? && !block_given? raise "block given with value" if !value.nil? && block_given? props = [props] if props.kind_of?(String) @cacheLock.synchronize(:SH) do ck, = send((hashName + "_locked").to_sym).detect do |_k, v| cv = v props.each do |pn| cv = cv[pn] break unless cv end block_given? ? yield(cv) : cv == value end return(dupObj(ck)) end end
Return a single License Manager object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1815 def licenseManagerByMor(licenseManagerMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(licenseManagersByMor_locked[licenseManagerMor])) if selSpec.nil? return(applySelector(licenseManagersByMor_locked[licenseManagerMor], selSpec)) end end
Public accessor
Return an array of license manager objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1827 def licenseManagersByFilter(filter) license_managers = nil @cacheLock.synchronize(:SH) do license_managers = applyFilter(licenseManagersByMor_locked.values, filter) license_managers = dupObj(license_managers) end assert_no_locks license_managers end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1799 def licenseManagersByMor(selSpec = nil) license_managers = nil @cacheLock.synchronize(:SH) do if selSpec.nil? license_managers = dupObj(licenseManagersByMor_locked) else license_managers = applySelector(licenseManagersByMor_locked, selSpec) end end assert_no_locks license_managers end
# File lib/VMwareWebService/MiqVimInventory.rb, line 212 def loadCache @cacheLock.synchronize(:EX) do @propMap.each_value do |pm| send("#{pm[:baseName][1..-1]}_locked".to_sym) end end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2073 def localVmPath(p) return p unless dsPath?(p) ds = path2dsName(p) path = dsRelativePath(p) begin dsPath = dsName2path(ds) rescue return nil end return dsPath if !path || path == "/" File.join(dsPath, path) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 82 def logCacheCounts(pref) @cacheLock.synchronize(:SH) do @propMap.each_value do |pm| hn = pm[:baseName] hnm = pm[:baseName] + "ByMor" unless instance_variable_get(hnm).nil? hnmc = instance_variable_get(hnm).keys.length logger.info "#{pref}#{hnm}: #{hnmc}" end unless instance_variable_get(hn).nil? hnc = instance_variable_get(hn).keys.length logger.info "#{pref}#{hn}: #{hnc}" end end end end
Generate a user event associated with the given managed object.
VimService#logUserEvent
# File lib/VMwareWebService/MiqVimInventory.rb, line 2010 def logUserEvent(entity, msg) logger.info "MiqVimInventory(#{@server}, #{@username}).logUserEvent: calling logUserEvent" super(@sic.eventManager, entity, msg) logger.info "MiqVimInventory(#{@server}, #{@username}).logUserEvent: returned from logUserEvent" end
# File lib/VMwareWebService/MiqVimInventory.rb, line 312 def objFixUp(objType, objHash) objType = objType.to_sym if objType.kind_of? String # # Type-specific processing # case objType when :VirtualMachine # # The above hashObj call will hash by datastore path. # Below, we also hash by local path. # if (dsPath = objHash.fetch_path('summary', 'config', 'vmPathName')) localPath = localVmPath(dsPath) if localPath && !localPath.empty? objHash['summary']['config']['vmLocalPathName'] = localPath @virtualMachines[localPath] = objHash else objHash['summary']['config']['vmLocalPathName'] = nil end end if (ssObj = objHash["snapshot"]) ssMorHash = VimHash.new rsl = ssObj['rootSnapshotList'] rsl = [rsl] unless rsl.kind_of?(Array) rsl.each { |rs| snapshotFixup(rs, ssMorHash) } ssObj['ssMorHash'] = ssMorHash end if (hostMor = objHash.fetch_path('summary', 'runtime', 'host')) hostObj = hostSystemsByMor_locked[hostMor] return unless hostObj objHash['summary']["runtime"]["hostName"] = hostObj.fetch_path("summary", "config", "name") end when :ResourcePool objHash['summary']['name'] = objHash['name'] end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2034 def path2dsName(p) MiqVimInventory.path2dsName(p) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2247 def pollTask(tmor, className = nil) className ||= self.class.to_s logger.info "#{className}(#{@server}, #{@username})::pollTask(#{tmor})" args = VimArray.new("ArrayOfPropertyFilterSpec") do |pfsa| pfsa << VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa| psa << VimHash.new("PropertySpec") do |ps| ps.type = tmor.vimType ps.all = "false" ps.pathSet = ["info.state", "info.error", "info.result", "info.progress"] end end pfs.objectSet = VimArray.new("ArrayOfObjectSpec") do |osa| VimHash.new("ObjectSpec") do |os| os.obj = tmor osa << os end end end end state = result = error = progress = nil oca = retrievePropertiesCompat(@propCol, args) raise "pollTask: task not found #{tmor}" if !oca || !oca[0] || !oca[0].propSet oca[0].propSet.each do |ps| case ps.name when "info.state" state = ps.val when "info.error" error = ps.val when "info.result" result = ps.val when "info.progress" progress = ps.val end end case state when TaskInfoState::Error raise error.localizedMessage when TaskInfoState::Success return state, result when TaskInfoState::Running return state, progress else return state, nil end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 426 def propFromCache(hashName, key, props) props = [props] if props.kind_of?(String) @cacheLock.synchronize(:SH) do cv = send((hashName + "_locked").to_sym)[key] raise "propFromCache: key \"#{key}\" not found in hash #{hashName}" unless cv ppn = key props.each do |pn| cv = cv[pn] raise "propFromCache: property \"#{pn}\" not found under \"#{ppn}\"" unless cv ppn = pn end return(dupObj(cv)) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2659 def propValue(baseHash, prop) return baseHash[prop] unless prop.index('.') h = baseHash ka = splitPropPath(prop) ka[0...-1].each do |k| k, arrayKey = tagAndKey(k) if arrayKey array, idx = getVimArrayEnt(h[k], arrayKey, false) return(nil) unless array h = array[idx] else return(nil) unless h[k] h = h[k] end end (h[ka[-1]]) end
Log and diagnostic methods.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2127 def queryLogDescriptions(host = nil) queryDescriptions(@sic.diagnosticManager, host) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1953 def refreshExtensionManager(extensionManagerMor) @cacheLock.synchronize(:EX) do return(conditionalCopy(addObjByMor(extensionManagerMor))) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1843 def refreshLicenseManager(licenseManagerMor) @cacheLock.synchronize(:EX) do return(conditionalCopy(addObjByMor(licenseManagerMor))) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 589 def refreshVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do return(conditionalCopy(addObjByMor(vmMor))) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1964 def removeExtensionManager(extensionManagerMor) @cacheLock.synchronize(:EX) do removeObjByMor(extensionManagerMor) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1854 def removeLicenseManager(licenseManagerMor) @cacheLock.synchronize(:EX) do removeObjByMor(licenseManagerMor) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 405 def removeObjByMor(objMor) raise "removeObjByMor: exclusive cache lock not held" unless @cacheLock.sync_exclusive? objType = objMor.vimBaseType.to_sym raise "removeObjByMor: Unknown VIM object type: #{objType}" unless (pmap = @propMap[objType]) baseName = pmap[:baseName] keyPath = pmap[:keyPath] keyPath2 = pmap[:keyPath2] objHash = instance_variable_get("#{baseName}ByMor") return unless (props = objHash.delete(objMor)) if keyPath key = props.fetch_path(keyPath) key2 = keyPath2 ? props.fetch_path(keyPath2) : nil objHash = instance_variable_get(baseName) objHash.delete(key) objHash.delete(key2) if key2 end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2518 def removeSelector(selName) remKeys = nil if selName.kind_of?(Symbol) remKeys = [selName] elsif selName.kind_of?(Hash) remKeys = selName.keys elsif selName.kind_of?(Array) remKeys = selName else raise "removeSelector: selName must be a symbol, hash or array, received #{selName.class}" end remKeys.each do |rk| raise "removeSelector: keys must be symbols, received #{rk.class}" unless rk.kind_of?(Symbol) end @configLock.synchronize(:EX) do remKeys.each do |rk| @selectorHash.delete(rk) @selectorPropPathHash.delete(rk) end end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 600 def removeVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do removeObjByMor(vmMor) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 220 def resetCache logger.info "MiqVimInventory.resetCache: clearing cache for #{@connId}" @cacheLock.synchronize(:EX) do @inventoryHash = nil @propMap.each_value do |pm| instance_variable_set("#{pm[:baseName]}ByMor", nil) instance_variable_set(pm[:baseName], nil) end end logger.info "MiqVimInventory.resetCache: cleared cache for #{@connId}" end
Return a single resourcePool object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 893 def resourcePoolByMor(rpMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(resourcePoolsByMor_locked[rpMor])) if selSpec.nil? return(applySelector(resourcePoolsByMor_locked[rpMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 861 def resourcePools(selSpec = nil) rp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? rp = dupObj(resourcePools_locked) else rp = applySelector(resourcePools_locked, selSpec) end end assert_no_locks rp end
Public accessor
Return an array of resource pool objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 905 def resourcePoolsByFilter(filter) rps = nil @cacheLock.synchronize(:SH) do rps = applyFilter(resourcePoolsByMor_locked.values, filter) rps = dupObj(rps) end assert_no_locks rps end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 877 def resourcePoolsByMor(selSpec = nil) rp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? rp = dupObj(resourcePoolsByMor_locked) else rp = applySelector(resourcePoolsByMor_locked, selSpec) end end assert_no_locks rp end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2551 def selSpecToPropPath(selSpec) return ss2pp(selSpec) unless selSpec.kind_of?(Symbol) @configLock.synchronize(:EX) do pp = @selectorPropPathHash[selSpec] return pp unless pp.nil? ss = getSelSpec(selSpec) raise "selSpecToPropPath: selector #{selSpec} not found" if ss.nil? return (@selectorPropPathHash[selSpec] = ss2pp(ss)) end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2485 def setSelector(selSpec) raise "setSelector: selSpec must be a hash, received #{selSpec.class}" unless selSpec.kind_of?(Hash) selSpec.each_key do |k| raise "setSelector: selSpec keys must be symbols, received #{k.class}" unless k.kind_of?(Symbol) end ov = nil selSpec.each_value do |v| if v.kind_of?(Array) v.each do |vv| unless vv.kind_of?(String) ov = vv break end end else ov = v unless v.kind_of?(String) end raise "setSelector: selSpec values must be strings or arrays of strings, received #{ov.class}" unless ov.nil? end @configLock.synchronize(:EX) do @selectorHash.merge!(selSpec) { |k, _o, n| @selectorPropPathHash.delete(k); n } end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 353 def snapshotFixup(ssObj, ssMorHash) # # There can be more than one root snapshot. # When this is the case, ssObj is an array instead of a hash. # ssObj.each { |sso| snapshotFixup(sso, ssMorHash) } if ssObj.kind_of? Array # # Hash snapshot info by MOR. # ssMorHash[String.new(ssObj['snapshot'].to_s)] = ssObj # # Hash snapshot info by create time. # # VMware API strips trailing '0's from the fractional seconds # which causes the string to not match what .iso8601(6) returns # # Example 12:12:59.123Z instead of 12:12:59.123000Z create_time = Time.parse(ssObj['createTime']).iso8601(6) ssMorHash[create_time] = ssObj # # Ensure childSnapshotList is always present and always an array, # evne if it's empty. # childList = ssObj['childSnapshotList'] if !childList ssObj['childSnapshotList'] = VimArray.new elsif !childList.kind_of? Array ssObj['childSnapshotList'] = VimArray.new { |a| a << childList } end ssObj['childSnapshotList'].each { |sso| snapshotFixup(sso, ssMorHash) } end
Construct an array of PropertySpec objects to retrieve the MORs for all the inventory objects we're interested in.
Most of thosse objects are subclasses of ManagedEntity, so they are all covered by the first entry. Datastore is a special case that requires its own entry.
# File lib/VMwareWebService/MiqVimInventory.rb, line 153 def spec propSpecAry = VimArray.new("ArrayOfPropertySpec") do |psa| psa << VimHash.new("PropertySpec") do |ps| ps.type = "ManagedEntity" ps.all = "false" end psa << VimHash.new("PropertySpec") do |ps| ps.type = "Datastore" ps.all = "false" end if isVirtualCenter psa << VimHash.new("PropertySpec") do |ps| ps.type = "LicenseManager" ps.all = "false" end psa << VimHash.new("PropertySpec") do |ps| ps.type = "ExtensionManager" ps.all = "false" end end end VimArray.new("ArrayOfPropertyFilterSpec") do |pfsa| pfsa << VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = propSpecAry pfs.objectSet = @objectSet end end end
Return a single storagePod object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1739 def storagePodByMor(spMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(storagePodsByMor_locked[spMor])) if selSpec.nil? return(applySelector(storagePodsByMor_locked[spMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1707 def storagePods(selSpec = nil) sp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? sp = dupObj(storagePods_locked) else sp = applySelector(storagePods_locked, selSpec) end end assert_no_locks sp end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 1723 def storagePodsByMor(selSpec = nil) sp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? sp = dupObj(storagePodsByMor_locked) else sp = applySelector(storagePodsByMor_locked, selSpec) end end assert_no_locks sp end
# File lib/VMwareWebService/MiqVimInventory.rb, line 198 def updateSpec updateSpecByPropMap(@propMap) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 183 def updateSpecByPropMap(propMap) VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa| propMap.each do |type, h| psa << VimHash.new("PropertySpec") do |ps| ps.type = type ps.all = h[:props].nil?.to_s ps.pathSet = h[:props] if h[:props] end end end pfs.objectSet = @objectSet end end
Return a single virtualApp object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 1005 def virtualAppByMor(vaMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(virtualAppsByMor_locked[vaMor])) if selSpec.nil? return(applySelector(virtualAppsByMor_locked[vaMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 973 def virtualApps(selSpec = nil) rp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? rp = dupObj(virtualApps_locked) else rp = applySelector(virtualApps_locked, selSpec) end end assert_no_locks rp end
Public accessor
Return an array of virtualApp objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1017 def virtualAppsByFilter(filter) rps = nil @cacheLock.synchronize(:SH) do rps = applyFilter(virtualAppsByMor_locked.values, filter) rps = dupObj(rps) end assert_no_locks rps end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 989 def virtualAppsByMor(selSpec = nil) rp = nil @cacheLock.synchronize(:SH) do if selSpec.nil? rp = dupObj(virtualAppsByMor_locked) else rp = applySelector(virtualAppsByMor_locked, selSpec) end end assert_no_locks rp end
Return a single VM object, given its MOR
# File lib/VMwareWebService/MiqVimInventory.rb, line 561 def virtualMachineByMor(vmMor, selSpec = nil) @cacheLock.synchronize(:SH) do return(dupObj(virtualMachinesByMor_locked[vmMor])) if selSpec.nil? return(applySelector(virtualMachinesByMor_locked[vmMor], selSpec)) end end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 529 def virtualMachines(selSpec = nil) vms = nil @cacheLock.synchronize(:SH) do if selSpec.nil? vms = dupObj(virtualMachines_locked) else vms = applySelector(virtualMachines_locked, selSpec) end end assert_no_locks vms end
Public accessor
Return an array of virtual machine objects that match the given property filter.
# File lib/VMwareWebService/MiqVimInventory.rb, line 573 def virtualMachinesByFilter(filter) vms = nil @cacheLock.synchronize(:SH) do vms = applyFilter(virtualMachinesByMor_locked.values, filter) vms = dupObj(vms) end assert_no_locks vms end
Public accessor
# File lib/VMwareWebService/MiqVimInventory.rb, line 545 def virtualMachinesByMor(selSpec = nil) vms = nil @cacheLock.synchronize(:SH) do if selSpec.nil? vms = dupObj(virtualMachinesByMor_locked) else vms = applySelector(virtualMachinesByMor_locked, selSpec) end end assert_no_locks vms end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2106 def vmDatacenterName(vmMor) @cacheLock.synchronize(:SH) do datacentersByMor_locked.each do |_n, o| begin f = foldersByMor_locked[o['vmFolder']] fVms = f['childEntity'] fVms.each do |vmMo| return o['name'] if vmMor == vmMo end rescue # Ignore errors, keep going and return nil if not found. end end return nil end end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2204 def waitForTask(tmor, className = nil) className ||= self.class.to_s logger.info "#{className}(#{@server}, #{@username})::waitForTask(#{tmor})" args = VimArray.new("ArrayOfPropertyFilterSpec") do |pfsa| pfsa << VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = VimArray.new("ArrayOfPropertySpec") do |psa| psa << VimHash.new("PropertySpec") do |ps| ps.type = tmor.vimType ps.all = "false" ps.pathSet = ["info.state", "info.error", "info.result"] end end pfs.objectSet = VimArray.new("ArrayOfObjectSpec") do |osa| VimHash.new("ObjectSpec") do |os| os.obj = tmor osa << os end end end end state = result = error = nil until state oca = retrievePropertiesCompat(@propCol, args) raise "waitForTask: task not found #{tmor}" if !oca || !oca[0] || !oca[0].propSet oca[0].propSet.each do |ps| if ps.name == "info.state" state = ps.val if ps.val == TaskInfoState::Success || ps.val == TaskInfoState::Error end error = ps.val if ps.name == "info.error" result = ps.val if ps.name == "info.result" end sleep 1 unless state end raise VimFault.new(error) if state == TaskInfoState::Error logger.info "#{className}(#{@server}, #{@username})::waitForTask: result = #{result}" result end
Protected Instance Methods
# File lib/VMwareWebService/MiqVimInventory.rb, line 1959 def addExtensionManagerObj(extensionManagerObj) addObjHash(:ExtensionManager, extensionManagerObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 1849 def addLicenseManagerObj(licenseManagerObj) addObjHash(:LicenseManager, licenseManagerObj) end
# File lib/VMwareWebService/MiqVimInventory.rb, line 595 def addVirtualMachineObj(vmObj) addObjHash(:VirtualMachine, vmObj) end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 747 def clusterComputeResourcesByMor_locked raise "clusterComputeResourcesByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@clusterComputeResourcesByMor) if @clusterComputeResourcesByMor clusterComputeResources_locked @clusterComputeResourcesByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 718 def clusterComputeResources_locked raise "clusterComputeResources_locked: cache lock not held" unless @cacheLock.sync_locked? return(@clusterComputeResources) if @clusterComputeResources logger.info "MiqVimInventory.clusterComputeResources_locked: loading ClusterComputeResource cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['ClusterComputeResource'], @propMap[:ClusterComputeResource][:props]) @clusterComputeResources = {} @clusterComputeResourcesByMor = {} ra.each do |crObj| addObjHash(:ClusterComputeResource, crObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.clusterComputeResources_locked: loaded ClusterComputeResource cache for #{@connId}" @clusterComputeResources end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 644 def computeResourcesByMor_locked raise "computeResourcesByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@computeResourcesByMor) if @computeResourcesByMor computeResources_locked @computeResourcesByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 615 def computeResources_locked raise "computeResources_locked: cache lock not held" unless @cacheLock.sync_locked? return(@computeResources) if @computeResources logger.info "MiqVimInventory.computeResources_locked: loading ComputeResource cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['ComputeResource'], @propMap[:ComputeResource][:props]) @computeResources = {} @computeResourcesByMor = {} ra.each do |crObj| addObjHash(:ComputeResource, crObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.computeResources_locked: loaded ComputeResource cache for #{@connId}" @computeResources end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1396 def dataStoresByMor_locked raise "dataStoresByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dataStoresByMor) if @dataStoresByMor dataStores_locked @dataStoresByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1367 def dataStores_locked raise "dataStores_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dataStores) if @dataStores logger.info "MiqVimInventory.dataStores_locked: loading Datastore cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['Datastore'], @propMap[:Datastore][:props]) @dataStores = {} @dataStoresByMor = {} ra.each do |dsObj| addDataStoreObj(dsObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.dataStores_locked: loaded Datastore cache for #{@connId}" @dataStores end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1168 def datacentersByMor_locked raise "datacentersByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@datacentersByMor) if @datacentersByMor datacenters_locked (@datacentersByMor) end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1139 def datacenters_locked raise "datacenters_locked: cache lock not held" unless @cacheLock.sync_locked? return(@datacenters) if @datacenters logger.info "MiqVimInventory.datacenters_locked: loading Datacenter cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['Datacenter'], @propMap[:Datacenter][:props]) @datacenters = {} @datacentersByMor = {} ra.each do |dcObj| addObjHash(:Datacenter, dcObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.datacenters_locked: loaded Datacenter cache for #{@connId}" @datacenters end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1515 def dvPortgroupsByMor_locked raise "dvPortgroupsByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dvPortgroupsByMor) if @dvPortgroupsByMor dvPortgroups_locked @dvPortgroupsByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1486 def dvPortgroups_locked raise "dvPortgroups_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dvPortgroups) if @dvPortgroups logger.info "MiqVimInventory.dvPortgroups_locked: loading DV Portgroup cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['DistributedVirtualPortgroup'], @propMap[:DistributedVirtualPortgroup][:props]) @dvPortgroups = {} @dvPortgroupsByMor = {} ra.each do |dvpObj| addDVPObj(dvpObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.dvPortgroups_locked: loaded DV Portgroup cache for #{@connId}" @dvPortgroups end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1609 def dvSwitchesByMor_locked raise "dvSwitchesByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dvSwitchesByMor) if @dvSwitchesByMor dvSwitches_locked @dvSwitchesByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1574 def dvSwitches_locked raise "dvSwitches_locked: cache lock not held" unless @cacheLock.sync_locked? return(@dvSwithces) if @dvSwitches logger.info "MiqVimInventory.dvSwitches_locked: loading DV Switch cache for #{@connId}" base_class = 'DistributedVirtualSwitch'.freeze child_classes = VimClass.child_classes(base_class) begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) moref_array = child_classes.collect { |klass| inventoryHash_locked[klass] }.flatten.compact ra = getMoPropMulti(moref_array, @propMap[base_class.to_sym][:props]) @dvSwitches = {} @dvSwitchesByMor = {} ra.each do |dvsObj| addDVSObj(dvsObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.dvSwitches_locked: loaded DV Switch cache for #{@connId}" @dvSwitches end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1898 def extensionManagersByMor_locked raise "extensionManagersByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@extensionManagersByMor) if @extensionManagersByMor extensionManagers_locked @extensionManagersByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1869 def extensionManagers_locked raise "extensionManagers_locked: cache lock not held" unless @cacheLock.sync_locked? return(@extensionManagers) if @extensionManagers logger.info "MiqVimInventory.extensionManagers_locked: loading ExtensionManager cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['ExtensionManager'], @propMap[:ExtensionManager][:props]) @extensionManagers = {} @extensionManagersByMor = {} ra.each do |extensionManagerObj| addExtensionManagerObj(extensionManagerObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.extensionManagers_locked: loaded ExtensionManager cache for #{@connId}" @extensionManagers end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1065 def foldersByMor_locked raise "foldersByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@foldersByMor) if @foldersByMor folders_locked @foldersByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1036 def folders_locked raise "folders_locked: cache lock not held" unless @cacheLock.sync_locked? return(@folders) if @folders logger.info "MiqVimInventory.folders_locked: loading Folder cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['Folder'], @propMap[:Folder][:props]) @folders = {} @foldersByMor = {} ra.each do |fObj| addObjHash(:Folder, fObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.folders_locked: loaded Folder cache for #{@connId}" @folders end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1271 def hostSystemsByMor_locked raise "hostSystemsByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@hostSystemsByMor) if @hostSystemsByMor hostSystems_locked @hostSystemsByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1242 def hostSystems_locked raise "hostSystems_locked: cache lock not held" unless @cacheLock.sync_locked? return(@hostSystems) if @hostSystems logger.info "MiqVimInventory.hostSystems_locked: loading HostSystem cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['HostSystem'], @propMap[:HostSystem][:props]) @hostSystems = {} @hostSystemsByMor = {} ra.each do |hsObj| addHostSystemObj(hsObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.hostSystems_locked: loaded HostSystem cache for #{@connId}" @hostSystems end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1788 def licenseManagersByMor_locked raise "licenseManagerByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@licenseManagersByMor) if @licenseManagersByMor licenseManagers_locked @licenseManagersByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1759 def licenseManagers_locked raise "licenseManagers_locked: cache lock not held" unless @cacheLock.sync_locked? return(@licenseManagers) if @licenseManagers logger.info "MiqVimInventory.licenseManagers_locked: loading LicenseManager cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['LicenseManager'], @propMap[:LicenseManager][:props]) @licenseManagers = {} @licenseManagersByMor = {} ra.each do |licenseManagerObj| addLicenseManagerObj(licenseManagerObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.licenseManagers_locked: loaded LicenseManager cache for #{@connId}" @licenseManagers end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 850 def resourcePoolsByMor_locked raise "resourcePoolsByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@resourcePoolsByMor) if @resourcePoolsByMor resourcePools_locked @resourcePoolsByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 821 def resourcePools_locked raise "resourcePools_locked: cache lock not held" unless @cacheLock.sync_locked? return(@resourcePools) if @resourcePools logger.info "MiqVimInventory.resourcePools_locked: loading ResourcePool cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['ResourcePool'], @propMap[:ResourcePool][:props]) @resourcePools = {} @resourcePoolsByMor = {} ra.each do |rpObj| addObjHash(:ResourcePool, rpObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.resourcePools_locked: loaded ResourcePool cache for #{@connId}" @resourcePools end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1696 def storagePodsByMor_locked raise "storagePodsByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@storagePodsByMor) if @storagePodsByMor storagePods_locked @storagePodsByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 1667 def storagePods_locked raise "storagePods_locked: cache lock not held" unless @cacheLock.sync_locked? return(@storagePods) if @storagePods logger.info "MiqVimInventory.storagePods_locked: loading Datastore Cluster cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['StoragePod'], @propMap[:StoragePod][:props]) @storagePods = {} @storagePodsByMor = {} ra.each do |dsObj| addStoragePodObj(dsObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.storagePods_locked: loaded Datastore Cluster cache for #{@connId}" @storagePods end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 962 def virtualAppsByMor_locked raise "virtualAppsByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@virtualAppsByMor) if @virtualAppsByMor virtualApps_locked @virtualAppsByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 924 def virtualApps_locked raise "virtualApps_locked: cache lock not held" unless @cacheLock.sync_locked? # # Not supported in v2.0 or v2.5 # if @v2 @virtualApps = {} @virtualAppsByMor = {} end return(@virtualApps) if @virtualApps logger.info "MiqVimInventory.virtualApps_locked: loading VirtualApp cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['VirtualApp'], @propMap[:VirtualApp][:props]) @virtualApps = {} @virtualAppsByMor = {} ra.each do |rpObj| addObjHash(:VirtualApp, rpObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.virtualApps_locked: loaded VirtualApp cache for #{@connId}" @virtualApps end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 518 def virtualMachinesByMor_locked raise "virtualMachinesByMor_locked: cache lock not held" unless @cacheLock.sync_locked? return(@virtualMachinesByMor) if @virtualMachinesByMor virtualMachines_locked @virtualMachinesByMor end
For internal use. Must be called with cache lock held Returns with the cache lock held - must be unlocked by caller.
# File lib/VMwareWebService/MiqVimInventory.rb, line 489 def virtualMachines_locked raise "virtualMachines_locked: cache lock not held" unless @cacheLock.sync_locked? return(@virtualMachines) if @virtualMachines logger.info "MiqVimInventory.virtualMachines_locked: loading VirtualMachine cache for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) ra = getMoPropMulti(inventoryHash_locked['VirtualMachine'], @propMap[:VirtualMachine][:props]) @virtualMachines = {} @virtualMachinesByMor = {} ra.each do |vmObj| addVirtualMachineObj(vmObj) end ensure @cacheLock.sync_unlock if unlock end logger.info "MiqVimInventory.virtualMachines_locked: loaded VirtualMachine cache for #{@connId}" @virtualMachines end
Private Instance Methods
Return array and index?
# File lib/VMwareWebService/MiqVimInventory.rb, line 2788 def getVimArrayEnt(arrayProp, key, create = false) return nil, nil unless arrayProp.kind_of?(Array) if getVimArrayType(arrayProp) == 'ManagedObjectReference' arrayProp.each_index { |n| return arrayProp, n if arrayProp[n] == key } else hasKey = false arrayProp.each_index do |n| next unless (h = arrayProp[n]).kind_of? Hash if h.key?('key') hasKey = true return arrayProp, n if h['key'] == key end end unless hasKey begin nkey = Integer(key) return arrayProp, nkey rescue end end if create h = VimHash.new h['key'] = key arrayProp << h return arrayProp, (arrayProp.length - 1) end end return nil, nil end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2764 def getVimArrayType(arrayProp) return nil if !arrayProp.respond_to?(:xsiType) || !(typeStr = arrayProp.xsiType) return $1 if typeStr =~ /^ArrayOf(.*)$/ nil end
# File lib/VMwareWebService/MiqVimInventory.rb, line 266 def hashObj(type, props) type = type.to_sym if type.kind_of?(String) raise "hashObj: exclusive cache lock not held" unless @cacheLock.sync_exclusive? raise "Unknown VIM object type: #{type}" unless (pmap = @propMap[type]) return nil unless props baseName = pmap[:baseName] keyPath = pmap[:keyPath] mor = props['MOR'] if keyPath key = props.fetch_path(keyPath) if !key logger.debug "hashObj: key is nil for #{mor}: #{keyPath}" elsif key.empty? logger.debug "hashObj: key is empty for #{mor}: #{keyPath}" key = nil props.store_path(keyPath, nil) end else key = nil end if key objHash = instance_variable_get(baseName) objHash[key] = props end if mor objHash = instance_variable_get("#{baseName}ByMor") objHash[mor] = props end props end
Here, keyString can be a property path in the form: a.b.c If that's the case, return baseHash['b'] for the hash, and 'c' for the key creating intermediate nodes as needed.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2702 def hashTarget(baseHash, keyString, create = false) return baseHash, keyString unless keyString.index('.') h = baseHash ka = splitPropPath(keyString) ka[0...-1].each do |k| k, arrayKey = tagAndKey(k) if arrayKey array, idx = getVimArrayEnt(h[k], arrayKey, create) raise "hashTarget: Could not traverse tree through array element #{k}[#{arrayKey}] in #{keyString}" unless array h = array[idx] else h[k] = VimHash.new unless h[k] h = h[k] end end return h, ka[-1] end
Array keys (between “[” and “]”) can contain “.”, so we can't just use split.
# File lib/VMwareWebService/MiqVimInventory.rb, line 2725 def splitPropPath(propPath) pathArray = [] inKey = false pc = '' propPath.split(//).each do |c| case c when '.' unless inKey pathArray << pc pc = '' next end when '[' inKey = true when ']' inKey = false end pc << c end pathArray << pc unless pc.empty? pathArray end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2565 def ss2pp(ss) # We add "MOR" it isn't from VMware so always strip it out of # the propPath even if it is in the selSpec getSelSpec(ss).collect { |s| s.split("[")[0] }.uniq - ["MOR"] end
# File lib/VMwareWebService/MiqVimInventory.rb, line 2751 def tagAndKey(propStr) return propStr, nil unless propStr.include? '[' if propStr =~ /([^\[]+)\[([^\]]+)\]/ tag, key = $1, $2 else raise "tagAndKey: malformed property string #{propStr}" end key = key[1...-1] if key[0, 1] == '"' && key[-1, 1] == '"' return tag, key end