Class: MiqVimInventory
- Inherits:
-
MiqVimClientBase
- Object
- Handsoap::Service
- VimService
- MiqVimClientBase
- MiqVimInventory
- Includes:
- MiqVimDump, MiqVimObjectSet, VimPropMaps
- Defined in:
- lib/VMwareWebService/MiqVimInventory.rb
Direct Known Subclasses
Constant Summary collapse
- @@selectorHash =
{}
- @@cacheScope =
:cache_scope_full
Constants included from VimPropMaps
VimPropMaps::CorePropMap, VimPropMaps::EmsRefreshPropMap, VimPropMaps::EventMonitorPropMap, VimPropMaps::FullPropMap, VimPropMaps::PropMap4, VimPropMaps::UpdatePropMapsByType, VimPropMaps::VimCoreUpdaterPropMap
Instance Attribute Summary collapse
-
#cacheLock ⇒ Object
readonly
Returns the value of attribute cacheLock.
-
#configLock ⇒ Object
readonly
Returns the value of attribute configLock.
Attributes inherited from MiqVimClientBase
#connId, #password, #server, #username
Attributes inherited from VimService
#about, #apiVersion, #isVirtualCenter, #serviceInstanceMor, #session_cookie, #sic, #v2, #v20, #v4
Class Method Summary collapse
- .cacheScope ⇒ Object
- .cacheScope=(val) ⇒ Object
-
.dsPath?(p) ⇒ Boolean
Datastore/path utility methods.
- .dsRelativePath(p) ⇒ Object
- .path2dsName(p) ⇒ Object
- .removeSelector(selName) ⇒ Object
- .setSelector(selSpec) ⇒ Object
Instance Method Summary collapse
- #addDataStore(dsMor) ⇒ Object
- #addDataStoreObj(dsObj) ⇒ Object
- #addDVPObj(dvpObj) ⇒ Object
- #addDVSObj(dvsObj) ⇒ Object
- #addHostSystem(hsMor) ⇒ Object
- #addHostSystemObj(hsObj) ⇒ Object
-
#addObjByMor(objMor) ⇒ Object
Extract the properties for the VIM object represented by objMor and hash them.
-
#addObjHash(objType, objHash) ⇒ Object
Add the property hash for the VIM object to the appropriate inventory hashes.
-
#addProperty(key, property) ⇒ Object
def initialize.
- #addStoragePodObj(spObj) ⇒ Object
- #addToCollection(hash, tag, val) ⇒ Object
- #addVirtualMachine(vmMor) ⇒ Object
- #allPropsFromCache(hashName, props) ⇒ Object
- #applyFilter(objArr, propFilter) ⇒ Object
- #applySelector(topObj, selSpec) ⇒ Object
- #applySelSpec(topObj, retObj, pa) ⇒ Object
- #assert_no_locks ⇒ Object
- #browseDiagnosticLog(key, start = nil, lines = nil, host = nil) ⇒ Object
- #browseDiagnosticLogEx(key, start = nil, lines = nil, host = nil) ⇒ Object
- #cacheStats(pref) ⇒ Object
- #cancelTask(tmor) ⇒ Object
-
#clusterComputeResourceByMor(ccrMor, selSpec = nil) ⇒ Object
Return a single clusterComputeResource object, given its MOR.
-
#clusterComputeResources(selSpec = nil) ⇒ Object
Public accessor.
-
#clusterComputeResourcesByFilter(filter) ⇒ Object
Public accessor.
-
#clusterComputeResourcesByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#computeResourceByMor(crMor, selSpec = nil) ⇒ Object
Return a single computeResource object, given its MOR.
-
#computeResources(selSpec = nil) ⇒ Object
Public accessor.
-
#computeResourcesByFilter(filter) ⇒ Object
Public accessor.
-
#computeResourcesByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#conditionalCopy(obj) ⇒ Object
When used in the broker - DRB - this method is redefined to create a deep clone of the object.
-
#currentSession ⇒ Object
def resetCache.
-
#datacenterByMor(dcMor, selSpec = nil) ⇒ Object
Return a single datacenter object, given its MOR.
-
#datacenters(selSpec = nil) ⇒ Object
Public accessor.
-
#datacentersByFilter(filter) ⇒ Object
Public accessor.
-
#datacentersByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#dataStoreByMor(dsMor, selSpec = nil) ⇒ Object
Return a single hostSystem object, given its MOR.
-
#datastorePath(p) ⇒ Object
def localVmPath.
-
#dataStores(selSpec = nil) ⇒ Object
Public accessor.
-
#dataStoresByFilter(filter) ⇒ Object
Public accessor.
- #dataStoresByFilter_local(filter) ⇒ Object
-
#dataStoresByMor(selSpec = nil) ⇒ Object
Public accessor.
- #deepClone(obj) ⇒ Object
- #deleteProperty(key, property) ⇒ Object
- #dsName2mo(dsn) ⇒ Object
- #dsName2mo_local(dsn) ⇒ Object
- #dsName2path(dsn) ⇒ Object
- #dsPath?(p) ⇒ Boolean
- #dsRelativePath(p) ⇒ Object
-
#dupObj(obj) ⇒ Object
When used in the broker - DRB - this method is redefined to carry the cacheLock into the DRB dump method.
-
#dvPortgroupByMor(dvpMor, selSpec = nil) ⇒ Object
Return a single storagePod object, given its MOR.
-
#dvPortgroups(selSpec = nil) ⇒ Object
Public accessor.
-
#dvPortgroupsByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#dvSwitchByMor(dvsMor, selSpec = nil) ⇒ Object
Return a single DV Switch object, given its MOR.
-
#dvSwitches(selSpec = nil) ⇒ Object
Public accessor.
-
#dvSwitchesByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#folderByMor(fMor, selSpec = nil) ⇒ Object
Return a single folder object, given its MOR.
-
#folders(selSpec = nil) ⇒ Object
Public accessor.
-
#foldersByFilter(filter) ⇒ Object
Public accessor.
-
#foldersByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#getMoProp(mo, path = nil) ⇒ Object
Public accessor.
-
#getMoProp_local(mo, path = nil) ⇒ Object
Retrieve the properties for a single object, given its managed object reference.
-
#getMoPropMulti(moa, path = nil) ⇒ Object
Retrieve the properties for multiple objects of the same type, given an array of managed object references.
-
#getMoPropMultiIter(moa, path = nil) ⇒ Object
def getMoPropMulti.
- #getSelector(selName) ⇒ Object
- #getSelSpec(selSpec) ⇒ Object
- #getTaskMor(tmor) ⇒ Object
-
#getTasks ⇒ Object
Task utility methods.
-
#getTasksByFilter(filter) ⇒ Object
private :getTasks.
- #hasProp?(baseHash, prop) ⇒ Boolean
-
#hostSystemByMor(hsMor, selSpec = nil) ⇒ Object
Return a single hostSystem object, given its MOR.
-
#hostSystems(selSpec = nil) ⇒ Object
Public accessor.
-
#hostSystemsByFilter(filter) ⇒ Object
Public accessor.
-
#hostSystemsByMor(selSpec = nil) ⇒ Object
Public accessor.
- #hostSystemsStorageDevice(hostMors, selSpec = nil) ⇒ Object
-
#initialize(server, username, password, cacheScope = nil) ⇒ MiqVimInventory
constructor
A new instance of MiqVimInventory.
- #inventoryHash ⇒ Object
-
#inventoryHash_locked ⇒ Object
A hash of managed object references for all the objects we care about.
- #isAlive? ⇒ Boolean
-
#isDead ⇒ Object
For testing.
- #isHostAgent? ⇒ Boolean
- #isVirtualCenter? ⇒ Boolean
- #keyExistsInCache?(hashName, key) ⇒ Boolean
- #keyFromCache(hashName, props, value = nil) ⇒ Object
- #loadCache ⇒ Object
- #localVmPath(p) ⇒ Object
- #logCacheCounts(pref) ⇒ Object
-
#logUserEvent(entity, msg) ⇒ Object
Generate a user event associated with the given managed object.
- #objFixUp(objType, objHash) ⇒ Object
- #path2dsName(p) ⇒ Object
-
#pollTask(tmor, className = nil) ⇒ Object
def waitForTask.
- #propFromCache(hashName, key, props) ⇒ Object
- #propValue(baseHash, prop) ⇒ Object
-
#queryLogDescriptions(host = nil) ⇒ Object
Log and diagnostic methods.
- #refreshVirtualMachine(vmMor) ⇒ Object
- #removeObjByMor(objMor) ⇒ Object
- #removeSelector(selName) ⇒ Object
- #removeVirtualMachine(vmMor) ⇒ Object
- #resetCache ⇒ Object
-
#resourcePoolByMor(rpMor, selSpec = nil) ⇒ Object
Return a single resourcePool object, given its MOR.
-
#resourcePools(selSpec = nil) ⇒ Object
Public accessor.
-
#resourcePoolsByFilter(filter) ⇒ Object
Public accessor.
-
#resourcePoolsByMor(selSpec = nil) ⇒ Object
Public accessor.
- #selSpecToPropPath(selSpec) ⇒ Object
- #setSelector(selSpec) ⇒ Object
- #snapshotFixup(ssObj, ssMorHash) ⇒ Object
-
#spec ⇒ Object
Construct an array of PropertySpec objects to retrieve the MORs for all the inventory objects we’re interested in.
-
#storagePodByMor(spMor, selSpec = nil) ⇒ Object
Return a single storagePod object, given its MOR.
-
#storagePods(selSpec = nil) ⇒ Object
Public accessor.
-
#storagePodsByMor(selSpec = nil) ⇒ Object
Public accessor.
- #updateSpec ⇒ Object
- #updateSpecByPropMap(propMap) ⇒ Object
-
#virtualAppByMor(vaMor, selSpec = nil) ⇒ Object
Return a single virtualApp object, given its MOR.
-
#virtualApps(selSpec = nil) ⇒ Object
Public accessor.
-
#virtualAppsByFilter(filter) ⇒ Object
Public accessor.
-
#virtualAppsByMor(selSpec = nil) ⇒ Object
Public accessor.
-
#virtualMachineByMor(vmMor, selSpec = nil) ⇒ Object
Return a single VM object, given its MOR.
-
#virtualMachines(selSpec = nil) ⇒ Object
Public accessor.
-
#virtualMachinesByFilter(filter) ⇒ Object
Public accessor.
-
#virtualMachinesByMor(selSpec = nil) ⇒ Object
Public accessor.
- #vmDatacenterName(vmMor) ⇒ Object
- #waitForTask(tmor, className = nil) ⇒ Object
Methods included from MiqVimObjectSet
Methods included from MiqVimDump
#dumpAll, #dumpArray, #dumpClass, #dumpHash, #dumpHostInfo, #dumpMors, #dumpObj, #dumpToLog=, #globalIndent=, #indentedPrint
Methods included from VimPropMaps
Methods inherited from MiqVimClientBase
#acquireCloneTicket, #connect, #currentServerTime, #disconnect, #receiveTimeout, receiveTimeout, #receiveTimeout=, receiveTimeout=, #sdk_uri, #verify_callback
Methods inherited from VimService
#acquireCloneTicket, #acquireMksTicket, #acquireTicket, #addHost_Task, #addInternetScsiSendTargets, #addInternetScsiStaticTargets, #addStandaloneHost_Task, #cancelWaitForUpdates, #cloneVM_Task, #continueRetrievePropertiesEx, #createAlarm, #createCollectorForEvents, #createCustomizationSpec, #createFilter, #createFolder, #createNasDatastore, #createSnapshot_Task, #createVM_Task, #currentTime, #customizationSpecItemToXml, #deleteCustomizationSpec, #deselectVnicForNicType, #destroyCollector, #destroyPropertyFilter, #destroy_Task, #disableRuleset, #doesCustomizationSpecExist, #enableRuleset, #enterMaintenanceMode_Task, #exitMaintenanceMode_Task, #getAlarm, #getCustomizationSpec, #login, #logout, #markAsTemplate, #markAsVirtualMachine, #migrateVM_Task, #moveIntoFolder_Task, #powerDownHostToStandBy_Task, #powerOffVM_Task, #powerOnVM_Task, #powerUpHostFromStandBy_Task, #queryAvailablePerfMetric, #queryDescriptions, #queryDvsConfigTarget, #queryNetConfig, #queryOptions, #queryPerf, #queryPerfComposite, #queryPerfProviderSummary, #readNextEvents, #readPreviousEvents, #rebootGuest, #rebootHost_Task, #reconfigVM_Task, #reconfigureAlarm, #refreshFirewall, #refreshNetworkSystem, #refreshServices, #registerVM_Task, #relocateVM_Task, #removeAlarm, #removeAllSnapshots_Task, #removeSnapshot_Task, #renameSnapshot, #rename_Task, #resetCollector, #resetVM_Task, #restartService, #retrieveProperties, #retrievePropertiesCompat, #retrievePropertiesEx, #retrievePropertiesIter, #retrieveServiceContent, #revertToCurrentSnapshot_Task, #revertToSnapshot_Task, #rewindCollector, #searchDatastoreSubFolders_Task, #searchDatastore_Task, #selectVnicForNicType, #setCollectorPageSize, #setField, #setTaskDescription, #setTaskState, #shutdownGuest, #shutdownHost_Task, #standbyGuest, #startService, #stopService, #suspendVM_Task, #uninstallService, #unregisterVM, #updateDefaultPolicy, #updateServicePolicy, #updateSoftwareInternetScsiEnabled, #waitForUpdates, #waitForUpdatesEx, #xmlToCustomizationSpecItem
Constructor Details
#initialize(server, username, password, cacheScope = nil) ⇒ MiqVimInventory
Returns a new instance of MiqVimInventory.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 22 def initialize(server, username, password, cacheScope = nil) super(server, username, password) cacheScope ||= @@cacheScope case cacheScope when :cache_scope_full @propMap = FullPropMap $vim_log.info "MiqVimInventory: using property map FullPropMap" when :cache_scope_ems_refresh @propMap = EmsRefreshPropMap $vim_log.info "MiqVimInventory: using property map EmsRefreshPropMap" when :cache_scope_core @propMap = CorePropMap $vim_log.info "MiqVimInventory: using property map CorePropMap" when :cache_scope_event_monitor @propMap = EventMonitorPropMap $vim_log.info "MiqVimInventory: using property map EventMonitorPropMap" else @propMap = FullPropMap $vim_log.info "MiqVimInventory: unrecognized cache scope #{cacheScope}, using FullPropMap" end if @v2 @propMap = dupProps(@propMap) deleteProperty(:HostSystem, "capability.storageVMotionSupported") deleteProperty(:HostSystem, "capability.vmotionWithStorageVMotionSupported") deleteProperty(:Datastore, "summary.uncommitted") deleteProperty(:Datastore, "summary.maintenanceMode") deleteProperty(:VirtualMachine, "config.cpuHotAddEnabled") deleteProperty(:VirtualMachine, "config.cpuHotRemoveEnabled") deleteProperty(:VirtualMachine, "config.hardware.numCoresPerSocket") deleteProperty(:VirtualMachine, "config.hotPlugMemoryIncrementSize") deleteProperty(:VirtualMachine, "config.hotPlugMemoryLimit") deleteProperty(:VirtualMachine, "config.memoryHotAddEnabled") deleteProperty(:VirtualMachine, "summary.config.ftInfo.instanceUuids") deleteProperty(:VirtualMachine, "summary.storage.unshared") deleteProperty(:VirtualMachine, "summary.storage.committed") deleteProperty(:ClusterComputeResource, "configuration.dasConfig.admissionControlPolicy") if @v20 deleteProperty(:VirtualMachine, "availableField") deleteProperty(:HostSystem, "config.dateTimeInfo") end else if @v4 @propMap = dupProps(@propMap) deleteProperty(:Datastore, "summary.maintenanceMode") if cacheScope != :cache_scope_event_monitor addProperty(:VirtualMachine, "runtime.memoryOverhead") deleteProperty(:VirtualMachine, "config.hardware.numCoresPerSocket") end end @propMap = @propMap.merge(PropMap4) end @propCol = @sic.propertyCollector @rootFolder = @sic.rootFolder @objectSet = objectSet @spec = spec @updateSpec = updateSpec @globalIndent = "" @selectorHash = @@selectorHash @selectorPropPathHash = {} @cacheLock = Sync.new @configLock = Sync.new # Un-comment to enable Sync lock debugging. # extend VimSyncDebug resetCache __connect @alive = true end |
Instance Attribute Details
#cacheLock ⇒ Object (readonly)
Returns the value of attribute cacheLock.
10 11 12 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 10 def cacheLock @cacheLock end |
#configLock ⇒ Object (readonly)
Returns the value of attribute configLock.
10 11 12 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 10 def configLock @configLock end |
Class Method Details
.cacheScope ⇒ Object
115 116 117 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 115 def self.cacheScope @@cacheScope end |
.cacheScope=(val) ⇒ Object
119 120 121 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 119 def self.cacheScope=(val) @@cacheScope = val end |
.dsPath?(p) ⇒ Boolean
Datastore/path utility methods.
1825 1826 1827 1828 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1825 def self.dsPath?(p) return true if p =~ /^\[[^\]]*\].*/ false end |
.dsRelativePath(p) ⇒ Object
1869 1870 1871 1872 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1869 def self.dsRelativePath(p) raise "dsRelativePath: #{p} is not a datastore path" unless dsPath?(p) p.gsub(/^.*\]\s*/, '') end |
.path2dsName(p) ⇒ Object
1834 1835 1836 1837 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1834 def self.path2dsName(p) return nil unless MiqVimInventory.dsPath?(p) p.gsub(/^\[([^\]]*)\].*/, '\1') end |
.removeSelector(selName) ⇒ Object
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2270 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 "MiqVimBroker.removeSelector: selName must be a symbol, hash or array, received #{selName.class}" end remKeys.each do |rk| raise "MiqVimBroker.removeSelector: keys must be symbols, received #{rk.class}" unless rk.kind_of?(Symbol) end remKeys.each do |rk| @@selectorHash.delete(rk) end end |
.setSelector(selSpec) ⇒ Object
2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2248 def self.setSelector(selSpec) raise "MiqVimBroker.setSelector: selSpec must be a hash, received #{selSpec.class}" unless selSpec.kind_of?(Hash) selSpec.each_key do |k| raise "MiqVimBroker.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 "MiqVimBroker.setSelector: selSpec values must be strings or arrays of strings, received #{ov.class}" unless ov.nil? end @@selectorHash.merge!(selSpec) end |
Instance Method Details
#addDataStore(dsMor) ⇒ Object
1496 1497 1498 1499 1500 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1496 def addDataStore(dsMor) @cacheLock.synchronize(:EX) do addObjByMor(dsMor) end end |
#addDataStoreObj(dsObj) ⇒ Object
1502 1503 1504 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1502 def addDataStoreObj(dsObj) addObjHash(:Datastore, dsObj) end |
#addDVPObj(dvpObj) ⇒ Object
1590 1591 1592 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1590 def addDVPObj(dvpObj) addObjHash(:DistributedVirtualPortgroup, dvpObj) end |
#addDVSObj(dvsObj) ⇒ Object
1684 1685 1686 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1684 def addDVSObj(dvsObj) addObjHash(:DistributedVirtualSwitch, dvsObj) end |
#addHostSystem(hsMor) ⇒ Object
1373 1374 1375 1376 1377 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1373 def addHostSystem(hsMor) @cacheLock.synchronize(:EX) do addObjByMor(hsMor) end end |
#addHostSystemObj(hsObj) ⇒ Object
1379 1380 1381 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1379 def addHostSystemObj(hsObj) addObjHash(:HostSystem, hsObj) end |
#addObjByMor(objMor) ⇒ Object
Extract the properties for the VIM object represented by objMor and hash them. Add the resulting property hash to the appropriate inventory hashes.
418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 418 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 |
#addObjHash(objType, objHash) ⇒ Object
Add the property hash for the VIM object to the appropriate inventory hashes.
335 336 337 338 339 340 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 335 def addObjHash(objType, objHash) raise "addObjHash: exclusive cache lock not held" unless @cacheLock.sync_exclusive? objHash = hashObj(objType, objHash) objFixUp(objType, objHash) end |
#addProperty(key, property) ⇒ Object
def initialize
105 106 107 108 109 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 105 def addProperty(key, property) return if (pm = @propMap[key]).nil? property.split('.').each { |p| return if pm.include?(p) } @propMap[key][:props] << property end |
#addStoragePodObj(spObj) ⇒ Object
1771 1772 1773 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1771 def addStoragePodObj(spObj) addObjHash(:StoragePod, spObj) end |
#addToCollection(hash, tag, val) ⇒ Object
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2576 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 |
#addVirtualMachine(vmMor) ⇒ Object
608 609 610 611 612 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 608 def addVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do return(addObjByMor(vmMor)) end end |
#allPropsFromCache(hashName, props) ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 466 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 |
#applyFilter(objArr, propFilter) ⇒ Object
2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2436 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 |
#applySelector(topObj, selSpec) ⇒ Object
2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2377 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 |
#applySelSpec(topObj, retObj, pa) ⇒ Object
2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2406 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 |
#assert_no_locks ⇒ Object
232 233 234 235 236 237 238 239 240 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 232 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 |
#browseDiagnosticLog(key, start = nil, lines = nil, host = nil) ⇒ Object
1936 1937 1938 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1936 def browseDiagnosticLog(key, start = nil, lines = nil, host = nil) super(@sic.diagnosticManager, host, key, start, lines) end |
#browseDiagnosticLogEx(key, start = nil, lines = nil, host = nil) ⇒ Object
1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1940 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 |
#cacheStats(pref) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 141 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? $vim_log.info "#{pref}#{hnm}: is nil" next end keya = hashByMor.keys obja = hashByMor.values $vim_log.info "#{pref}#{hnm}: #keys = #{keya.length}" $vim_log.info "#{pref}#{hnm}: #objects = #{obja.length}" obja.compact! obja.uniq! $vim_log.info "#{pref}#{hnm}: #unique non-nill objects = #{obja.length}" unless hashByKey.nil? keyb = hashByKey.keys objb = hashByKey.values $vim_log.info "#{pref}#{hn}: #keys = #{keyb.length}" $vim_log.info "#{pref}#{hn}: #objects = #{objb.length}" objb.compact! objb.uniq! $vim_log.info "#{pref}#{hn}: #unique non-nill objects = #{objb.length}" obja.concat(objb).uniq! end $vim_log.info "#{pref}TOTAL: #unique non-nill objects = #{obja.length}" cacheSz = Marshal.dump(obja).length $vim_log.info "#{pref}TOTAL: size of objects = #{cacheSz}" $vim_log.info "#{pref}****" totalCacheSz += cacheSz end $vim_log.info "#{pref}****************" $vim_log.info "#{pref}TOTAL: cache size = #{totalCacheSz}" $vim_log.info "#{pref}****************" end totalCacheSz end |
#cancelTask(tmor) ⇒ Object
2005 2006 2007 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2005 def cancelTask(tmor) super(getTaskMor(tmor)) end |
#clusterComputeResourceByMor(ccrMor, selSpec = nil) ⇒ Object
Return a single clusterComputeResource object, given its MOR
815 816 817 818 819 820 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 815 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 |
#clusterComputeResources(selSpec = nil) ⇒ Object
Public accessor
783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 783 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 |
#clusterComputeResourcesByFilter(filter) ⇒ Object
Public accessor
Return an array of cluster compute resource objects that match the given property filter.
827 828 829 830 831 832 833 834 835 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 827 def clusterComputeResourcesByFilter(filter) crs = nil @cacheLock.synchronize(:SH) do crs = applyFilter(clusterComputeResourcesByMor_locked.values, filter) crs = dupObj(crs) end assert_no_locks crs end |
#clusterComputeResourcesByMor(selSpec = nil) ⇒ Object
Public accessor
799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 799 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 |
#computeResourceByMor(crMor, selSpec = nil) ⇒ Object
Return a single computeResource object, given its MOR
712 713 714 715 716 717 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 712 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 |
#computeResources(selSpec = nil) ⇒ Object
Public accessor
680 681 682 683 684 685 686 687 688 689 690 691 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 680 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 |
#computeResourcesByFilter(filter) ⇒ Object
Public accessor
Return an array of compute resource objects that match the given property filter.
724 725 726 727 728 729 730 731 732 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 724 def computeResourcesByFilter(filter) crs = nil @cacheLock.synchronize(:SH) do crs = applyFilter(computeResourcesByMor_locked.values, filter) crs = dupObj(crs) end assert_no_locks crs end |
#computeResourcesByMor(selSpec = nil) ⇒ Object
Public accessor
696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 696 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 |
#conditionalCopy(obj) ⇒ Object
When used in the broker - DRB - this method is redefined to create a deep clone of the object.
2643 2644 2645 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2643 def conditionalCopy(obj) obj end |
#currentSession ⇒ Object
def resetCache
263 264 265 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 263 def currentSession getMoProp(@sic.sessionManager, "currentSession") end |
#datacenterByMor(dcMor, selSpec = nil) ⇒ Object
Return a single datacenter object, given its MOR
1236 1237 1238 1239 1240 1241 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1236 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 |
#datacenters(selSpec = nil) ⇒ Object
Public accessor
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1204 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 |
#datacentersByFilter(filter) ⇒ Object
Public accessor
Return an array of datacenter objects that match the given property filter.
1248 1249 1250 1251 1252 1253 1254 1255 1256 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1248 def datacentersByFilter(filter) dc = nil @cacheLock.synchronize(:SH) do dc = applyFilter(datacentersByMor_locked.values, filter) dc = dupObj(dc) end assert_no_locks dc end |
#datacentersByMor(selSpec = nil) ⇒ Object
Public accessor
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1220 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 |
#dataStoreByMor(dsMor, selSpec = nil) ⇒ Object
Return a single hostSystem object, given its MOR
1464 1465 1466 1467 1468 1469 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1464 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 |
#datastorePath(p) ⇒ Object
def localVmPath
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1894 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 |
#dataStores(selSpec = nil) ⇒ Object
Public accessor
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1432 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 |
#dataStoresByFilter(filter) ⇒ Object
Public accessor
Return an array of data store objects that match the given property filter.
1476 1477 1478 1479 1480 1481 1482 1483 1484 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1476 def dataStoresByFilter(filter) ds = nil @cacheLock.synchronize(:SH) do ds = applyFilter(dataStoresByMor_locked.values, filter) ds = dupObj(ds) end assert_no_locks ds end |
#dataStoresByFilter_local(filter) ⇒ Object
1486 1487 1488 1489 1490 1491 1492 1493 1494 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1486 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 |
#dataStoresByMor(selSpec = nil) ⇒ Object
Public accessor
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1448 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 |
#deepClone(obj) ⇒ Object
2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2647 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 |
#deleteProperty(key, property) ⇒ Object
111 112 113 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 111 def deleteProperty(key, property) @propMap[key][:props].delete(property) unless @propMap[key].nil? end |
#dsName2mo(dsn) ⇒ Object
1851 1852 1853 1854 1855 1856 1857 1858 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1851 def dsName2mo(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dupObj(dataStores_locked[dsn]['summary']["datastore"]) end assert_no_locks ret end |
#dsName2mo_local(dsn) ⇒ Object
1860 1861 1862 1863 1864 1865 1866 1867 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1860 def dsName2mo_local(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dataStores_locked[dsn]['summary']["datastore"] end assert_no_locks ret end |
#dsName2path(dsn) ⇒ Object
1843 1844 1845 1846 1847 1848 1849 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1843 def dsName2path(dsn) ret = nil @cacheLock.synchronize(:SH) do ret = dataStores_locked[dsn]['summary']["url"] end ret end |
#dsPath?(p) ⇒ Boolean
1830 1831 1832 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1830 def dsPath?(p) MiqVimInventory.dsPath?(p) end |
#dsRelativePath(p) ⇒ Object
1874 1875 1876 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1874 def dsRelativePath(p) MiqVimInventory.dsRelativePath(p) end |
#dupObj(obj) ⇒ Object
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.
2635 2636 2637 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2635 def dupObj(obj) obj end |
#dvPortgroupByMor(dvpMor, selSpec = nil) ⇒ Object
Return a single storagePod object, given its MOR
1583 1584 1585 1586 1587 1588 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1583 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 |
#dvPortgroups(selSpec = nil) ⇒ Object
Public accessor
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1551 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 |
#dvPortgroupsByMor(selSpec = nil) ⇒ Object
Public accessor
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1567 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 |
#dvSwitchByMor(dvsMor, selSpec = nil) ⇒ Object
Return a single DV Switch object, given its MOR
1677 1678 1679 1680 1681 1682 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1677 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 |
#dvSwitches(selSpec = nil) ⇒ Object
Public accessor
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1645 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 |
#dvSwitchesByMor(selSpec = nil) ⇒ Object
Public accessor
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1661 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 |
#folderByMor(fMor, selSpec = nil) ⇒ Object
Return a single folder object, given its MOR
1133 1134 1135 1136 1137 1138 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1133 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 |
#folders(selSpec = nil) ⇒ Object
Public accessor
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1101 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 |
#foldersByFilter(filter) ⇒ Object
Public accessor
Return an array of folder objects that match the given property filter.
1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1145 def foldersByFilter(filter) f = nil @cacheLock.synchronize(:SH) do f = applyFilter(foldersByMor_locked.values, filter) f = dupObj(f) end assert_no_locks f end |
#foldersByMor(selSpec = nil) ⇒ Object
Public accessor
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1117 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 |
#getMoProp(mo, path = nil) ⇒ Object
Public accessor
2168 2169 2170 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2168 def getMoProp(mo, path = nil) getMoProp_local(mo, path) end |
#getMoProp_local(mo, path = nil) ⇒ Object
Retrieve the properties for a single object, given its managed object reference.
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2111 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 $vim_log.info "MiqVimInventory(#{@server}, #{@username}).getMoProp_local: calling retrieveProperties(#{mo.vimType})" if $vim_log oca = retrievePropertiesCompat(@propCol, pfSpec) $vim_log.info "MiqVimInventory(#{@server}, #{@username}).getMoProp_local: return from retrieveProperties(#{mo.vimType})" if $vim_log 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 |
#getMoPropMulti(moa, path = nil) ⇒ Object
Retrieve the properties for multiple objects of the same type, given an array of managed object references.
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2176 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 |
#getMoPropMultiIter(moa, path = nil) ⇒ Object
def getMoPropMulti
2239 2240 2241 2242 2243 2244 2245 2246 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2239 def getMoPropMultiIter(moa, path = nil) oca = [] moa.each do |mo| oc = getMoProp_local(mo, path) oca << oc if oc end oca end |
#getSelector(selName) ⇒ Object
2315 2316 2317 2318 2319 2320 2321 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2315 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 |
#getSelSpec(selSpec) ⇒ Object
2346 2347 2348 2349 2350 2351 2352 2353 2354 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2346 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 |
#getTaskMor(tmor) ⇒ Object
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1989 def getTaskMor(tmor) if tmor.respond_to?(:vimType) $vim_log.debug "getTaskMor: returning #{tmor}, no search" return tmor else $vim_log.debug "getTaskMor: searching for task #{tmor}" getTasks.each do |tmo| if tmo.to_str == tmor $vim_log.debug "getTaskMor: returning #{tmo} (#{tmo.vimType})" return tmo end end raise "getTaskMor: task #{tmor} not found." end end |
#getTasks ⇒ Object
Task utility methods.
1979 1980 1981 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1979 def getTasks getMoProp_local(@sic.taskManager, "recentTask")['recentTask'] end |
#getTasksByFilter(filter) ⇒ Object
private :getTasks
1984 1985 1986 1987 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1984 def getTasksByFilter(filter) ta = applyFilter(getMoPropMulti(getTasks, 'info'), filter) dupObj(ta) end |
#hasProp?(baseHash, prop) ⇒ Boolean
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2483 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 |
#hostSystemByMor(hsMor, selSpec = nil) ⇒ Object
Return a single hostSystem object, given its MOR
1339 1340 1341 1342 1343 1344 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1339 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 |
#hostSystems(selSpec = nil) ⇒ Object
Public accessor
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1307 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 |
#hostSystemsByFilter(filter) ⇒ Object
Public accessor
Return an array of host system objects that match the given property filter.
1351 1352 1353 1354 1355 1356 1357 1358 1359 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1351 def hostSystemsByFilter(filter) hs = nil @cacheLock.synchronize(:SH) do hs = applyFilter(hostSystemsByMor_locked.values, filter) hs = dupObj(hs) end assert_no_locks hs end |
#hostSystemsByMor(selSpec = nil) ⇒ Object
Public accessor
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1323 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 |
#hostSystemsStorageDevice(hostMors, selSpec = nil) ⇒ Object
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1361 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 |
#inventoryHash ⇒ Object
1804 1805 1806 1807 1808 1809 1810 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1804 def inventoryHash ih = nil @cacheLock.synchronize(:SH) do ih = dupObj(inventoryHash_locked) end ih end |
#inventoryHash_locked ⇒ Object
A hash of managed object references for all the objects we care about.
For internal use. Locking handled by caller
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1780 def inventoryHash_locked raise "inventoryHash_locked: cache lock not held" unless @cacheLock.sync_locked? return(@inventoryHash) if @inventoryHash $vim_log.info "MiqVimInventory.inventoryHash_locked: loading inventoryHash for #{@connId}" begin @cacheLock.sync_lock(:EX) if (unlock = @cacheLock.sync_shared?) $vim_log.info "MiqVimInventory(#{@server}, #{@username}).inventoryHash_locked: calling retrieveProperties" if $vim_log @inventoryHash = {} retrievePropertiesIter(@propCol, @spec) do |oc| (@inventoryHash[oc.obj.vimType] ||= []) << oc.obj end $vim_log.info "MiqVimInventory(#{@server}, #{@username}).inventoryHash_locked: returned from retrieveProperties" if $vim_log ensure @cacheLock.sync_unlock if unlock end $vim_log.info "MiqVimInventory.inventoryHash_locked: loaded inventoryHash for #{@connId}" @inventoryHash end |
#isAlive? ⇒ Boolean
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 267 def isAlive? return false unless @alive begin unless currentSession $vim_log.info "MiqVimInventory.isAlive?: Current session no longer exists." @alive = false end rescue Exception => err $vim_log.info "MiqVimInventory.isAlive?: Could not access connection - #{err}" @alive = false end @alive end |
#isDead ⇒ Object
For testing
284 285 286 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 284 def isDead @alive = false end |
#isHostAgent? ⇒ Boolean
292 293 294 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 292 def isHostAgent? !@isVirtualCenter end |
#isVirtualCenter? ⇒ Boolean
288 289 290 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 288 def isVirtualCenter? @isVirtualCenter end |
#keyExistsInCache?(hashName, key) ⇒ Boolean
499 500 501 502 503 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 499 def keyExistsInCache?(hashName, key) @cacheLock.synchronize(:SH) do return send((hashName + "_locked").to_sym).key?(key) end end |
#keyFromCache(hashName, props, value = nil) ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 481 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 |
#loadCache ⇒ Object
242 243 244 245 246 247 248 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 242 def loadCache @cacheLock.synchronize(:EX) do @propMap.each_value do |pm| send("#{pm[:baseName][1..-1]}_locked".to_sym) end end end |
#localVmPath(p) ⇒ Object
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1878 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 |
#logCacheCounts(pref) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 123 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 $vim_log.info "#{pref}#{hnm}: #{hnmc}" end unless instance_variable_get(hn).nil? hnc = instance_variable_get(hn).keys.length $vim_log.info "#{pref}#{hn}: #{hnc}" end end end end |
#logUserEvent(entity, msg) ⇒ Object
Generate a user event associated with the given managed object.
1815 1816 1817 1818 1819 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1815 def logUserEvent(entity, msg) $vim_log.info "MiqVimInventory(#{@server}, #{@username}).logUserEvent: calling logUserEvent" if $vim_log super(@sic.eventManager, entity, msg) $vim_log.info "MiqVimInventory(#{@server}, #{@username}).logUserEvent: returned from logUserEvent" if $vim_log end |
#objFixUp(objType, objHash) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 342 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 |
#path2dsName(p) ⇒ Object
1839 1840 1841 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1839 def path2dsName(p) MiqVimInventory.path2dsName(p) end |
#pollTask(tmor, className = nil) ⇒ Object
def waitForTask
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2052 def pollTask(tmor, className = nil) className ||= self.class.to_s $vim_log.info "#{className}(#{@server}, #{@username})::pollTask(#{tmor})" if $vim_log 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 |
#propFromCache(hashName, key, props) ⇒ Object
451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 451 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 |
#propValue(baseHash, prop) ⇒ Object
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2464 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 |
#queryLogDescriptions(host = nil) ⇒ Object
Log and diagnostic methods.
1932 1933 1934 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1932 def queryLogDescriptions(host = nil) queryDescriptions(@sic.diagnosticManager, host) end |
#refreshVirtualMachine(vmMor) ⇒ Object
614 615 616 617 618 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 614 def refreshVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do return(conditionalCopy(addObjByMor(vmMor))) end end |
#removeObjByMor(objMor) ⇒ Object
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 430 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 |
#removeSelector(selName) ⇒ Object
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2323 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 |
#removeVirtualMachine(vmMor) ⇒ Object
625 626 627 628 629 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 625 def removeVirtualMachine(vmMor) @cacheLock.synchronize(:EX) do removeObjByMor(vmMor) end end |
#resetCache ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 250 def resetCache $vim_log.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 $vim_log.info "MiqVimInventory.resetCache: cleared cache for #{@connId}" end |
#resourcePoolByMor(rpMor, selSpec = nil) ⇒ Object
Return a single resourcePool object, given its MOR
918 919 920 921 922 923 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 918 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 |
#resourcePools(selSpec = nil) ⇒ Object
Public accessor
886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 886 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 |
#resourcePoolsByFilter(filter) ⇒ Object
Public accessor
Return an array of resource pool objects that match the given property filter.
930 931 932 933 934 935 936 937 938 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 930 def resourcePoolsByFilter(filter) rps = nil @cacheLock.synchronize(:SH) do rps = applyFilter(resourcePoolsByMor_locked.values, filter) rps = dupObj(rps) end assert_no_locks rps end |
#resourcePoolsByMor(selSpec = nil) ⇒ Object
Public accessor
902 903 904 905 906 907 908 909 910 911 912 913 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 902 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 |
#selSpecToPropPath(selSpec) ⇒ Object
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2356 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 |
#setSelector(selSpec) ⇒ Object
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2290 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 |
#snapshotFixup(ssObj, ssMorHash) ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 383 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. # ssMorHash[ssObj['createTime']] = 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 |
#spec ⇒ Object
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.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 194 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 end VimArray.new("ArrayOfPropertyFilterSpec") do |pfsa| pfsa << VimHash.new("PropertyFilterSpec") do |pfs| pfs.propSet = propSpecAry pfs.objectSet = @objectSet end end end |
#storagePodByMor(spMor, selSpec = nil) ⇒ Object
Return a single storagePod object, given its MOR
1764 1765 1766 1767 1768 1769 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1764 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 |
#storagePods(selSpec = nil) ⇒ Object
Public accessor
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1732 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 |
#storagePodsByMor(selSpec = nil) ⇒ Object
Public accessor
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1748 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 |
#updateSpec ⇒ Object
228 229 230 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 228 def updateSpec updateSpecByPropMap(@propMap) end |
#updateSpecByPropMap(propMap) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 213 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 |
#virtualAppByMor(vaMor, selSpec = nil) ⇒ Object
Return a single virtualApp object, given its MOR
1030 1031 1032 1033 1034 1035 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1030 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 |
#virtualApps(selSpec = nil) ⇒ Object
Public accessor
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 998 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 |
#virtualAppsByFilter(filter) ⇒ Object
Public accessor
Return an array of virtualApp objects that match the given property filter.
1042 1043 1044 1045 1046 1047 1048 1049 1050 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1042 def virtualAppsByFilter(filter) rps = nil @cacheLock.synchronize(:SH) do rps = applyFilter(virtualAppsByMor_locked.values, filter) rps = dupObj(rps) end assert_no_locks rps end |
#virtualAppsByMor(selSpec = nil) ⇒ Object
Public accessor
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1014 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 |
#virtualMachineByMor(vmMor, selSpec = nil) ⇒ Object
Return a single VM object, given its MOR
586 587 588 589 590 591 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 586 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 |
#virtualMachines(selSpec = nil) ⇒ Object
Public accessor
554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 554 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 |
#virtualMachinesByFilter(filter) ⇒ Object
Public accessor
Return an array of virtual machine objects that match the given property filter.
598 599 600 601 602 603 604 605 606 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 598 def virtualMachinesByFilter(filter) vms = nil @cacheLock.synchronize(:SH) do vms = applyFilter(virtualMachinesByMor_locked.values, filter) vms = dupObj(vms) end assert_no_locks vms end |
#virtualMachinesByMor(selSpec = nil) ⇒ Object
Public accessor
570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 570 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 |
#vmDatacenterName(vmMor) ⇒ Object
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 1911 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 |
#waitForTask(tmor, className = nil) ⇒ Object
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 |
# File 'lib/VMwareWebService/MiqVimInventory.rb', line 2009 def waitForTask(tmor, className = nil) className ||= self.class.to_s $vim_log.info "#{className}(#{@server}, #{@username})::waitForTask(#{tmor})" if $vim_log 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 $vim_log.info "#{className}(#{@server}, #{@username})::waitForTask: result = #{result}" if $vim_log result end |