1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

M #-: minor changes in onecluster helper

(cherry picked from commit a9171690a79733a97b6e37580ccc9f900378be76)
This commit is contained in:
Alejandro Huertas 2021-05-05 18:15:25 +02:00 committed by Ruben S. Montero
parent c1c4fd12a1
commit eafea8607f
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
2 changed files with 69 additions and 69 deletions

View File

@ -309,7 +309,6 @@ AllCops:
- src/cli/one_helper/onequota_helper.rb
- src/cli/one_helper/oneuser_helper.rb
- src/cli/one_helper/onegroup_helper.rb
- src/cli/one_helper/onecluster_helper.rb
- src/cli/one_helper/onevntemplate_helper.rb
- src/cli/one_helper/onevrouter_helper.rb
- src/cli/one_helper/onevdc_helper.rb

View File

@ -16,73 +16,71 @@
require 'one_helper'
# OneCluster CLI command helper
class OneClusterHelper < OpenNebulaHelper::OneHelper
CLUSTER = {
:name => "cluster",
:short => "-c id|name",
:large => "--cluster id|name" ,
:description => "Selects the cluster",
:name => 'cluster',
:short => '-c id|name',
:large => '--cluster id|name',
:description => 'Selects the cluster',
:format => String,
:proc => lambda { |o, options|
OpenNebulaHelper.rname_to_id(o, "CLUSTER")
:proc => lambda {|o, _options|
OpenNebulaHelper.rname_to_id(o, 'CLUSTER')
}
}
def self.rname
"CLUSTER"
'CLUSTER'
end
def self.conf_file
"onecluster.yaml"
'onecluster.yaml'
end
def element_size(ehash, ename)
ids = ehash[ename]["ID"]
ids = ehash[ename]['ID']
if ids.nil?
return 0
0
elsif ids.class == String
return 1
1
else
return ids.size
ids.size
end
end
def format_pool(options)
def format_pool(_options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Cluster", :size=>5 do |d|
d["ID"]
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"]
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
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
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
column :DATASTORES, 'Number of Datastores', :size=>10 do |d|
@ext.element_size(d, 'DATASTORES') rescue 0
end
default :ID, :NAME, :HOSTS, :VNETS, :DATASTORES
end
table
end
private
def factory(id=nil)
def factory(id = nil)
if id
OpenNebula::Cluster.new_with_id(id, @client)
else
@ -91,64 +89,67 @@ class OneClusterHelper < OpenNebulaHelper::OneHelper
end
end
def factory_pool(user_flag=-2)
def factory_pool(_user_flag = -2)
OpenNebula::ClusterPool.new(@client)
end
def format_resource(cluster, options = {})
str="%-18s: %-20s"
str_h1="%-80s"
def format_resource(cluster, _options = {})
str='%-18s: %-20s'
str_h1='%-80s'
CLIHelper.print_header(str_h1 % "CLUSTER #{cluster['ID']} INFORMATION")
puts str % ["ID", cluster.id.to_s]
puts str % ["NAME", cluster.name]
puts
CLIHelper.print_header(str_h1 % "CLUSTER RESOURCES", false)
cluster.info!
total_cpu = 0
used_cpu = 0
total_ram = 0
used_ram = 0
hosts = cluster.to_hash['CLUSTER']['HOSTS']['ID']
hosts.each do |h|
h = OpenNebula::Host.new_with_id(h, @client)
h.info!
h = h.to_hash
total_cpu += h['HOST']['HOST_SHARE']['TOTAL_CPU'].to_i/100
used_cpu += h['HOST']['HOST_SHARE']['CPU_USAGE'].to_i/100
total_ram += h['HOST']['HOST_SHARE']['TOTAL_MEM'].to_i/1024/1024
used_ram += h['HOST']['HOST_SHARE']['MEM_USAGE'].to_i/1024/1024
end
puts "TOTAL CPUs: "+total_cpu.to_s
puts "OCCUPIED CPUs: "+used_cpu.to_s
puts "AVAILABLE CPUs: "+(total_cpu - used_cpu).to_s
puts
puts "TOTAL RAM: "+total_ram.to_s
puts "OCCUPIED RAM: "+used_ram.to_s
puts "AVAILABLE RAM: "+(total_ram - used_ram).to_s
puts format(str, 'ID', cluster.id.to_s)
puts format(str, 'NAME', cluster.name)
puts
CLIHelper.print_header(str_h1 % "CLUSTER TEMPLATE", false)
CLIHelper.print_header(str_h1 % 'CLUSTER RESOURCES', false)
cluster.info!
total_cpu = 0
used_cpu = 0
total_ram = 0
used_ram = 0
cluster.to_hash['CLUSTER']['HOSTS']['ID'].each do |h|
h = OpenNebula::Host.new_with_id(h, @client)
h.info!
h = h.to_hash
total_cpu += h['HOST']['HOST_SHARE']['TOTAL_CPU'].to_i / 100
used_cpu += h['HOST']['HOST_SHARE']['CPU_USAGE'].to_i / 100
total_ram += h['HOST']['HOST_SHARE']['TOTAL_MEM'].to_i / 1024 / 1024
used_ram += h['HOST']['HOST_SHARE']['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}"
puts
CLIHelper.print_header(str_h1 % 'CLUSTER TEMPLATE', false)
puts cluster.template_str
puts
CLIHelper.print_header("%-15s" % ["HOSTS"])
puts
CLIHelper.print_header(format('%-15s', 'HOSTS'))
cluster.host_ids.each do |id|
puts "%-15s" % [id]
puts format('%-15s', id)
end
puts
CLIHelper.print_header("%-15s" % ["VNETS"])
CLIHelper.print_header(format('%-15s', 'VNETS'))
cluster.vnet_ids.each do |id|
puts "%-15s" % [id]
puts format('%-15s', id)
end
puts
CLIHelper.print_header("%-15s" % ["DATASTORES"])
CLIHelper.print_header(format('%-15s', 'DATASTORES'))
cluster.datastore_ids.each do |id|
puts "%-15s" % [id]
puts format('%-15s', id)
end
end
end