Sha256: 28439524256455815dffcd4650dd54248a7a090d297ab31700de8541dd5dfbb6

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

require 'trollop'
require 'rbvmomi'
require 'rbvmomi/trollop'

VIM = RbVmomi::VIM
CMDS = %w(get set)

opts = Trollop.options do
  banner <<-EOS
Annotate a VM.

Usage:
    annotate.rb [options] VM get
    annotate.rb [options] VM set annotation

Commands: #{CMDS * ' '}

VIM connection options:
    EOS

    rbvmomi_connection_opts

    text <<-EOS

VM location options:
    EOS

    rbvmomi_datacenter_opt

    text <<-EOS

Other options:
  EOS

  stop_on CMDS
end

vm_name = ARGV[0] or Trollop.die("no VM name given")
cmd = ARGV[1] or Trollop.die("no command given")
abort "invalid command" unless CMDS.member? cmd
Trollop.die("must specify host") unless opts[:host]

vim = VIM.connect opts

dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
vm = dc.find_vm(vm_name) or abort "VM not found"

case cmd
when 'get'
  puts vm.config.annotation
when 'set'
  value = ARGV[2] or Trollop.die("no annotation given")
  vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:annotation => value)).wait_for_completion
end

Version data entries

22 entries across 22 versions & 4 rubygems

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