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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'bin/esx', line 24
def execute
begin
host = ESX::Host.connect(address, user, password, true, {:free_license=>free_license?})
puts
name = host.name.upcase
puts "*" * name.size
puts name
puts "*" * name.size
puts "Memory Size: %s GB" % host.memory_size.bytes.to.gigabytes.to_f.round
puts "Memory Usage: %s GB" % host.memory_usage.bytes.to.gigabytes.to_f.round
puts "Cpu Cores: %s" % host.cpu_cores
puts "Power State: %s" % host.power_state
puts "Hosted VMs: %s" % host.virtual_machines.size
puts "Running VMs: %s" % (host.virtual_machines.find_all{ |vm| vm.power_state == 'poweredOn' }).size
if not host.virtual_machines.empty?
puts "\nVirtual Machines:"
user_table = table do |t|
t.headings = "NAME","MEMORY","CPUS","NICS","DISKS", "STATE"
host.virtual_machines.each do |vm|
t << [vm.name,vm.memory_size.bytes.to.megabytes.to_i, vm.cpus, vm.ethernet_cards_number, vm.virtual_disks_number, vm.power_state]
end
end
puts user_table
end
puts "\nDatastores:"
user_table = table do |t|
t.headings = "NAME","CAPACITY","FREESPACE","ACCESIBLE","TYPE","URL"
host.datastores.each do |ds|
dsname = ds.name
if dsname.size > 20
dsname = dsname[0..19] + '...'
end
t << [dsname,ds.capacity, ds.free_space, ds.datastore_type, ds.accessible, ds.url]
end
end
puts user_table
puts
rescue Exception => e
puts "Error connecting to the ESX host"
puts "\n#{e.message}"
if debug?
puts e.backtrace
end
end
end
|