mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
parent
1e1c613fe3
commit
89f999187d
@ -359,7 +359,6 @@ AllCops:
|
||||
- src/cli/command_parser.rb
|
||||
- src/cli/cli_helper.rb
|
||||
- src/cli/one_helper.rb
|
||||
- src/cli/one_helper/onehost_helper.rb
|
||||
- src/cli/one_helper/onevmgroup_helper.rb
|
||||
- src/cli/one_helper/onemarket_helper.rb
|
||||
- src/cli/one_helper/onesecgroup_helper.rb
|
||||
|
@ -18,8 +18,10 @@ require 'one_helper'
|
||||
require 'one_helper/onevm_helper'
|
||||
require 'rubygems'
|
||||
|
||||
# implements onehost command
|
||||
class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
TEMPLATE_XPATH = '//HOST/TEMPLATE'
|
||||
|
||||
TEMPLATE_XPATH = '//HOST/TEMPLATE'
|
||||
HYBRID = {
|
||||
:ec2 => {
|
||||
:help => <<-EOT.unindent,
|
||||
@ -41,7 +43,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
# See your ec2_driver.conf for more information
|
||||
#
|
||||
#-----------------------------------------------------------------------
|
||||
EOT
|
||||
EOT
|
||||
},
|
||||
:az => {
|
||||
:help => <<-EOT.unindent,
|
||||
@ -67,110 +69,112 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
# AZ_ENDPOINT = <endpoint address>
|
||||
#
|
||||
#-----------------------------------------------------------------------
|
||||
EOT
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VERSION_XPATH = "#{TEMPLATE_XPATH}/VERSION"
|
||||
VERSION_XPATH = "#{TEMPLATE_XPATH}/VERSION"
|
||||
|
||||
def self.rname
|
||||
"HOST"
|
||||
'HOST'
|
||||
end
|
||||
|
||||
def self.conf_file
|
||||
"onehost.yaml"
|
||||
'onehost.yaml'
|
||||
end
|
||||
|
||||
def self.state_to_str(id)
|
||||
id = id.to_i
|
||||
state_str = Host::HOST_STATES[id]
|
||||
|
||||
return Host::SHORT_HOST_STATES[state_str]
|
||||
Host::SHORT_HOST_STATES[state_str]
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for Host", :size=>4 do |d|
|
||||
d["ID"]
|
||||
column :ID, 'ONE identifier for Host', :size => 4 do |d|
|
||||
d['ID']
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Host", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
column :NAME, 'Name of the Host', :left, :size => 15 do |d|
|
||||
d['NAME']
|
||||
end
|
||||
|
||||
column :CLUSTER, "Name of the Cluster", :left, :size=>9 do |d|
|
||||
OpenNebulaHelper.cluster_str(d["CLUSTER"])
|
||||
column :CLUSTER, 'Name of the Cluster', :left, :size => 9 do |d|
|
||||
OpenNebulaHelper.cluster_str(d['CLUSTER'])
|
||||
end
|
||||
|
||||
column :TVM, "Total Virtual Machines allocated to the Host", :size=>3 do |d|
|
||||
d["HOST_SHARE"]["RUNNING_VMS"] || 0
|
||||
column :TVM, 'Total Virtual Machines allocated to the Host',
|
||||
:size => 3 do |d|
|
||||
d['HOST_SHARE']['RUNNING_VMS'] || 0
|
||||
end
|
||||
|
||||
column :ZVM, "Number of Virtual Machine zombies", :size=>3 do |d|
|
||||
d["TEMPLATE"]["TOTAL_ZOMBIES"] || 0
|
||||
column :ZVM, 'Number of Virtual Machine zombies', :size => 3 do |d|
|
||||
d['TEMPLATE']['TOTAL_ZOMBIES'] || 0
|
||||
end
|
||||
|
||||
column :TCPU, "Total CPU percentage", :size=>4 do |d|
|
||||
d["HOST_SHARE"]["MAX_CPU"] || 0
|
||||
column :TCPU, 'Total CPU percentage', :size => 4 do |d|
|
||||
d['HOST_SHARE']['MAX_CPU'] || 0
|
||||
end
|
||||
|
||||
column :FCPU, "Free CPU percentage", :size=>4 do |d|
|
||||
d["HOST_SHARE"]["MAX_CPU"].to_i-
|
||||
d["HOST_SHARE"]["USED_CPU"].to_i rescue "-"
|
||||
column :FCPU, 'Free CPU percentage', :size => 4 do |d|
|
||||
d['HOST_SHARE']['MAX_CPU'].to_i -
|
||||
d['HOST_SHARE']['USED_CPU'].to_i rescue '-'
|
||||
end
|
||||
|
||||
column :ACPU, "Available cpu percentage (not reserved by VMs)",
|
||||
:size=>4 do |d|
|
||||
max_cpu=d["HOST_SHARE"]["MAX_CPU"].to_i
|
||||
max_cpu=100 if max_cpu==0
|
||||
max_cpu-d["HOST_SHARE"]["CPU_USAGE"].to_i
|
||||
column :ACPU, 'Available cpu percentage (not reserved by VMs)',
|
||||
:size => 4 do |d|
|
||||
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
||||
max_cpu = 100 if max_cpu.zero?
|
||||
max_cpu - d['HOST_SHARE']['CPU_USAGE'].to_i
|
||||
end
|
||||
|
||||
column :TMEM, "Total Memory", :size=>7 do |d|
|
||||
column :TMEM, 'Total Memory', :size => 7 do |d|
|
||||
OpenNebulaHelper.unit_to_str(
|
||||
d["HOST_SHARE"]["MAX_MEM"].to_i,
|
||||
options) rescue "-"
|
||||
d['HOST_SHARE']['MAX_MEM'].to_i,
|
||||
options
|
||||
) rescue '-'
|
||||
end
|
||||
|
||||
column :FMEM, "Free Memory", :size=>7 do |d|
|
||||
column :FMEM, 'Free Memory', :size => 7 do |d|
|
||||
OpenNebulaHelper.unit_to_str(
|
||||
d["HOST_SHARE"]["FREE_MEM"].to_i,
|
||||
options) rescue "-"
|
||||
d['HOST_SHARE']['FREE_MEM'].to_i,
|
||||
options
|
||||
) rescue '-'
|
||||
end
|
||||
|
||||
column :AMEM, "Available Memory (not reserved by VMs)",
|
||||
:size=>7 do |d|
|
||||
acpu=d["HOST_SHARE"]["MAX_MEM"].to_i-
|
||||
d["HOST_SHARE"]["MEM_USAGE"].to_i
|
||||
OpenNebulaHelper.unit_to_str(acpu,options)
|
||||
column :AMEM, 'Available Memory (not reserved by VMs)',
|
||||
:size => 7 do |d|
|
||||
acpu = d['HOST_SHARE']['MAX_MEM'].to_i -
|
||||
d['HOST_SHARE']['MEM_USAGE'].to_i
|
||||
OpenNebulaHelper.unit_to_str(acpu, options)
|
||||
end
|
||||
|
||||
column :REAL_CPU, "Real CPU", :size=>18 do |d|
|
||||
max_cpu = d["HOST_SHARE"]["MAX_CPU"].to_i
|
||||
column :REAL_CPU, 'Real CPU', :size => 18 do |d|
|
||||
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
||||
|
||||
if max_cpu != 0
|
||||
used_cpu = d["HOST_SHARE"]["USED_CPU"].to_i
|
||||
ratio = (used_cpu*100) / max_cpu
|
||||
used_cpu = d['HOST_SHARE']['USED_CPU'].to_i
|
||||
ratio = (used_cpu * 100) / max_cpu
|
||||
"#{used_cpu} / #{max_cpu} (#{ratio}%)"
|
||||
else
|
||||
'-'
|
||||
end
|
||||
end
|
||||
|
||||
column :ALLOCATED_CPU, "Allocated CPU)", :size=>18 do |d|
|
||||
max_cpu = d["HOST_SHARE"]["MAX_CPU"].to_i
|
||||
cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
|
||||
column :ALLOCATED_CPU, 'Allocated CPU)', :size => 18 do |d|
|
||||
max_cpu = d['HOST_SHARE']['MAX_CPU'].to_i
|
||||
cpu_usage = d['HOST_SHARE']['CPU_USAGE'].to_i
|
||||
|
||||
if max_cpu == 0 && cpu_usage == 0
|
||||
if max_cpu.zero? && cpu_usage.zero?
|
||||
'-'
|
||||
else
|
||||
cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
|
||||
cpu_usage = d['HOST_SHARE']['CPU_USAGE'].to_i
|
||||
|
||||
if max_cpu != 0
|
||||
ratio = (cpu_usage*100) / max_cpu
|
||||
ratio = (cpu_usage * 100) / max_cpu
|
||||
"#{cpu_usage} / #{max_cpu} (#{ratio}%)"
|
||||
else
|
||||
"#{cpu_usage} / -"
|
||||
@ -178,39 +182,42 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
end
|
||||
|
||||
column :REAL_MEM, "Real MEM", :size=>18 do |d|
|
||||
max_mem = d["HOST_SHARE"]["MAX_MEM"].to_i
|
||||
column :REAL_MEM, 'Real MEM', :size => 18 do |d|
|
||||
max_mem = d['HOST_SHARE']['MAX_MEM'].to_i
|
||||
|
||||
if max_mem != 0
|
||||
used_mem = d["HOST_SHARE"]["USED_MEM"].to_i
|
||||
ratio = (used_mem*100) / max_mem
|
||||
"#{OpenNebulaHelper.unit_to_str(used_mem,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
|
||||
used_mem = d['HOST_SHARE']['USED_MEM'].to_i
|
||||
ratio = (used_mem * 100) / max_mem
|
||||
"#{OpenNebulaHelper.unit_to_str(used_mem, options)} / "\
|
||||
"#{OpenNebulaHelper.unit_to_str(max_mem, options)} "\
|
||||
"(#{ratio}%)"
|
||||
else
|
||||
'-'
|
||||
end
|
||||
end
|
||||
|
||||
column :ALLOCATED_MEM, "Allocated MEM", :size=>18 do |d|
|
||||
max_mem = d["HOST_SHARE"]["MAX_MEM"].to_i
|
||||
mem_usage = d["HOST_SHARE"]["MEM_USAGE"].to_i
|
||||
column :ALLOCATED_MEM, 'Allocated MEM', :size => 18 do |d|
|
||||
max_mem = d['HOST_SHARE']['MAX_MEM'].to_i
|
||||
mem_usage = d['HOST_SHARE']['MEM_USAGE'].to_i
|
||||
|
||||
if max_mem == 0 && mem_usage == 0
|
||||
if max_mem.zero? && mem_usage.zero?
|
||||
'-'
|
||||
elsif max_mem != 0
|
||||
ratio = (mem_usage * 100) / max_mem
|
||||
"#{OpenNebulaHelper.unit_to_str(mem_usage, options)} / "\
|
||||
"#{OpenNebulaHelper.unit_to_str(max_mem, options)} "\
|
||||
"(#{ratio}%)"
|
||||
else
|
||||
if max_mem != 0
|
||||
ratio = (mem_usage*100) / max_mem
|
||||
"#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
|
||||
else
|
||||
"#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / -"
|
||||
end
|
||||
"#{OpenNebulaHelper.unit_to_str(mem_usage, options)} / -"
|
||||
end
|
||||
end
|
||||
|
||||
column :STAT, "Host status", :left, :size=>6 do |d|
|
||||
OneHostHelper.state_to_str(d["STATE"])
|
||||
column :STAT, 'Host status', :left, :size => 6 do |d|
|
||||
OneHostHelper.state_to_str(d['STATE'])
|
||||
end
|
||||
|
||||
default :ID, :NAME, :CLUSTER, :TVM, :ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
|
||||
default :ID, :NAME, :CLUSTER, :TVM,
|
||||
:ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
|
||||
end
|
||||
|
||||
table
|
||||
@ -218,34 +225,37 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
def set_hybrid(type, path)
|
||||
k = type.to_sym
|
||||
if HYBRID.key?(k)
|
||||
str = path.nil? ? OpenNebulaHelper.editor_input(HYBRID[k][:help]): File.read(path)
|
||||
end
|
||||
|
||||
return unless HYBRID.key?(k)
|
||||
|
||||
return OpenNebulaHelper.editor_input(HYBRID[k][:help]) if path.nil?
|
||||
|
||||
File.read(path)
|
||||
end
|
||||
|
||||
NUM_THREADS = 15
|
||||
def sync(host_ids, options)
|
||||
if `id -u`.to_i == 0 || `id -G`.split.collect{|e| e.to_i}.include?(0)
|
||||
if Process.uid.zero? || Process.gid.zero?
|
||||
STDERR.puts("Cannot run 'onehost sync' as root")
|
||||
exit -1
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
begin
|
||||
current_version = File.read(REMOTES_LOCATION+'/VERSION').strip
|
||||
rescue
|
||||
current_version = File.read(REMOTES_LOCATION + '/VERSION').strip
|
||||
rescue StandardError
|
||||
STDERR.puts("Could not read #{REMOTES_LOCATION}/VERSION")
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if current_version.empty?
|
||||
STDERR.puts "Remotes version can not be empty"
|
||||
STDERR.puts 'Remotes version can not be empty'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
begin
|
||||
current_version = Gem::Version.new(current_version)
|
||||
rescue
|
||||
STDERR.puts "VERSION file is malformed, use semantic versioning."
|
||||
rescue StandardError
|
||||
STDERR.puts 'VERSION file is malformed, use semantic versioning.'
|
||||
end
|
||||
|
||||
cluster_id = options[:cluster]
|
||||
@ -259,13 +269,13 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
# Verify the existence of REMOTES_LOCATION
|
||||
if !File.directory? REMOTES_LOCATION
|
||||
error_msg = "'#{REMOTES_LOCATION}' does not exist. " <<
|
||||
"This command must be run in the frontend."
|
||||
return -1,error_msg
|
||||
error_msg = "'#{REMOTES_LOCATION}' does not exist. " \
|
||||
'This command must be run in the frontend.'
|
||||
return -1, error_msg
|
||||
end
|
||||
|
||||
# Touch the update file
|
||||
FileUtils.touch(File.join(REMOTES_LOCATION,'.update'))
|
||||
FileUtils.touch(File.join(REMOTES_LOCATION, '.update'))
|
||||
|
||||
# Get the Host pool
|
||||
filter_flag ||= OpenNebula::Pool::INFO_ALL
|
||||
@ -276,18 +286,16 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
return -1, rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
# Assign hosts to threads
|
||||
i = 0
|
||||
queue = Array.new
|
||||
queue = []
|
||||
|
||||
pool.each do |host|
|
||||
if host_ids
|
||||
next if !host_ids.include?(host['ID'].to_i)
|
||||
next unless host_ids.include?(host['ID'].to_i)
|
||||
elsif cluster_id
|
||||
next if host['CLUSTER_ID'].to_i != cluster_id
|
||||
end
|
||||
|
||||
vm_mad = host['VM_MAD'].downcase
|
||||
remote_remotes = host['TEMPLATE/REMOTE_REMOTES']
|
||||
state = host['STATE']
|
||||
|
||||
# Skip this host from remote syncing if it's a PUBLIC_CLOUD host
|
||||
@ -297,20 +305,22 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
next if Host::HOST_STATES[state.to_i] == 'OFFLINE'
|
||||
|
||||
# Skip this host if it is a vCenter cluster
|
||||
next if vm_mad == "vcenter"
|
||||
next if vm_mad == 'vcenter'
|
||||
|
||||
host_version=host['TEMPLATE/VERSION']
|
||||
host_version = host['TEMPLATE/VERSION']
|
||||
|
||||
begin
|
||||
host_version = Gem::Version.new(host_version)
|
||||
rescue
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
if !options[:force]
|
||||
begin
|
||||
next if host_version && host_version >= current_version
|
||||
rescue
|
||||
STDERR.puts "Error comparing versions for host #{host['NAME']}."
|
||||
rescue StandardError
|
||||
STDERR.puts 'Error comparing versions '\
|
||||
" for host #{host['NAME']}."
|
||||
end
|
||||
end
|
||||
|
||||
@ -320,45 +330,45 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
# Run the jobs in threads
|
||||
host_errors = Array.new
|
||||
host_errors = []
|
||||
queue_lock = Mutex.new
|
||||
error_lock = Mutex.new
|
||||
total = queue.length
|
||||
|
||||
if total==0
|
||||
puts "No hosts are going to be updated."
|
||||
if total.zero?
|
||||
puts 'No hosts are going to be updated.'
|
||||
exit(0)
|
||||
end
|
||||
|
||||
ts = (1..NUM_THREADS).map do |t|
|
||||
ts = (1..NUM_THREADS).map do |_t|
|
||||
Thread.new do
|
||||
while true do
|
||||
loop do
|
||||
host = nil
|
||||
size = 0
|
||||
|
||||
queue_lock.synchronize do
|
||||
host=queue.shift
|
||||
size=queue.length
|
||||
host = queue.shift
|
||||
size = queue.length
|
||||
end
|
||||
|
||||
break if !host
|
||||
break unless host
|
||||
|
||||
print_update_info(total-size, total, host['NAME'])
|
||||
print_update_info(total - size, total, host['NAME'])
|
||||
|
||||
if options[:rsync]
|
||||
sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}" <<
|
||||
" #{host['NAME']}:#{remote_dir}"
|
||||
sync_cmd = "rsync -Laz --delete #{REMOTES_LOCATION}" \
|
||||
" #{host['NAME']}:#{remote_dir}"
|
||||
else
|
||||
sync_cmd = "scp -rp #{REMOTES_LOCATION}/. " <<
|
||||
"#{host['NAME']}:#{remote_dir} 2> /dev/null"
|
||||
sync_cmd = "scp -rp #{REMOTES_LOCATION}/. " \
|
||||
"#{host['NAME']}:#{remote_dir} 2> /dev/null"
|
||||
end
|
||||
|
||||
`#{sync_cmd} 2>/dev/null`
|
||||
|
||||
if !$?.success?
|
||||
error_lock.synchronize {
|
||||
if !$CHILD_STATUS.success?
|
||||
error_lock.synchronize do
|
||||
host_errors << host['NAME']
|
||||
}
|
||||
end
|
||||
else
|
||||
update_version(host, current_version)
|
||||
end
|
||||
@ -367,16 +377,108 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
# Wait for threads to finish
|
||||
ts.each{|t| t.join}
|
||||
ts.each {|t| t.join }
|
||||
|
||||
puts
|
||||
|
||||
if host_errors.empty?
|
||||
puts "All hosts updated successfully."
|
||||
puts 'All hosts updated successfully.'
|
||||
0
|
||||
else
|
||||
STDERR.puts "Failed to update the following hosts:"
|
||||
host_errors.each{|h| STDERR.puts "* #{h}"}
|
||||
STDERR.puts 'Failed to update the following hosts:'
|
||||
host_errors.each {|h| STDERR.puts "* #{h}" }
|
||||
-1
|
||||
end
|
||||
end
|
||||
|
||||
def forceupdate(host_ids, options)
|
||||
if Process.uid.zero? || Process.gid.zero?
|
||||
STDERR.puts("Cannot run 'onehost forceupdate' as root")
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
cluster_id = options[:cluster]
|
||||
|
||||
# Get the Host pool
|
||||
filter_flag ||= OpenNebula::Pool::INFO_ALL
|
||||
|
||||
pool = factory_pool(filter_flag)
|
||||
|
||||
rc = pool.info
|
||||
return -1, rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
# Assign hosts to threads
|
||||
queue = []
|
||||
|
||||
pool.each do |host|
|
||||
if host_ids
|
||||
next unless host_ids.include?(host['ID'].to_i)
|
||||
elsif cluster_id
|
||||
next if host['CLUSTER_ID'].to_i != cluster_id
|
||||
end
|
||||
|
||||
vm_mad = host['VM_MAD'].downcase
|
||||
state = host['STATE']
|
||||
|
||||
# Skip this host from remote syncing if it's a PUBLIC_CLOUD host
|
||||
next if host['TEMPLATE/PUBLIC_CLOUD'] == 'YES'
|
||||
|
||||
# Skip this host from remote syncing if it's OFFLINE
|
||||
next if Host::HOST_STATES[state.to_i] == 'OFFLINE'
|
||||
|
||||
# Skip this host if it is a vCenter cluster
|
||||
next if vm_mad == 'vcenter'
|
||||
|
||||
queue << host
|
||||
end
|
||||
|
||||
# Run the jobs in threads
|
||||
host_errors = []
|
||||
queue_lock = Mutex.new
|
||||
error_lock = Mutex.new
|
||||
total = queue.length
|
||||
|
||||
if total.zero?
|
||||
puts 'No hosts are going to be forced.'
|
||||
exit(0)
|
||||
end
|
||||
|
||||
ts = (1..NUM_THREADS).map do |_t|
|
||||
Thread.new do
|
||||
loop do
|
||||
host = nil
|
||||
size = 0
|
||||
|
||||
queue_lock.synchronize do
|
||||
host = queue.shift
|
||||
size = queue.length
|
||||
end
|
||||
|
||||
break unless host
|
||||
|
||||
cmd = 'cat /tmp/one-collectd-client.pid | xargs kill -HUP'
|
||||
system("ssh #{host['NAME']} \"#{cmd}\" 2>/dev/null")
|
||||
|
||||
if !$CHILD_STATUS.success?
|
||||
error_lock.synchronize do
|
||||
host_errors << host['NAME']
|
||||
end
|
||||
else
|
||||
puts "#{host['NAME']} monitoring forced"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Wait for threads to finish
|
||||
ts.each {|t| t.join }
|
||||
|
||||
if host_errors.empty?
|
||||
puts 'All hosts updated successfully.'
|
||||
0
|
||||
else
|
||||
STDERR.puts 'Failed to update the following hosts:'
|
||||
host_errors.each {|h| STDERR.puts "* #{h}" }
|
||||
-1
|
||||
end
|
||||
end
|
||||
@ -384,22 +486,22 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
private
|
||||
|
||||
def print_update_info(current, total, host)
|
||||
bar_length=40
|
||||
bar_length = 40
|
||||
|
||||
percentage=current.to_f/total.to_f
|
||||
done=(percentage*bar_length).floor
|
||||
percentage = current.to_f / total.to_f
|
||||
done = (percentage * bar_length).floor
|
||||
|
||||
bar="["
|
||||
bar+="="*done
|
||||
bar+="-"*(bar_length-done)
|
||||
bar+="]"
|
||||
bar = '['
|
||||
bar += '=' * done
|
||||
bar += '-' * (bar_length - done)
|
||||
bar += ']'
|
||||
|
||||
info="#{current}/#{total}"
|
||||
info = "#{current}/#{total}"
|
||||
|
||||
str="#{bar} #{info} "
|
||||
name=host[0..(79-str.length)]
|
||||
str=str+name
|
||||
str=str+" "*(80-str.length)
|
||||
str = "#{bar} #{info} "
|
||||
name = host[0..(79 - str.length)]
|
||||
str += name
|
||||
str += ' ' * (80 - str.length)
|
||||
|
||||
print "#{str}\r"
|
||||
STDOUT.flush
|
||||
@ -412,54 +514,65 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
host.add_element(TEMPLATE_XPATH, 'VERSION' => version)
|
||||
|
||||
template=host.template_str
|
||||
template = host.template_str
|
||||
host.update(template)
|
||||
end
|
||||
|
||||
def factory(id=nil)
|
||||
def factory(id = nil)
|
||||
if id
|
||||
OpenNebula::Host.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::Host.build_xml
|
||||
xml = OpenNebula::Host.build_xml
|
||||
OpenNebula::Host.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
#TBD OpenNebula::HostPool.new(@client, user_flag)
|
||||
def factory_pool(_user_flag = -2)
|
||||
# TBD OpenNebula::HostPool.new(@client, user_flag)
|
||||
OpenNebula::HostPool.new(@client)
|
||||
end
|
||||
|
||||
def format_resource(host, options = {})
|
||||
str = "%-22s: %-20s"
|
||||
str_h1 = "%-80s"
|
||||
def format_resource(host, _options = {})
|
||||
str = '%-22s: %-20s'
|
||||
str_h1 = '%-80s'
|
||||
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
|
||||
str_h1 % "HOST #{host.id} INFORMATION", true
|
||||
)
|
||||
|
||||
puts str % ["ID", host.id.to_s]
|
||||
puts str % ["NAME", host.name]
|
||||
puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(host['CLUSTER'])]
|
||||
puts str % ["STATE", host.state_str]
|
||||
puts str % ["IM_MAD", host['IM_MAD']]
|
||||
puts str % ["VM_MAD", host['VM_MAD']]
|
||||
puts str % ["LAST MONITORING TIME", OpenNebulaHelper.time_to_str(host['LAST_MON_TIME'])]
|
||||
puts format(str, 'ID', host.id.to_s)
|
||||
puts format(str, 'NAME', host.name)
|
||||
puts format(str, 'CLUSTER',
|
||||
OpenNebulaHelper.cluster_str(host['CLUSTER']))
|
||||
puts format(str, 'STATE', host.state_str)
|
||||
puts format(str, 'IM_MAD', host['IM_MAD'])
|
||||
puts format(str, 'VM_MAD', host['VM_MAD'])
|
||||
puts format(str, 'LAST MONITORING TIME',
|
||||
OpenNebulaHelper.time_to_str(host['LAST_MON_TIME']))
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOST SHARES", false)
|
||||
puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
|
||||
CLIHelper.print_header(str_h1 % 'HOST SHARES', false)
|
||||
puts format(str, 'RUNNING VMS', host['HOST_SHARE/RUNNING_VMS'])
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MEMORY", false)
|
||||
puts str % [" TOTAL", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/TOTAL_MEM'].to_i, {})]
|
||||
puts str % [" TOTAL +/- RESERVED", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
|
||||
puts str % [" USED (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
|
||||
puts str % [" USED (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
|
||||
CLIHelper.print_header(str_h1 % 'MEMORY', false)
|
||||
puts format(str, ' TOTAL',
|
||||
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/TOTAL_MEM']
|
||||
.to_i, {}))
|
||||
puts format(str, ' TOTAL +/- RESERVED',
|
||||
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM']
|
||||
.to_i, {}))
|
||||
puts format(str, ' USED (REAL)',
|
||||
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM']
|
||||
.to_i, {}))
|
||||
puts format(str, ' USED (ALLOCATED)',
|
||||
OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE']
|
||||
.to_i, {}))
|
||||
|
||||
CLIHelper.print_header(str_h1 % "CPU", false)
|
||||
puts str % [" TOTAL", host['HOST_SHARE/TOTAL_CPU']]
|
||||
puts str % [" TOTAL +/- RESERVED", host['HOST_SHARE/MAX_CPU']]
|
||||
puts str % [" USED (REAL)", host['HOST_SHARE/USED_CPU']]
|
||||
puts str % [" USED (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
|
||||
CLIHelper.print_header(str_h1 % 'CPU', false)
|
||||
puts format(str, ' TOTAL', host['HOST_SHARE/TOTAL_CPU'])
|
||||
puts format(str, ' TOTAL +/- RESERVED', host['HOST_SHARE/MAX_CPU'])
|
||||
puts format(str, ' USED (REAL)', host['HOST_SHARE/USED_CPU'])
|
||||
puts format(str, ' USED (ALLOCATED)', host['HOST_SHARE/CPU_USAGE'])
|
||||
puts
|
||||
|
||||
datastores = host.to_hash['HOST']['HOST_SHARE']['DATASTORES']['DS']
|
||||
@ -471,26 +584,34 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
datastores.each do |datastore|
|
||||
CLIHelper.print_header(str_h1 % "LOCAL SYSTEM DATASTORE ##{datastore['ID']} CAPACITY", false)
|
||||
puts str % ["TOTAL:", OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB'].to_i, {},'M')]
|
||||
puts str % ["USED: ", OpenNebulaHelper.unit_to_str(datastore['USED_MB'].to_i, {},'M')]
|
||||
puts str % ["FREE:", OpenNebulaHelper.unit_to_str(datastore['FREE_MB'].to_i, {},'M')]
|
||||
CLIHelper.print_header(str_h1 %
|
||||
'LOCAL SYSTEM DATASTORE '\
|
||||
"##{datastore['ID']} CAPACITY", false)
|
||||
puts format(str, 'TOTAL:',
|
||||
OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB']
|
||||
.to_i, {}, 'M'))
|
||||
puts format(str, 'USED: ',
|
||||
OpenNebulaHelper.unit_to_str(datastore['USED_MB']
|
||||
.to_i, {}, 'M'))
|
||||
puts format(str, 'FREE:',
|
||||
OpenNebulaHelper.unit_to_str(datastore['FREE_MB']
|
||||
.to_i, {}, 'M'))
|
||||
puts
|
||||
end
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
|
||||
CLIHelper.print_header(str_h1 % 'MONITORING INFORMATION', false)
|
||||
|
||||
wilds = host.wilds
|
||||
|
||||
begin
|
||||
pcis = [host.to_hash['HOST']['HOST_SHARE']['PCI_DEVICES']['PCI']]
|
||||
pcis = pcis.flatten.compact
|
||||
rescue
|
||||
rescue StandardError
|
||||
pcis = nil
|
||||
end
|
||||
|
||||
host.delete_element("TEMPLATE/VM")
|
||||
host.delete_element("TEMPLATE_WILDS")
|
||||
host.delete_element('TEMPLATE/VM')
|
||||
host.delete_element('TEMPLATE_WILDS')
|
||||
|
||||
puts host.template_str
|
||||
|
||||
@ -499,81 +620,85 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
puts
|
||||
CLIHelper.print_header("WILD VIRTUAL MACHINES", false)
|
||||
CLIHelper.print_header('WILD VIRTUAL MACHINES', false)
|
||||
puts
|
||||
|
||||
format = "%-30.30s %36s %4s %10s"
|
||||
CLIHelper.print_header(format % ["NAME", "IMPORT_ID", "CPU", "MEMORY"],
|
||||
format = '%-30.30s %36s %4s %10s'
|
||||
CLIHelper.print_header(format(format, 'NAME',
|
||||
'IMPORT_ID', 'CPU', 'MEMORY'),
|
||||
true)
|
||||
|
||||
wilds.each do |wild|
|
||||
if wild['IMPORT_TEMPLATE']
|
||||
wild_tmplt = Base64::decode64(wild['IMPORT_TEMPLATE']).split("\n")
|
||||
name = wild['VM_NAME']
|
||||
import = wild_tmplt.select { |line|
|
||||
line[/^IMPORT_VM_ID/]
|
||||
}[0].split("=")[1].gsub("\"", " ").strip
|
||||
memory = wild_tmplt.select { |line|
|
||||
line[/^MEMORY/]
|
||||
}[0].split("=")[1].gsub("\"", " ").strip
|
||||
cpu = wild_tmplt.select { |line|
|
||||
line[/^CPU/]
|
||||
}[0].split("=")[1].gsub("\"", " ").strip
|
||||
else
|
||||
name = wild['DEPLOY_ID']
|
||||
import = memory = cpu = "-"
|
||||
end
|
||||
if wild['IMPORT_TEMPLATE']
|
||||
wild_tmplt = Base64.decode64(wild['IMPORT_TEMPLATE'])
|
||||
.split("\n")
|
||||
name = wild['VM_NAME']
|
||||
import = wild_tmplt.select do |line|
|
||||
line[/^IMPORT_VM_ID/]
|
||||
end[0].split('=')[1].tr('"', ' ').strip
|
||||
memory = wild_tmplt.select do |line|
|
||||
line[/^MEMORY/]
|
||||
end[0].split('=')[1].tr('"', ' ').strip
|
||||
cpu = wild_tmplt.select do |line|
|
||||
line[/^CPU/]
|
||||
end[0].split('=')[1].tr('"', ' ').strip
|
||||
else
|
||||
name = wild['DEPLOY_ID']
|
||||
import = memory = cpu = '-'
|
||||
end
|
||||
|
||||
puts format % [name, import, cpu, memory]
|
||||
puts format(format, name, import, cpu, memory)
|
||||
end
|
||||
|
||||
puts
|
||||
CLIHelper.print_header("VIRTUAL MACHINES", false)
|
||||
CLIHelper.print_header('VIRTUAL MACHINES', false)
|
||||
puts
|
||||
|
||||
onevm_helper=OneVMHelper.new
|
||||
onevm_helper.client=@client
|
||||
onevm_helper.list_pool({:filter=>["HOST=#{host.name}"], :no_pager => true}, false)
|
||||
onevm_helper = OneVMHelper.new
|
||||
onevm_helper.client = @client
|
||||
onevm_helper.list_pool({ :filter => ["HOST=#{host.name}"],
|
||||
:no_pager => true },
|
||||
false)
|
||||
end
|
||||
|
||||
def print_pcis(pcis)
|
||||
puts
|
||||
CLIHelper.print_header("PCI DEVICES", false)
|
||||
CLIHelper.print_header('PCI DEVICES', false)
|
||||
puts
|
||||
|
||||
table=CLIHelper::ShowTable.new(nil, self) do
|
||||
column :VM, "Used by VM", :size => 5, :left => false do |d|
|
||||
if d["VMID"] == "-1"
|
||||
""
|
||||
table = CLIHelper::ShowTable.new(nil, self) do
|
||||
column :VM, 'Used by VM', :size => 5, :left => false do |d|
|
||||
if d['VMID'] == '-1'
|
||||
''
|
||||
else
|
||||
d["VMID"]
|
||||
d['VMID']
|
||||
end
|
||||
end
|
||||
|
||||
column :ADDR, "PCI Address", :size => 7, :left => true do |d|
|
||||
d["SHORT_ADDRESS"]
|
||||
column :ADDR, 'PCI Address', :size => 7, :left => true do |d|
|
||||
d['SHORT_ADDRESS']
|
||||
end
|
||||
|
||||
column :TYPE, "Type", :size => 14, :left => true do |d|
|
||||
d["TYPE"]
|
||||
column :TYPE, 'Type', :size => 14, :left => true do |d|
|
||||
d['TYPE']
|
||||
end
|
||||
|
||||
column :CLASS, "Class", :size => 12, :left => true do |d|
|
||||
d["CLASS_NAME"]
|
||||
column :CLASS, 'Class', :size => 12, :left => true do |d|
|
||||
d['CLASS_NAME']
|
||||
end
|
||||
|
||||
column :NAME, "Name", :size => 50, :left => true do |d|
|
||||
d["DEVICE_NAME"]
|
||||
column :NAME, 'Name', :size => 50, :left => true do |d|
|
||||
d['DEVICE_NAME']
|
||||
end
|
||||
|
||||
column :VENDOR, "Vendor", :size => 8, :left => true do |d|
|
||||
d["VENDOR_NAME"]
|
||||
column :VENDOR, 'Vendor', :size => 8, :left => true do |d|
|
||||
d['VENDOR_NAME']
|
||||
end
|
||||
|
||||
default :VM, :ADDR, :TYPE, :NAME
|
||||
|
||||
end
|
||||
|
||||
table.show(pcis)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -285,4 +285,17 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
o.import_wild(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
forceupdate_desc = <<-EOT.unindent
|
||||
Forces host monitoring update
|
||||
Examples:
|
||||
onehost forceupdate host01
|
||||
onehost forceupdate host01,host02,host03
|
||||
onehost forceupdate -c myCluster
|
||||
EOT
|
||||
|
||||
command :forceupdate, forceupdate_desc, [:range, :hostid_list, nil],
|
||||
:options => [OneClusterHelper::CLUSTER] do
|
||||
helper.forceupdate(args[0], options)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user