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

bug #747: one* top commands refresh information

This commit is contained in:
Daniel Molina 2011-08-02 15:57:34 +02:00
parent 85d8ef3e7c
commit eaa91a534e
10 changed files with 69 additions and 75 deletions

View File

@ -132,17 +132,19 @@ module CLIHelper
def show(data, options={})
update_columns(options)
print_table(data, options)
print_table(data, options)
end
def top(data, options={})
update_columns(options)
def top(options={}, &block)
delay=options[:delay] ? options[:delay] : 1
begin
while true
CLIHelper.scr_cls
CLIHelper.scr_move(0,0)
data = block.call
show(data, options)
sleep delay
end

View File

@ -92,21 +92,17 @@ EOT
if options[:xml]
return 0, pool.to_xml(true)
else
phash = pool.to_hash
rname = self.class.rname
table = format_pool(options)
if phash["#{rname}_POOL"] &&
phash["#{rname}_POOL"]["#{rname}"]
if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array)
phash = phash["#{rname}_POOL"]["#{rname}"]
else
phash = [phash["#{rname}_POOL"]["#{rname}"]]
end
if top
table.top(options) {
pool.info
pool_to_array(pool)
}
else
phash = Array.new
table.show(pool_to_array(pool), options)
end
format_pool(phash, options, top)
return 0
end
end
@ -288,6 +284,24 @@ EOT
OpenNebula.is_error?(rc) ? rc : resource
end
def pool_to_array(pool)
phash = pool.to_hash
rname = self.class.rname
if phash["#{rname}_POOL"] &&
phash["#{rname}_POOL"]["#{rname}"]
if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array)
phash = phash["#{rname}_POOL"]["#{rname}"]
else
phash = [phash["#{rname}_POOL"]["#{rname}"]]
end
else
phash = Array.new
end
phash
end
def translation_hash
@translation_hash ||= {
:users => generate_resource_translation(UserPool),

View File

@ -97,10 +97,10 @@ private
mask
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
def format_pool(options)
config_file = self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "Rule Identifier",
:size=>5 do |d|
d['ID']
@ -127,8 +127,7 @@ private
default :ID, :USER, :RES_VHNIUTG, :RID, :OPE_CDUMIPpTW
end
table.show(pool, options)
table
end
end

View File

@ -106,9 +106,10 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
end
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Group", :size=>4 do |d|
d["ID"]
end
@ -120,10 +121,6 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
default :ID, :NAME
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end

View File

@ -78,9 +78,10 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
puts host.template_str
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
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"]
end
@ -136,10 +137,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
:AMEM, :STAT
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end

View File

@ -77,9 +77,10 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
puts image.template_str
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Image", :size=>4 do |d|
d["ID"]
end
@ -130,10 +131,6 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
:PERSISTENT , :STAT, :RVMS
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end

View File

@ -60,9 +60,10 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
puts template.template_str
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the Template", :size=>4 do |d|
d["ID"]
end
@ -93,10 +94,6 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
default :ID, :USER, :GROUP, :NAME, :REGTIME, :PUBLIC
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end

View File

@ -76,9 +76,10 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
OpenNebulaHelper.boolean_to_str(user['ENABLED'])]
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the User", :size=>4 do |d|
d["ID"]
end
@ -98,10 +99,6 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
default :ID, :GROUP, :NAME, :PASSWORD
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end

View File

@ -107,9 +107,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d|
d["ID"]
end
@ -162,11 +163,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
:TIME
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
def format_history(vm)

View File

@ -72,9 +72,10 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
end
end
def format_pool(pool, options, top=false)
config_file=self.class.table_conf
table=CLIHelper::ShowTable.new(config_file, self) do
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d|
d["ID"]
end
@ -120,10 +121,6 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :PUBLIC, :LEASES
end
if top
table.top(pool, options)
else
table.show(pool, options)
end
table
end
end