0001-Free-mem-calculated-not-provided-by-libvirt.patch
im/remotes/vmware.rb | ||
---|---|---|
1 | 1 |
#!/usr/bin/env ruby |
2 | 2 | |
3 |
require 'OpenNebula' |
|
4 |
include OpenNebula |
|
5 | ||
3 | 6 |
# -------------------------------------------------------------------------- |
4 | 7 |
# Copyright 2010, C12G Labs S.L. |
5 | 8 |
# |
... | ... | |
21 | 24 |
# <http://www.gnu.org/licenses/> |
22 | 25 |
# -------------------------------------------------------------------------- |
23 | 26 | |
27 |
begin |
|
28 |
client = Client.new() |
|
29 |
rescue Exception => e |
|
30 |
puts "Error: #{e}" |
|
31 |
exit(-1) |
|
32 |
end |
|
33 | ||
24 | 34 |
def add_info(name, value) |
25 | 35 |
value = "0" if value.nil? or value.to_s.empty? |
26 | 36 |
@result_str << "#{name}=#{value} " |
... | ... | |
52 | 62 |
end |
53 | 63 |
} |
54 | 64 | |
65 |
# Loop through all vms |
|
66 |
used_memory = 0 |
|
67 | ||
68 |
vms = VirtualMachinePool.new(client) |
|
69 |
if !OpenNebula.is_error?(vms) |
|
70 | ||
71 |
vms.info |
|
72 |
vm_ids_array = |
|
73 |
vms.retrieve_elements("/VM_POOL/VM/HISTORY[HOSTNAME=\"#{@host}\"]/../ID") |
|
74 |
if vm_ids_array |
|
75 |
vm_ids_array.each do |vm_id| |
|
76 |
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client) |
|
77 | ||
78 |
vm.info |
|
79 | ||
80 |
used_memory = used_memory + (vm['TEMPLATE/MEMORY'].to_i * 1024) |
|
81 |
end |
|
82 |
end |
|
83 |
end |
|
84 |
# 80% of the total free calculated memory to take hypervisor into account |
|
85 |
free_memory = ($total_memory.to_i - used_memory ) * 0.8 |
|
86 | ||
55 | 87 |
add_info("HYPERVISOR","vmware") |
56 | 88 |
add_info("TOTALCPU",$total_cpu) |
57 | 89 |
add_info("CPUSPEED",$cpu_speed) |
58 | 90 |
add_info("TOTALMEMORY",$total_memory) |
91 |
add_info("FREEMEMORY",free_memory.to_i) |
|
59 | 92 | |
60 | 93 |
print_info |
61 |
- |