class Chef::Knife::VsphereVmExecute
VsphereVMexecute extends the Basevspherecommand
Public Instance Methods
run()
click to toggle source
The main run method for vm_execute
# File lib/chef/knife/vsphere_vm_execute.rb, line 35 def run $stdout.sync = true vmname = @name_args.shift if vmname.nil? show_usage fatal_exit("You must specify a virtual machine name") end command = @name_args.shift if command.nil? show_usage fatal_exit("You must specify a command to execute") end args = @name_args args = [] if args.nil? vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}") gom = vim_connection.serviceContent.guestOperationsManager guest_auth = RbVmomi::VIM::NamePasswordAuthentication(interactiveSession: false, username: config[:exec_user], password: config[:exec_passwd]) prog_spec = RbVmomi::VIM::GuestProgramSpec(programPath: command, arguments: args.join(" "), workingDirectory: get_config(:exec_dir)) gom.processManager.StartProgramInGuest(vm: vm, auth: guest_auth, spec: prog_spec) end