lib/vmpooler/providers/vsphere.rb
# The connection_pool method is normally used only for testing
The connection_pool method is normally used only for testing
The connection_pool method is normally used only for testing
def migrate_vm(pool_name, vm_name)
          @connection_pool.with_metrics do |pool_object|
            begin
              connection = ensured_vsphere_connection(pool_object)
              vm_hash = get_vm_details(pool_name, vm_name, connection)
              @redis.with_metrics do |redis|
                redis.hset("vmpooler__vm__#{vm_name}", 'host', vm_hash['host_name'])
                migration_count = redis.scard('vmpooler__migration')
                migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
                if migration_enabled? @config
                  if migration_count >= migration_limit
                    logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached")
                    break
                  end
                  run_select_hosts(pool_name, @provider_hosts)
                  if vm_in_target?(pool_name, vm_hash['host_name'], vm_hash['architecture'], @provider_hosts)
                    logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}")
                  else
                    migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
                  end
                else
                  logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
                end
              end
            rescue StandardError
              logger.log('s', "[!] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
              raise
            end
          end
        end
def migrate_vm ( pool_name , vm_name ) @connection_pool . with_metrics do | pool_object | begin connection = ensured_vsphere_connection ( pool_object ) vm_hash = get_vm_details ( pool_name , vm_name , connection ) @redis . with_metrics do | redis | redis . hset ( "vmpooler__vm__#{vm_name}" , 'host' , vm_hash [ 'host_name' ] ) migration_count = redis . scard ( 'vmpooler__migration' ) migration_limit = @config [ :config ] [ 'migration_limit' ] if @config [ :config ] . key? ( 'migration_limit' ) if migration_enabled? @config if migration_count >= migration_limit logger . log ( 's' , "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached" ) break end run_select_hosts ( pool_name , @provider_hosts ) if vm_in_target? ( pool_name , vm_hash [ 'host_name' ] , vm_hash [ 'architecture' ] , @provider_hosts ) logger . log ( 's' , "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}" ) else migrate_vm_to_new_host ( pool_name , vm_name , vm_hash , connection ) end else logger . log ( 's' , "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}" ) end end rescue StandardError logger . log ( 's' , "[!] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}" ) raise end end end
The connection_pool method is normally used only for testing
The connection_pool method is normally used only for testing
pool_name
vm_name