Sha256: 30ec1103f635ece807a08fc38536c3c34c16146b6cdc30dc973166069cc43f9f

Contents?: true

Size: 1.38 KB

Versions: 30

Compression:

Stored size: 1.38 KB

Contents

# @todo Retrieve ESX log bundles when run against VC.
require 'trollop'
require 'rbvmomi'
require 'rbvmomi/trollop'

VIM = RbVmomi::VIM
DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'

opts = Trollop.options do
  banner <<-EOS
Generate and retrieve a log bundle.

Usage:
    logbundle.rb [options] dest

dest must be a directory.

VIM connection options:
    EOS

    rbvmomi_connection_opts

    text <<-EOS

Other options:
  EOS
end

Trollop.die("must specify host") unless opts[:host]
dest = ARGV[0] or abort("must specify destination directory")

abort "destination is not a directory" unless File.directory? dest

vim = VIM.connect opts
is_vc = vim.serviceContent.about.apiType == 'VirtualCenter'
diagMgr = vim.serviceContent.diagnosticManager

bundles =
  begin
    diagMgr.GenerateLogBundles_Task(includeDefault: true).wait_for_completion
  rescue VIM::TaskInProgress
    $!.task.wait_for_completion
  end

bundles.each do |b|
  uri = URI.parse(b.url.sub('*', DEFAULT_SERVER_PLACEHOLDER))
  dest_path = File.join(dest, File.basename(uri.path))
  puts "downloading bundle #{b.url} to #{dest_path}"
  if uri.host == DEFAULT_SERVER_PLACEHOLDER
    vim.http.request_get(uri.path) do |res|
      File.open dest_path, 'w' do |io|
        res.read_body do |data|
          io.write data
          $stdout.write '.'
          $stdout.flush
        end
      end
      puts
    end
  else
    puts 'not supported yet'
  end
end

Version data entries

30 entries across 30 versions & 4 rubygems

Version Path
rbvmomi-1.8.5 examples/logbundle.rb
rbvmomi-1.8.4 examples/logbundle.rb
rbvmomi-1.8.3 examples/logbundle.rb
rbvmomi-1.9.4 examples/logbundle.rb
rbvmomi-1.9.3 examples/logbundle.rb
rbvmomi-1.9.2 examples/logbundle.rb
rbvmomi-1.9.1 examples/logbundle.rb
rbvmomi-1.9.0 examples/logbundle.rb
rbvmomi-1.8.2 examples/logbundle.rb
rbvmomi-1.8.2.pre examples/logbundle.rb
mkuzmin-rbvmomi-1.8.2.1 examples/logbundle.rb
vagrant-rbvmomi-1.8.1 examples/logbundle.rb
rbvmomi-1.8.1 examples/logbundle.rb
rbvmomi-1.8.0 examples/logbundle.rb
gapinc-rbvmomi-1.6.1 examples/logbundle.rb
gapinc-rbvmomi-1.6.0 examples/logbundle.rb
rbvmomi-1.6.0 examples/logbundle.rb
rbvmomi-1.5.1 examples/logbundle.rb
rbvmomi-1.5.0 examples/logbundle.rb
rbvmomi-1.4.0 examples/logbundle.rb