Class: PowerOffVMCommand

Inherits:
BaseCommand show all
Defined in:
bin/esx

Instance Method Summary collapse

Instance Method Details

#executeObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'bin/esx', line 108

def execute
  begin
    host = ESX::Host.connect address, user, password, true, {:free_license=>free_license?}
    host.virtual_machines.each do |vm|
      if vm.name == vm_name and vm.power_state == 'poweredOn'
        print "Powering Off VM #{vm_name}... "
        vm.power_off
        puts "Done."
      end
    end
  rescue Exception => e
    $stderr.puts "Can't connect to the host #{address}."
    if debug?
      $stderr.puts e.message
    end
    exit 1
  end
end