class OneClusterHelper
OneCluster CLI command helper
Constants
- CLUSTER
Public Class Methods
conf_file()
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 37 def self.conf_file 'onecluster.yaml' end
rname()
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 33 def self.rname 'CLUSTER' end
Public Instance Methods
element_size(ehash, ename)
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 41 def element_size(ehash, ename) ids = ehash[ename]['ID'] if ids.nil? 0 elsif ids.class == String 1 else ids.size end end
format_pool(_options)
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 53 def format_pool(_options) config_file = self.class.table_conf CLIHelper::ShowTable.new(config_file, self) do column :ID, 'ONE identifier for the Cluster', :size=>5 do |d| d['ID'] end column :NAME, 'Name of the Cluster', :left, :size=>25 do |d| d['NAME'] end column :HOSTS, 'Number of Hosts', :size=>5 do |d| @ext.element_size(d, 'HOSTS') rescue 0 end column :VNETS, 'Number of Networks', :size=>5 do |d| @ext.element_size(d, 'VNETS') rescue 0 end column :DATASTORES, 'Number of Datastores', :size=>10 do |d| @ext.element_size(d, 'DATASTORES') rescue 0 end default :ID, :NAME, :HOSTS, :VNETS, :DATASTORES end end
Private Instance Methods
factory(id = nil)
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 83 def factory(id = nil) if id OpenNebula::Cluster.new_with_id(id, @client) else xml=OpenNebula::Cluster.build_xml OpenNebula::Cluster.new(xml, @client) end end
factory_pool(_user_flag = -2)
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 92 def factory_pool(_user_flag = -2) OpenNebula::ClusterPool.new(@client) end
format_resource(cluster, _options = {})
click to toggle source
# File lib/one_helper/onecluster_helper.rb, line 96 def format_resource(cluster, _options = {}) str='%-18s: %-20s' str_h1='%-80s' CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION") puts format(str, 'ID', cluster.id.to_s) puts format(str, 'NAME', cluster.name) puts CLIHelper.print_header(str_h1 % 'CLUSTER RESOURCES', false) cluster.info! hosts = cluster.to_hash['CLUSTER']['HOSTS']['ID'] if hosts total_cpu = 0 used_cpu = 0 total_ram = 0 used_ram = 0 [hosts].flatten.each do |h| h = OpenNebula::Host.new_with_id(h, @client) h.info! h = h.to_hash h = h['HOST']['HOST_SHARE'] total_cpu += h['TOTAL_CPU'].to_i / 100 used_cpu += h['CPU_USAGE'].to_i / 100 total_ram += h['TOTAL_MEM'].to_i / 1024 / 1024 used_ram += h['MEM_USAGE'].to_i / 1024 / 1024 end puts "TOTAL CPUs: #{total_cpu}" puts "OCCUPIED CPUs: #{used_cpu}" puts "AVAILABLE CPUs: #{total_cpu - used_cpu}" puts puts "TOTAL RAM: #{total_ram}" puts "OCCUPIED RAM: #{used_ram}" puts "AVAILABLE RAM: #{total_ram - used_ram}" end puts CLIHelper.print_header(str_h1 % 'CLUSTER TEMPLATE', false) puts cluster.template_str puts CLIHelper.print_header(format('%-15s', 'HOSTS')) cluster.host_ids.each do |id| puts format('%-15s', id) end puts CLIHelper.print_header(format('%-15s', 'VNETS')) cluster.vnet_ids.each do |id| puts format('%-15s', id) end puts CLIHelper.print_header(format('%-15s', 'DATASTORES')) cluster.datastore_ids.each do |id| puts format('%-15s', id) end end