class MiqVim

Attributes

monitor_updates[R]
updateThread[R]

Public Class Methods

monitor_updates() click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 55
def self.monitor_updates
  @@monitor_updates
end
monitor_updates=(val) click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 59
def self.monitor_updates=(val)
  @@monitor_updates = val
end
new(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) click to toggle source

@param server [String] DNS name or IP address of the vCenter Server @param username [String] Username to connect to the vCenter Server @param password [String] Password to connect to the vCenter Server @param port [Integer] Port to connect to the vCenter Server (default: 443) @param ssl_options [Hash] SSL connection options, :verify_mode and :ca_file @param cache_scope [Symbol] A pre-defined set of properties to cache (default: nil) @param monitor_updates [Bool] Should a thread be started to monitor updates (default: false) @param pre_load [Bool] Should the cache be built before returning the connection (default: false) @param debug_updates [Bool] Should we print debug info for each update (default: false) @param notify_method [Method] A optional method to call for each update (default: nil) @param max_wait [Integer] How many seconds to wait before breaking out of WaitForUpdates (default: 60) @param max_objects [Integer] How many objects to return from each WaitForUpdates page (default: 250)

Calls superclass method MiqVimInventory::new
# 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
pre_load() click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 63
def self.pre_load
  @@pre_load
end
pre_load=(val) click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 67
def self.pre_load=(val)
  @@pre_load = val
end

Public Instance Methods

disconnect() click to toggle source
Calls superclass method MiqVimClientBase#disconnect
# File lib/VMwareWebService/MiqVim.rb, line 273
def disconnect
  shutdown_monitor_updates_thread if @monitor_updates

  super
end
getMiqCustomFieldsManager() click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 255
def getMiqCustomFieldsManager
  miqVimCfm = MiqCustomFieldsManager.new(self)
  logger.info "MiqVimMod.getMiqCustomFieldsManager: returning object #{miqVimCfm.object_id}"
  (miqVimCfm)
end
getVimAlarmManager() click to toggle source
# 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) click to toggle source

Cluster

# 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) click to toggle source
# 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) click to toggle source
# 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
getVimCustomizationSpecManager() click to toggle source
# 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) click to toggle source

DataStore

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source
# 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
getVimPerfHistory() click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source
# 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

Private Instance Methods

checkForOrphanedMonitors() click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 296
def checkForOrphanedMonitors
  log_prefix = "MiqVim.checkForOrphanedMonitors (#{@connId})"
  logger.debug "#{log_prefix}: called..."
  Thread.list.each do |thr|
    next unless thr[:vim_connection_id] == connId
    logger.error "#{log_prefix}: Terminating orphaned update monitor <#{thr.object_id}>"
    thr.raise "Orphaned update monitor (#{@connId}) <#{thr.object_id}>, terminated by <#{Thread.current.object_id}>"
    thr.wakeup
  end
  logger.debug "#{log_prefix}: done."
end
monitor(preLoad) click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 308
def monitor(preLoad)
  log_prefix = "MiqVim.monitor (#{@connId})"
  begin
    monitorUpdates(preLoad)
  rescue Exception => err
    logger.info "#{log_prefix}: returned from monitorUpdates via #{err.class} exception"
    @error = err
  end
end
shutdown_monitor_updates_thread() click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 318
def shutdown_monitor_updates_thread
  log_prefix = "MiqVim.disconnect (#{@connId})"
  stopUpdateMonitor
  begin
    if @updateThread != Thread.current && @updateThread.alive?
      logger.info "#{log_prefix}: waiting for Update Monitor Thread...Starting"
      @updateThread.join
      logger.info "#{log_prefix}: waiting for Update Monitor Thread...Complete"
    end
  rescue
  end
end
start_monitor_updates_thread(preLoad) click to toggle source
# File lib/VMwareWebService/MiqVim.rb, line 281
def start_monitor_updates_thread(preLoad)
  checkForOrphanedMonitors
  log_prefix          = "MiqVim.initialize (#{@connId})"
  logger.info "#{log_prefix}: starting update monitor thread"
  @updateThread = Thread.new { monitor(preLoad) }
  @updateThread[:vim_connection_id] = connId
  logger.info "#{log_prefix}: waiting for update monitor to become ready"
  until @updateMonitorReady
    raise @error unless @error.nil?
    break unless @updateThread.alive?
    Thread.pass
  end
  logger.info "#{log_prefix}: update monitor ready"
end