mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
formating changes to CLI
This commit is contained in:
parent
39cb1ea9c1
commit
2d1f173ca2
@ -95,7 +95,8 @@ EOT
|
||||
phash = pool.to_hash
|
||||
rname = self.class.rname
|
||||
|
||||
if phash["#{rname}_POOL"] && phash["#{rname}_POOL"]["#{rname}"]
|
||||
if phash["#{rname}_POOL"] &&
|
||||
phash["#{rname}_POOL"]["#{rname}"]
|
||||
if phash["#{rname}_POOL"]["#{rname}"].instance_of?(Array)
|
||||
phash = phash["#{rname}_POOL"]["#{rname}"]
|
||||
else
|
||||
@ -130,7 +131,9 @@ EOT
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
else
|
||||
puts "#{self.class.rname} #{id}: #{verbose}" if options[:verbose]
|
||||
if options[:verbose]
|
||||
puts "#{self.class.rname} #{id}: #{verbose}"
|
||||
end
|
||||
return 0
|
||||
end
|
||||
end
|
||||
@ -260,12 +263,13 @@ EOT
|
||||
|
||||
if objects.length>0
|
||||
if objects.length>1
|
||||
return -1, "There are multiple #{ename}s with name #{name}."
|
||||
return -1,
|
||||
"There are multiple #{ename}s with name #{name}."
|
||||
else
|
||||
result = objects.first.id
|
||||
end
|
||||
else
|
||||
return -1, "#{ename} named #{name} not found."
|
||||
return -1, "#{ename} named #{name} not found."
|
||||
end
|
||||
|
||||
return 0, result
|
||||
@ -326,6 +330,7 @@ EOT
|
||||
def OpenNebulaHelper.name_to_id_desc(poolname)
|
||||
"OpenNebula #{poolname} name or id"
|
||||
end
|
||||
|
||||
def OpenNebulaHelper.public_to_str(str)
|
||||
if str.to_i == 1
|
||||
public_str = "Y"
|
||||
@ -384,4 +389,4 @@ EOT
|
||||
str = File.read(path)
|
||||
str
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -119,7 +119,8 @@ private
|
||||
d['STRING'].split(" ")[1].split("/")[1]
|
||||
end
|
||||
|
||||
column :OPE_CDUMIPpTW, "Operation to which the rule applies" do |d|
|
||||
column :OPE_CDUMIPpTW,
|
||||
"Operation to which the rule applies" do |d|
|
||||
OneAclHelper::right_mask d['STRING'].split(" ")[2]
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,7 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
column :NAME, "Name of the Group", :left, :size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
|
||||
column :USER, "Username of the Group owner", :left,
|
||||
:size=>8 do |d|
|
||||
helper.user_name(d, options)
|
||||
@ -82,4 +82,4 @@ class OneGroupHelper < OpenNebulaHelper::OneHelper
|
||||
table.show(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -51,7 +51,8 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
str = "%-22s: %-20s"
|
||||
str_h1 = "%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
|
||||
|
||||
puts str % ["ID", host.id.to_s]
|
||||
puts str % ["NAME", host.name]
|
||||
@ -97,33 +98,42 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
end
|
||||
|
||||
column :FCPU, "Free CPU percentage", :size=>6 do |d|
|
||||
d["HOST_SHARE"]["MAX_CPU"].to_i-d["HOST_SHARE"]["USED_CPU"].to_i
|
||||
d["HOST_SHARE"]["MAX_CPU"].to_i-
|
||||
d["HOST_SHARE"]["USED_CPU"].to_i
|
||||
end
|
||||
|
||||
column :ACPU, "Available cpu percentage (not reserved by VMs)", :size=>6 do |d|
|
||||
column :ACPU, "Available cpu percentage (not reserved by VMs)",
|
||||
:size=>6 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
|
||||
end
|
||||
|
||||
column :TMEM, "Total Memory", :size=>6 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["MAX_MEM"].to_i,options)
|
||||
OpenNebulaHelper.unit_to_str(
|
||||
d["HOST_SHARE"]["MAX_MEM"].to_i,
|
||||
options)
|
||||
end
|
||||
|
||||
column :FMEM, "Free Memory", :size=>6 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d["HOST_SHARE"]["FREE_MEM"].to_i,options)
|
||||
OpenNebulaHelper.unit_to_str(
|
||||
d["HOST_SHARE"]["FREE_MEM"].to_i,
|
||||
options)
|
||||
end
|
||||
|
||||
column :AMEM, "Available Memory (not reserved by VMs)", :size=>6 do |d|
|
||||
acpu=d["HOST_SHARE"]["MAX_MEM"].to_i-d["HOST_SHARE"]["MEM_USAGE"].to_i
|
||||
column :AMEM, "Available Memory (not reserved by VMs)",
|
||||
:size=>6 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 :STAT, "Host status", :size=>6 do |d|
|
||||
OneHostHelper.state_to_str(d["STATE"])
|
||||
end
|
||||
|
||||
default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM, :AMEM, :STAT
|
||||
default :ID, :NAME, :RVM, :TCPU, :FCPU, :ACPU, :TMEM, :FMEM,
|
||||
:AMEM, :STAT
|
||||
end
|
||||
|
||||
if top
|
||||
@ -132,4 +142,4 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
table.show(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -64,9 +64,11 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
puts str % ["ID", image.id.to_s]
|
||||
puts str % ["NAME", image.name]
|
||||
puts str % ["TYPE", image.type_str]
|
||||
puts str % ["REGISTER TIME", OpenNebulaHelper.time_to_str(image['REGTIME'])]
|
||||
puts str % ["REGISTER TIME",
|
||||
OpenNebulaHelper.time_to_str(image['REGTIME'])]
|
||||
puts str % ["PUBLIC", OpenNebulaHelper.public_to_str(image['PUBLIC'])]
|
||||
puts str % ["PERSISTENT", OneImageHelper.persistent_to_str(image["PERSISTENT"])]
|
||||
puts str % ["PERSISTENT",
|
||||
OneImageHelper.persistent_to_str(image["PERSISTENT"])]
|
||||
puts str % ["SOURCE", image['SOURCE']]
|
||||
puts str % ["STATE", image.short_state_str]
|
||||
puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
|
||||
@ -101,15 +103,18 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
OneImageHelper.type_to_str(d["TYPE"])
|
||||
end
|
||||
|
||||
column :REGTIME, "Registration time of the Image", :size=>20 do |d|
|
||||
column :REGTIME, "Registration time of the Image",
|
||||
:size=>20 do |d|
|
||||
OpenNebulaHelper.time_to_str(d["REGTIME"])
|
||||
end
|
||||
|
||||
column :PUBLIC, "Whether the Image is public or not", :size=>3 do |d|
|
||||
column :PUBLIC, "Whether the Image is public or not",
|
||||
:size=>3 do |d|
|
||||
OpenNebulaHelper.public_to_str(d["PUBLIC"])
|
||||
end
|
||||
|
||||
column :PERSISTENT, "Whether the Image is persistent or not", :size=>3 do |d|
|
||||
column :PERSISTENT, "Whether the Image is persistent or not",
|
||||
:size=>3 do |d|
|
||||
OneImageHelper.persistent_to_str(d["PERSISTENT"])
|
||||
end
|
||||
|
||||
@ -117,11 +122,13 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
OneImageHelper.state_to_str(d["STATE"])
|
||||
end
|
||||
|
||||
column :RVMS, "Number of VMs currently running from this Image", :size=>5 do |d|
|
||||
column :RVMS, "Number of VMs currently running from this Image",
|
||||
:size=>5 do |d|
|
||||
d['RUNNING_VMS']
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :REGTIME, :PUBLIC, :PERSISTENT , :STAT, :RVMS
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :REGTIME, :PUBLIC,
|
||||
:PERSISTENT , :STAT, :RVMS
|
||||
end
|
||||
|
||||
if top
|
||||
@ -130,4 +137,4 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
|
||||
table.show(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -44,11 +44,14 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "TEMPLATE #{template['ID']} INFORMATION")
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "TEMPLATE #{template['ID']} INFORMATION")
|
||||
puts str % ["ID", template.id.to_s]
|
||||
puts str % ["NAME", template.name]
|
||||
puts str % ["REGISTER TIME", OpenNebulaHelper.time_to_str(template['REGTIME'])]
|
||||
puts str % ["PUBLIC", OpenNebulaHelper.public_to_str(template['PUBLIC'])]
|
||||
puts str % ["REGISTER TIME",
|
||||
OpenNebulaHelper.time_to_str(template['REGTIME'])]
|
||||
puts str % ["PUBLIC",
|
||||
OpenNebulaHelper.public_to_str(template['PUBLIC'])]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "TEMPLATE CONTENTS",false)
|
||||
@ -75,11 +78,13 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
|
||||
helper.group_name(d, options)
|
||||
end
|
||||
|
||||
column :REGTIME, "Registration time of the Template", :size=>20 do |d|
|
||||
column :REGTIME, "Registration time of the Template",
|
||||
:size=>20 do |d|
|
||||
OpenNebulaHelper.time_to_str(d["REGTIME"])
|
||||
end
|
||||
|
||||
column :PUBLIC, "Whether the Template is public or not", :size=>3 do |d|
|
||||
column :PUBLIC, "Whether the Template is public or not",
|
||||
:size=>3 do |d|
|
||||
OpenNebulaHelper.public_to_str(d["PUBLIC"])
|
||||
end
|
||||
|
||||
@ -92,4 +97,4 @@ class OneTemplateHelper < OpenNebulaHelper::OneHelper
|
||||
table.show(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -43,7 +43,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
password = Digest::SHA1.hexdigest(arg)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return 0, password
|
||||
end
|
||||
|
||||
@ -110,4 +110,4 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
table.show(pool, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -66,7 +66,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
str_h1="%-80s"
|
||||
str="%-20s: %-20s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE #{vm['ID']} INFORMATION")
|
||||
CLIHelper.print_header(
|
||||
str_h1 % "VIRTUAL MACHINE #{vm['ID']} INFORMATION")
|
||||
puts str % ["ID", vm.id.to_s]
|
||||
puts str % ["NAME", vm.name]
|
||||
puts str % ["STATE", vm.state_str]
|
||||
@ -108,7 +109,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Machine", :left, :size=>15 do |d|
|
||||
column :NAME, "Name of the Virtual Machine", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
@ -144,10 +146,15 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
stime = Time.at(d["STIME"].to_i)
|
||||
etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i)
|
||||
dtime = Time.at(etime-stime).getgm
|
||||
"%02d %02d:%02d:%02d" % [dtime.yday-1, dtime.hour, dtime.min, dtime.sec]
|
||||
"%02d %02d:%02d:%02d" % [
|
||||
dtime.yday-1,
|
||||
dtime.hour,
|
||||
dtime.min,
|
||||
dtime.sec]
|
||||
end
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, :TIME
|
||||
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME,
|
||||
:TIME
|
||||
end
|
||||
|
||||
if top
|
||||
@ -205,4 +212,4 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
table.show(history)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,7 +48,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
def format_resource(vn)
|
||||
str_h1="%-80s"
|
||||
CLIHelper.print_header(str_h1 % ["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"])
|
||||
CLIHelper.print_header(str_h1 %
|
||||
["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"])
|
||||
|
||||
str="%-10s: %-20s"
|
||||
puts str % ["ID: ", vn.id.to_s]
|
||||
@ -75,7 +76,8 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Virtual Network", :left, :size=>15 do |d|
|
||||
column :NAME, "Name of the Virtual Network", :left,
|
||||
:size=>15 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
@ -97,15 +99,18 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d["SIZE"]
|
||||
end
|
||||
|
||||
column :BRIDGE, "Bridge associated to the Virtual Network", :size=>6 do |d|
|
||||
column :BRIDGE, "Bridge associated to the Virtual Network",
|
||||
:size=>6 do |d|
|
||||
d["BRIDGE"]
|
||||
end
|
||||
|
||||
column :PUBLIC, "Whether the Virtual Network is public or not", :size=>1 do |d|
|
||||
column :PUBLIC, "Whether the Virtual Network is public or not",
|
||||
:size=>1 do |d|
|
||||
OpenNebulaHelper.public_to_str(d['PUBLIC'])
|
||||
end
|
||||
|
||||
column :LEASES, "Number of this Virtual Network's given leases", :size=>7 do |d|
|
||||
column :LEASES, "Number of this Virtual Network's given leases",
|
||||
:size=>7 do |d|
|
||||
d["TOTAL_LEASES"]
|
||||
end
|
||||
|
||||
|
@ -56,7 +56,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a new ACL rule
|
||||
EOT
|
||||
|
||||
command :create, addrule_desc, [:user,:rulestr], [:resource, nil], [:rights, nil] do
|
||||
command :create, addrule_desc, [:user,:rulestr], [:resource, nil],
|
||||
[:rights, nil] do
|
||||
case args.length
|
||||
when 1
|
||||
new_args=Acl.parse_rule(args[0])
|
||||
|
@ -40,7 +40,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
list_options << OpenNebulaHelper::NUMERIC
|
||||
@ -105,7 +105,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
unpublish_desc = <<-EOT.unindent
|
||||
Unpublishes the given Image. A private Image can't be used by any other
|
||||
Unpublishes the given Image. A private Image can't be used by any other
|
||||
User
|
||||
EOT
|
||||
|
||||
@ -183,9 +183,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Image owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :imageid_list], :userid, [:groupid,nil] do
|
||||
command :chown, chown_desc, [:range, :imageid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |image|
|
||||
helper.perform_actions(args[0],options,
|
||||
"Owner/Group changed") do |image|
|
||||
image.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
|
@ -146,7 +146,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Template owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :templateid_list], :userid, [:groupid,nil] do
|
||||
command :chown, chown_desc, [:range, :templateid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_id
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |t|
|
||||
t.chown(args[1].to_i, gid)
|
||||
|
@ -40,11 +40,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
list_options << OpenNebulaHelper::NUMERIC
|
||||
|
||||
|
||||
READ_FILE={
|
||||
:name => "read_file",
|
||||
:short => "-r",
|
||||
@ -58,7 +58,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:large => "--plain-password",
|
||||
:description => "Store plain password"
|
||||
}
|
||||
|
||||
|
||||
create_options = [READ_FILE, PLAIN]
|
||||
|
||||
########################################################################
|
||||
@ -88,7 +88,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Creates a new User
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :username, :password, :options=>create_options do
|
||||
command :create, create_desc, :username, :password,
|
||||
:options=>create_options do
|
||||
helper.create_resource(options) do |user|
|
||||
user.allocate(args[0], args[1])
|
||||
end
|
||||
|
@ -312,7 +312,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Image owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :vmid_list], :userid, [:groupid,nil] do
|
||||
command :chown, chown_desc, [:range, :vmid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_id
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |vm|
|
||||
vm.chown(args[1].to_i, gid)
|
||||
@ -345,4 +346,4 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:options=>CLIHelper::OPTIONS+OpenNebulaHelper::OPTIONS do
|
||||
helper.list_pool(options, true, args[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -93,7 +93,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a lease to the Virtual Network
|
||||
EOT
|
||||
|
||||
command :addleases, 'Adds a lease to the Virtual Network', :vnetid, :ip, [:mac, nil] do
|
||||
command :addleases, 'Adds a lease to the Virtual Network', :vnetid, :ip,
|
||||
[:mac, nil] do
|
||||
helper.perform_action(args[0],options,"lease added") do |vn|
|
||||
vn.addleases(args[1], args[2])
|
||||
end
|
||||
@ -145,7 +146,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Changes the Virtual Network owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :vnid_list], :userid, [:groupid,nil] do
|
||||
command :chown, chown_desc, [:range, :vnid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_id
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |vn|
|
||||
vn.chown(args[1].to_i, gid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user