class VcenterLibMongodb::Updater

update vms data from source to destination

Attributes

destination[R]
source[R]

Public Class Methods

new(source, destination) click to toggle source
# File lib/vcenter_lib_mongodb/updater.rb, line 11
def initialize(source, destination)
  @source = source
  @destination = destination
end

Public Instance Methods

update() click to toggle source

update by deleting missing vms and get a complete map of vms with facts and update or insert facts for each one

for example: 1633 vms in 60.70 seconds

# File lib/vcenter_lib_mongodb/updater.rb, line 20
def update
  logger.info "update started (full update)"
  tsb = Time.now
  complete = source.facts
  source_vms = complete.keys
  destination_vms = destination.all_vms
  delete_missing(destination_vms, source_vms)
  errors = false

  complete.each do |vm, facts|
    begin
      destination.vm_update(vm, facts)
    rescue
      errors = true
      logger.error $!
      pp facts
    end
  end
  tse = Time.now
  logger.info "update updated #{source_vms.size} vms in #{tse - tsb}"
  if errors
    logger.error "we don't update metadata information due to update errors"
  else
    destination.meta_fact_update("update", tsb, tse)
  end
end

Private Instance Methods

delete_missing(destination_vms, source_vms) click to toggle source
# File lib/vcenter_lib_mongodb/updater.rb, line 49
def delete_missing(destination_vms, source_vms)
  missing = destination_vms - source_vms
  missing.each do |vm|
    destination.vm_delete(vm)
  end
  logger.info "  deleted #{missing.size} vms"
end