/usr/share/doc/ruby-rbvmomi/examples/power.rb is in ruby-rbvmomi 1.8.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | require 'trollop'
require 'rbvmomi'
require 'rbvmomi/trollop'
VIM = RbVmomi::VIM
CMDS = %w(on off reset suspend destroy)
opts = Trollop.options do
banner <<-EOS
Perform VM power operations.
Usage:
power.rb [options] cmd VM
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
cmd = ARGV[0] or Trollop.die("no command given")
vm_name = ARGV[1] or Trollop.die("no VM name given")
Trollop.die("must specify host") unless opts[:host]
vim = VIM.connect opts
dc = vim.serviceInstance.content.rootFolder.traverse(opts[:datacenter], VIM::Datacenter) or abort "datacenter not found"
vm = dc.vmFolder.traverse(vm_name, VIM::VirtualMachine) or abort "VM not found"
case cmd
when 'on'
vm.PowerOnVM_Task.wait_for_completion
when 'off'
vm.PowerOffVM_Task.wait_for_completion
when 'reset'
vm.ResetVM_Task.wait_for_completion
when 'suspend'
vm.SuspendVM_Task.wait_for_completion
when 'destroy'
vm.Destroy_Task.wait_for_completion
else
abort "invalid command"
end
|