class Architect::Report
Public Class Methods
new()
click to toggle source
# File lib/architect/report.rb, line 9 def initialize @fvm = ForemanVM.new end
Public Instance Methods
capacity()
click to toggle source
Show the current capacity of the hypervisor cluster
# File lib/architect/report.rb, line 14 def capacity summary = { :host => {}, :cluster => { :cpu_count => 0, :vcpu_count => 0, :allocated_memory => 0, :total_memory => 0, } } @fvm.cluster.members2.each do |host| total_memory = host.memory cpu_count = host.cpus allocated_memory = 0 vcpu_count = 0 host.domains2.each do |domain| vcpu_count += domain.vcpu_count allocated_memory += domain.memory end summary[:host][shortname(host.hostname)] = { :allocated_memory => allocated_memory, :total_memory => total_memory, :vcpu_count => vcpu_count, :cpu_count => cpu_count, } end # Compute the cluster-wide totals summary[:host].values.each do |host| summary[:cluster].keys.each do |item| summary[:cluster][item] += host[item] end end #pp summary[:cluster] ; raise 'DEBUG' cluster = summary[:cluster] used_mem_pct = 100 * (cluster[:allocated_memory].to_f / cluster[:total_memory].to_f) free_mem = cluster[:total_memory] - cluster[:allocated_memory] printf "Memory: %d%% allocated, %s free, %s total\n", used_mem_pct, gigabytes(free_mem), gigabytes(cluster[:total_memory]) used_cpu_pct = 100 * (cluster[:vcpu_count].to_f / cluster[:cpu_count].to_f) printf "CPU: %d%% allocated, %d vCPUs running on %d CPUs\n", used_cpu_pct, cluster[:vcpu_count], cluster[:cpu_count] end