Sha256: 818a396943df28d3f830547571b4888c1a919efd1c80d32c601f756c7f1a9b7d

Contents?: true

Size: 1.47 KB

Versions: 15

Compression:

Stored size: 1.47 KB

Contents

# Copyright (c) 2011-2017 VMware, Inc.  All Rights Reserved.
# SPDX-License-Identifier: MIT

# @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

15 entries across 13 versions & 2 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rbvmomi-1.13.0/examples/logbundle.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rbvmomi-1.13.0/examples/logbundle.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rbvmomi-1.13.0/examples/logbundle.rb
rbvmomi-1.13.0 examples/logbundle.rb
rbvmomi-1.12.0 examples/logbundle.rb
rbvmomi-1.11.7 examples/logbundle.rb
rbvmomi-1.11.6 examples/logbundle.rb
rbvmomi-1.11.5 examples/logbundle.rb
rbvmomi-1.11.4 examples/logbundle.rb
rbvmomi-1.11.3 examples/logbundle.rb
rbvmomi-1.11.2 examples/logbundle.rb
rbvmomi-1.11.1 examples/logbundle.rb
rbvmomi-1.11.0 examples/logbundle.rb
rbvmomi-1.10.0 examples/logbundle.rb
rbvmomi-1.9.5 examples/logbundle.rb