Class: MiqVim

Inherits:
MiqVimInventory show all
Includes:
MiqVimUpdate, MiqVimVdlConnectionMod
Defined in:
lib/VMwareWebService/MiqVim.rb

Constant Summary collapse

@@monitor_updates =
false
@@pre_load =
false

Constants included from VimPropMaps

VimPropMaps::CorePropMap, VimPropMaps::EmsRefreshPropMap, VimPropMaps::EventMonitorPropMap, VimPropMaps::FullPropMap, VimPropMaps::PropMapVCenter, VimPropMaps::UpdatePropMapsByType, VimPropMaps::VimCoreUpdaterPropMap

Instance Attribute Summary collapse

Attributes inherited from MiqVimInventory

#cacheLock, #configLock

Attributes inherited from MiqVimClientBase

#connId, #password, #port, #server, #username

Attributes inherited from VimService

#about, #apiVersion, #isVirtualCenter, #serviceInstanceMor, #session_cookie, #sic, #v2, #v20, #v4, #v5, #v6

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MiqVimUpdate

#addObject, #debugUpdates=, #deleteObject, #forceFail, #monitorUpdates, #monitorUpdatesInitial, #monitorUpdatesSince, #notifyMethod=, #propUpdate, #stopUpdateMonitor, #updateDelay, #updateDelay=, #updateObject, #updateProps

Methods included from MiqVimVdlConnectionMod

#closeVdlConnection, #vdlConnection

Methods inherited from MiqVimInventory

#addDVPObj, #addDVSObj, #addDataStore, #addDataStoreObj, #addExtensionManager, #addHostSystem, #addHostSystemObj, #addLicenseManager, #addObjByMor, #addObjHash, #addProperty, #addStoragePodObj, #addToCollection, #addVirtualMachine, #allPropsFromCache, #applyFilter, #applySelSpec, #applySelector, #assert_no_locks, #browseDiagnosticLog, #browseDiagnosticLogEx, cacheScope, cacheScope=, #cacheStats, #cancelTask, #clusterComputeResourceByMor, #clusterComputeResources, #clusterComputeResourcesByFilter, #clusterComputeResourcesByMor, #computeResourceByMor, #computeResources, #computeResourcesByFilter, #computeResourcesByMor, #conditionalCopy, #currentSession, #dataStoreByMor, #dataStores, #dataStoresByFilter, #dataStoresByFilter_local, #dataStoresByMor, #datacenterByMor, #datacenters, #datacentersByFilter, #datacentersByMor, #datastorePath, #deepClone, #deleteProperty, #dsName2mo, #dsName2mo_local, #dsName2path, #dsPath?, dsPath?, dsRelativePath, #dsRelativePath, #dupObj, #dvPortgroupByMor, #dvPortgroups, #dvPortgroupsByMor, #dvSwitchByMor, #dvSwitches, #dvSwitchesByMor, #extensionManagerByMor, #extensionManagersByFilter, #extensionManagersByMor, #folderByMor, #folders, #foldersByFilter, #foldersByMor, #getMoProp, #getMoPropMulti, #getMoPropMultiIter, #getMoProp_local, #getSelSpec, #getSelector, #getTaskMor, #getTasks, #getTasksByFilter, #hasProp?, #hostSystemByMor, #hostSystems, #hostSystemsByFilter, #hostSystemsByMor, #hostSystemsStorageDevice, #inventoryHash, #inventoryHash_locked, #isAlive?, #isDead, #isHostAgent?, #isVirtualCenter?, #keyExistsInCache?, #keyFromCache, #licenseManagerByMor, #licenseManagersByFilter, #licenseManagersByMor, #loadCache, #localVmPath, #logCacheCounts, #logUserEvent, #objFixUp, path2dsName, #path2dsName, #pollTask, #propFromCache, #propValue, #queryLogDescriptions, #refreshExtensionManager, #refreshLicenseManager, #refreshVirtualMachine, #removeExtensionManager, #removeLicenseManager, #removeObjByMor, #removeSelector, removeSelector, #removeVirtualMachine, #resetCache, #resourcePoolByMor, #resourcePools, #resourcePoolsByFilter, #resourcePoolsByMor, #selSpecToPropPath, setSelector, #setSelector, #snapshotFixup, #spec, #storagePodByMor, #storagePods, #storagePodsByMor, #updateSpec, #updateSpecByPropMap, #virtualAppByMor, #virtualApps, #virtualAppsByFilter, #virtualAppsByMor, #virtualMachineByMor, #virtualMachines, #virtualMachinesByFilter, #virtualMachinesByMor, #vmDatacenterName, #waitForTask

Methods included from MiqVimObjectSet

#objectSet

Methods included from MiqVimDump

#dumpAll, #dumpArray, #dumpClass, #dumpHash, #dumpHostInfo, #dumpMors, #dumpObj, #dumpToLog=, #globalIndent=, #indentedPrint

Methods included from VimPropMaps

#dupProps

Methods inherited from MiqVimClientBase

#acquireCloneTicket, #connect, #currentServerTime, #receiveTimeout, receiveTimeout, #receiveTimeout=, receiveTimeout=, #sdk_uri, #verify_callback

Methods inherited from VimService

#acquireCloneTicket, #acquireMksTicket, #acquireTicket, #addHost_Task, #addInternetScsiSendTargets, #addInternetScsiStaticTargets, #addStandaloneHost_Task, #browseDiagnosticLog, #cancelTask, #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, #logUserEvent, #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

Methods included from VMwareWebService::Logging

#logger

Constructor Details

#initialize(server:, username:, password:, port: 443, ssl_options: {}, cache_scope: nil, monitor_updates: nil, pre_load: nil, debug_updates: false, notify_method: nil, max_wait: 60, max_objects: 250) ⇒ MiqVim

Returns a new instance of MiqVim.

Parameters:

  • server (String)

    DNS name or IP address of the vCenter Server

  • username (String)

    Username to connect to the vCenter Server

  • password (String)

    Password to connect to the vCenter Server

  • port (Integer) (defaults to: 443)

    Port to connect to the vCenter Server (default: 443)

  • ssl_options (Hash) (defaults to: {})

    SSL connection options, :verify_mode and :ca_file

  • cache_scope (Symbol) (defaults to: nil)

    A pre-defined set of properties to cache (default: nil)

  • monitor_updates (Bool) (defaults to: nil)

    Should a thread be started to monitor updates (default: false)

  • pre_load (Bool) (defaults to: nil)

    Should the cache be built before returning the connection (default: false)

  • debug_updates (Bool) (defaults to: false)

    Should we print debug info for each update (default: false)

  • notify_method (Method) (defaults to: nil)

    A optional method to call for each update (default: nil)

  • max_wait (Integer) (defaults to: 60)

    How many seconds to wait before breaking out of WaitForUpdates (default: 60)

  • max_objects (Integer) (defaults to: 250)

    How many objects to return from each WaitForUpdates page (default: 250)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/VMwareWebService/MiqVim.rb', line 35

def initialize(server:, username:, password:, port: 443, ssl_options: {}, cache_scope: nil, monitor_updates: nil, pre_load: nil, debug_updates: false, notify_method: nil, max_wait: 60, max_objects: 250)
  super(:server => server, :port => port, :ssl_options => ssl_options, :username => username, :password => password, :cache_scope => cache_scope)

  monitor_updates = self.class.monitor_updates if monitor_updates.nil?
  pre_load        = self.class.pre_load        if pre_load.nil?

  @monitor_updates    = monitor_updates
  @updateMonitorReady = false
  @error              = nil
  @notifyMethod       = notify_method
  @debugUpdates       = debug_updates
  @maxWait            = max_wait
  @maxObjects         = max_objects

  start_monitor_updates_thread(pre_load) if @monitor_updates
end

Instance Attribute Details

#monitor_updatesObject (readonly)

Returns the value of attribute monitor_updates.



21
22
23
# File 'lib/VMwareWebService/MiqVim.rb', line 21

def monitor_updates
  @monitor_updates
end

#updateThreadObject (readonly)

Returns the value of attribute updateThread.



21
22
23
# File 'lib/VMwareWebService/MiqVim.rb', line 21

def updateThread
  @updateThread
end

Class Method Details

.monitor_updatesObject



55
56
57
# File 'lib/VMwareWebService/MiqVim.rb', line 55

def self.monitor_updates
  @@monitor_updates
end

.monitor_updates=(val) ⇒ Object



59
60
61
# File 'lib/VMwareWebService/MiqVim.rb', line 59

def self.monitor_updates=(val)
  @@monitor_updates = val
end

.pre_loadObject



63
64
65
# File 'lib/VMwareWebService/MiqVim.rb', line 63

def self.pre_load
  @@pre_load
end

.pre_load=(val) ⇒ Object



67
68
69
# File 'lib/VMwareWebService/MiqVim.rb', line 67

def self.pre_load=(val)
  @@pre_load = val
end

Instance Method Details

#disconnectObject



273
274
275
276
277
# File 'lib/VMwareWebService/MiqVim.rb', line 273

def disconnect
  shutdown_monitor_updates_thread if @monitor_updates

  super
end

#getMiqCustomFieldsManagerObject



255
256
257
258
259
# File 'lib/VMwareWebService/MiqVim.rb', line 255

def getMiqCustomFieldsManager
  miqVimCfm = MiqCustomFieldsManager.new(self)
  logger.info "MiqVimMod.getMiqCustomFieldsManager: returning object #{miqVimCfm.object_id}"
  (miqVimCfm)
end

#getVimAlarmManagerObject



261
262
263
264
265
# File 'lib/VMwareWebService/MiqVim.rb', line 261

def getVimAlarmManager
  miqVimAm = MiqVimAlarmManager.new(self)
  logger.info "MiqVimMod.getVimAlarmManager: returning object #{miqVimAm.object_id}"
  (miqVimAm)
end

#getVimCluster(name) ⇒ Object

Cluster



184
185
186
187
188
189
190
191
192
193
# File 'lib/VMwareWebService/MiqVim.rb', line 184

def getVimCluster(name)
  logger.info "MiqVimMod.getVimCluster: called"
  miqVimCluster = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Cluster: #{name}" unless (ch = clusterComputeResources_locked[name])
    miqVimCluster = MiqVimCluster.new(self, conditionalCopy(ch))
  end
  logger.info "MiqVimMod.getVimCluster: returning object #{miqVimCluster.object_id}"
  (miqVimCluster)
end

#getVimClusterByFilter(filter) ⇒ Object

def getVimClusterByMor



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/VMwareWebService/MiqVim.rb', line 206

def getVimClusterByFilter(filter)
  logger.info "MiqVimMod.getVimClusterByFilter: called"
  miqVimCluster = nil
  @cacheLock.synchronize(:SH) do
    clusters = applyFilter(clusterComputeResourcesByMor_locked.values, filter)
    raise MiqException::MiqVimResourceNotFound, "getVimClusterByFilter: Could not find Cluster matching filter" if clusters.empty?
    miqVimCluster = MiqVimCluster.new(self, conditionalCopy(clusters[0]))
  end
  logger.info "MiqVimMod.getVimClusterByFilter: returning object #{miqVimCluster.object_id}"
  (miqVimCluster)
end

#getVimClusterByMor(cMor) ⇒ Object

def getVimCluster



195
196
197
198
199
200
201
202
203
204
# File 'lib/VMwareWebService/MiqVim.rb', line 195

def getVimClusterByMor(cMor)
  logger.info "MiqVimMod.getVimClusterByMor: called"
  miqVimCluster = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Cluster: #{cMor}" unless (ch = clusterComputeResourcesByMor_locked[cMor])
    miqVimCluster = MiqVimCluster.new(self, conditionalCopy(ch))
  end
  logger.info "MiqVimMod.getVimClusterByMor: returning object #{miqVimCluster.object_id}"
  (miqVimCluster)
end

#getVimCustomizationSpecManagerObject



267
268
269
270
271
# File 'lib/VMwareWebService/MiqVim.rb', line 267

def getVimCustomizationSpecManager
  miqVimCsm = MiqVimCustomizationSpecManager.new(self)
  logger.info "MiqVimMod.getVimCustomizationSpecManager: returning object #{miqVimCsm.object_id}"
  (miqVimCsm)
end

#getVimDataStore(dsName) ⇒ Object

DataStore



221
222
223
224
225
226
227
228
229
230
# File 'lib/VMwareWebService/MiqVim.rb', line 221

def getVimDataStore(dsName)
  logger.info "MiqVimMod.getVimDataStore: called"
  miqVimDs = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find datastore: #{dsName}" unless (dsh = dataStores_locked[dsName])
    miqVimDs = MiqVimDataStore.new(self, conditionalCopy(dsh))
  end
  logger.info "MiqVimMod.getVimDataStore: returning object #{miqVimDs.object_id}"
  (miqVimDs)
end

#getVimDataStoreByMor(dsMor) ⇒ Object



232
233
234
235
236
237
238
239
240
241
# File 'lib/VMwareWebService/MiqVim.rb', line 232

def getVimDataStoreByMor(dsMor)
  logger.info "MiqVimMod.getVimDataStoreByMor: called"
  miqVimDs = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find datastore: #{dsMor}" unless (dsh = dataStoresByMor_locked[dsMor])
    miqVimDs = MiqVimDataStore.new(self, conditionalCopy(dsh))
  end
  logger.info "MiqVimMod.getVimDataStoreByMor: returning object #{miqVimDs.object_id}"
  (miqVimDs)
end

#getVimEventHistory(eventFilterSpec = nil, pgSize = 20) ⇒ Object



249
250
251
252
253
# File 'lib/VMwareWebService/MiqVim.rb', line 249

def getVimEventHistory(eventFilterSpec = nil, pgSize = 20)
  miqVimEh = MiqVimEventHistoryCollector.new(self, eventFilterSpec, pgSize)
  logger.info "MiqVimMod.getVimEventHistory: returning object #{miqVimEh.object_id}"
  (miqVimEh)
end

#getVimFolder(name) ⇒ Object

def getVimHostByFilter



147
148
149
150
151
152
153
154
155
156
# File 'lib/VMwareWebService/MiqVim.rb', line 147

def getVimFolder(name)
  logger.info "MiqVimMod.getVimFolder: called"
  miqVimFolder = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Folder: #{name}" unless (fh = folders_locked[name])
    miqVimFolder = MiqVimFolder.new(self, conditionalCopy(fh))
  end
  logger.info "MiqVimMod.getVimFolder: returning object #{miqVimFolder.object_id}"
  (miqVimFolder)
end

#getVimFolderByFilter(filter) ⇒ Object

def getVimFolderByMor



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/VMwareWebService/MiqVim.rb', line 169

def getVimFolderByFilter(filter)
  logger.info "MiqVimMod.getVimFolderByFilter: called"
  miqVimFolder = nil
  @cacheLock.synchronize(:SH) do
    folders = applyFilter(foldersByMor_locked.values, filter)
    raise MiqException::MiqVimResourceNotFound, "getVimFolderByFilter: Could not find folder matching filter" if folders.empty?
    miqVimFolder = MiqVimFolder.new(self, conditionalCopy(folders[0]))
  end
  logger.info "MiqVimMod.getVimFolderByFilter: returning object #{miqVimFolder.object_id}"
  (miqVimFolder)
end

#getVimFolderByMor(fMor) ⇒ Object

def getVimFolder



158
159
160
161
162
163
164
165
166
167
# File 'lib/VMwareWebService/MiqVim.rb', line 158

def getVimFolderByMor(fMor)
  logger.info "MiqVimMod.getVimFolderByMor: called"
  miqVimFolder = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Folder: #{fMor}" unless (fh = foldersByMor_locked[fMor])
    miqVimFolder = MiqVimFolder.new(self, conditionalCopy(fh))
  end
  logger.info "MiqVimMod.getVimFolderByMor: returning object #{miqVimFolder.object_id}"
  (miqVimFolder)
end

#getVimHost(name) ⇒ Object

def getVimVmByFilter



109
110
111
112
113
114
115
116
117
118
# File 'lib/VMwareWebService/MiqVim.rb', line 109

def getVimHost(name)
  logger.info "MiqVimMod.getVimHost: called"
  miqVimHost = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Host: #{name}" unless (hh = hostSystems_locked[name])
    miqVimHost = MiqVimHost.new(self, conditionalCopy(hh))
  end
  logger.info "MiqVimMod.getVimHost: returning object #{miqVimHost.object_id}"
  (miqVimHost)
end

#getVimHostByFilter(filter) ⇒ Object

Returns a MiqVimHost object for the first Host found that matches the criteria defined by the filter.



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/VMwareWebService/MiqVim.rb', line 135

def getVimHostByFilter(filter)
  logger.info "MiqVimMod.getVimHostByFilter: called"
  miqVimHost = nil
  @cacheLock.synchronize(:SH) do
    ha = applyFilter(hostSystemsByMor_locked.values, filter)
    raise MiqException::MiqVimResourceNotFound, "getVimHostByFilter: Could not find Host matching filter" if ha.empty?
    miqVimHost = MiqVimHost.new(self, conditionalCopy(ha[0]))
  end
  logger.info "MiqVimMod.getVimHostByFilter: returning object #{miqVimHost.object_id}"
  (miqVimHost)
end

#getVimHostByMor(hMor) ⇒ Object

def getVimHost



120
121
122
123
124
125
126
127
128
129
# File 'lib/VMwareWebService/MiqVim.rb', line 120

def getVimHostByMor(hMor)
  logger.info "MiqVimMod.getVimHostByMor: called"
  miqVimHost = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find Host: #{hMor}" unless (hh = hostSystemsByMor_locked[hMor])
    miqVimHost = MiqVimHost.new(self, conditionalCopy(hh))
  end
  logger.info "MiqVimMod.getVimHostByMor: returning object #{miqVimHost.object_id}"
  (miqVimHost)
end

#getVimPerfHistoryObject



243
244
245
246
247
# File 'lib/VMwareWebService/MiqVim.rb', line 243

def getVimPerfHistory
  miqVimPh = MiqVimPerfHistory.new(self)
  logger.info "MiqVimMod.getVimPerfHistory: returning object #{miqVimPh.object_id}"
  (miqVimPh)
end

#getVimVm(path) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/VMwareWebService/MiqVim.rb', line 71

def getVimVm(path)
  logger.info "MiqVimMod.getVimVm: called"
  miqVimVm = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find VM: #{path}" unless (vmh = virtualMachines_locked[path])
    miqVimVm = MiqVimVm.new(self, conditionalCopy(vmh))
  end
  logger.info "MiqVimMod.getVimVm: returning object #{miqVimVm.object_id}"
  (miqVimVm)
end

#getVimVmByFilter(filter) ⇒ Object

Returns a MiqVimVm object for the first VM found that matches the criteria defined by the filter.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/VMwareWebService/MiqVim.rb', line 97

def getVimVmByFilter(filter)
  logger.info "MiqVimMod.getVimVmByFilter: called"
  miqVimVm = nil
  @cacheLock.synchronize(:SH) do
    vms = applyFilter(virtualMachinesByMor_locked.values, filter)
    raise MiqException::MiqVimResourceNotFound, "getVimVmByFilter: Could not find VM matching filter" if vms.empty?
    miqVimVm = MiqVimVm.new(self, conditionalCopy(vms[0]))
  end
  logger.info "MiqVimMod.getVimVmByFilter: returning object #{miqVimVm.object_id}"
  (miqVimVm)
end

#getVimVmByMor(vmMor) ⇒ Object

def getVimVm



82
83
84
85
86
87
88
89
90
91
# File 'lib/VMwareWebService/MiqVim.rb', line 82

def getVimVmByMor(vmMor)
  logger.info "MiqVimMod.getVimVmByMor: called"
  miqVimVm = nil
  @cacheLock.synchronize(:SH) do
    raise MiqException::MiqVimResourceNotFound, "Could not find VM: #{vmMor}" unless (vmh = virtualMachinesByMor_locked[vmMor])
    miqVimVm = MiqVimVm.new(self, conditionalCopy(vmh))
  end
  logger.info "MiqVimMod.getVimVmByMor: returning object #{miqVimVm.object_id}"
  (miqVimVm)
end