mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #661: Remove trailing spaces
This commit is contained in:
parent
ff0f977884
commit
0cbef148cd
@ -22,7 +22,7 @@ module CLIHelper
|
||||
:format => Array,
|
||||
:description => "Selects columns to display with list command"
|
||||
}
|
||||
|
||||
|
||||
#ORDER = {
|
||||
# :name => "order",
|
||||
# :short => "-o x,y,z",
|
||||
@ -45,7 +45,7 @@ module CLIHelper
|
||||
# :large => "--header",
|
||||
# :description => "Shows the header of the table"
|
||||
#}
|
||||
|
||||
|
||||
DELAY = {
|
||||
:name => "delay",
|
||||
:short => "-d x",
|
||||
@ -53,10 +53,10 @@ module CLIHelper
|
||||
:format => Integer,
|
||||
:description => "Sets the delay in seconds for top command"
|
||||
}
|
||||
|
||||
|
||||
#OPTIONS = [LIST, ORDER, FILTER, HEADER, DELAY]
|
||||
OPTIONS = [LIST, DELAY]
|
||||
|
||||
|
||||
# Sets bold font
|
||||
def CLIHelper.scr_bold
|
||||
print "\33[1m"
|
||||
@ -93,17 +93,17 @@ module CLIHelper
|
||||
|
||||
class ShowTable
|
||||
include CLIHelper
|
||||
|
||||
|
||||
def initialize(conf=nil, ext=nil, &block)
|
||||
# merge del conf con la table
|
||||
@columns = Hash.new
|
||||
@default_columns = Array.new
|
||||
|
||||
|
||||
@ext = ext
|
||||
|
||||
|
||||
instance_eval(&block)
|
||||
end
|
||||
|
||||
|
||||
def column(name, desc, *conf, &block)
|
||||
column = Hash.new
|
||||
column[:desc] = desc
|
||||
@ -121,16 +121,16 @@ module CLIHelper
|
||||
@columns[name.to_sym] = column
|
||||
@default_columns<<name
|
||||
end
|
||||
|
||||
|
||||
def default(*args)
|
||||
@default_columns=args
|
||||
end
|
||||
|
||||
|
||||
def show(data, options={})
|
||||
update_columns(options)
|
||||
print_table(data, options)
|
||||
end
|
||||
|
||||
|
||||
def top(data, options={})
|
||||
update_columns(options)
|
||||
delay=options[:delay] ? options[:delay] : 1
|
||||
@ -145,14 +145,14 @@ module CLIHelper
|
||||
rescue Exception
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def print_table(data, options)
|
||||
CLIHelper.print_header(header_str)
|
||||
print_data(data, options)
|
||||
end
|
||||
|
||||
|
||||
def print_data(data, options)
|
||||
ncolumns=@default_columns.length
|
||||
res_data=data_array(data, options)
|
||||
@ -160,17 +160,17 @@ module CLIHelper
|
||||
(0..ncolumns-1).collect{ |i|
|
||||
dat=l[i]
|
||||
col=@default_columns[i]
|
||||
|
||||
|
||||
if @columns[col] && @columns[col][:humanize]
|
||||
dat = @columns[col][:humanize].call(dat)
|
||||
end
|
||||
|
||||
|
||||
format_str(col, dat)
|
||||
}.join(' ')
|
||||
}.join("\n")
|
||||
puts
|
||||
end
|
||||
|
||||
|
||||
def data_array(data, options)
|
||||
res_data=data.collect {|d|
|
||||
@default_columns.collect {|c|
|
||||
@ -185,17 +185,17 @@ module CLIHelper
|
||||
|
||||
res_data
|
||||
end
|
||||
|
||||
|
||||
def format_str(field, data)
|
||||
minus=( @columns[field][:left] ? "-" : "" )
|
||||
size=@columns[field][:size]
|
||||
"%#{minus}#{size}.#{size}s" % [ data.to_s ]
|
||||
end
|
||||
|
||||
|
||||
def update_columns(options)
|
||||
@default_columns = options[:list].collect{|o| o.to_sym} if options[:list]
|
||||
end
|
||||
|
||||
|
||||
def header_str
|
||||
@default_columns.collect {|c|
|
||||
if @columns[c]
|
||||
@ -205,9 +205,9 @@ module CLIHelper
|
||||
end
|
||||
}.compact.join(' ')
|
||||
end
|
||||
|
||||
|
||||
# TBD def filter_data!
|
||||
|
||||
|
||||
# TBD def sort_data!
|
||||
end
|
||||
end
|
@ -32,33 +32,33 @@ module CommandParser
|
||||
:description => "Show this message"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
class CmdParser
|
||||
attr_reader :options, :args
|
||||
|
||||
|
||||
def initialize(args=[], &block)
|
||||
@opts = Array.new
|
||||
@commands = Hash.new
|
||||
@formats = Hash.new
|
||||
@script = nil
|
||||
@usage = ""
|
||||
|
||||
|
||||
@args = args
|
||||
@options = Hash.new
|
||||
|
||||
|
||||
set :format, :file, "" do |arg| format_file(arg) ; end
|
||||
set :format, :range, "" do |arg| format_range(arg) ; end
|
||||
set :format, :text, "" do |arg| format_text(arg) ; end
|
||||
|
||||
|
||||
instance_eval(&block)
|
||||
|
||||
|
||||
self.run
|
||||
end
|
||||
|
||||
|
||||
def usage(str)
|
||||
@usage = "Usage: #{str}"
|
||||
end
|
||||
|
||||
|
||||
def set(e, *args, &block)
|
||||
case e
|
||||
when :option
|
||||
@ -67,7 +67,7 @@ module CommandParser
|
||||
add_format(args[0], args[1], block)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def command(name, desc, *args_format, &block)
|
||||
cmd = Hash.new
|
||||
cmd[:desc] = desc
|
||||
@ -103,10 +103,10 @@ module CommandParser
|
||||
@script[:args_format] << [args]
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
@script[:proc] = block
|
||||
end
|
||||
|
||||
|
||||
def run
|
||||
comm_name=""
|
||||
if @script
|
||||
@ -117,24 +117,24 @@ module CommandParser
|
||||
comm=@commands[comm_name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if comm.nil?
|
||||
help
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
extra_options = comm[:options] if comm
|
||||
parse(extra_options)
|
||||
if comm
|
||||
check_args!(comm_name, comm[:arity], comm[:args_format])
|
||||
|
||||
|
||||
begin
|
||||
rc = comm[:proc].call
|
||||
rescue Exception =>e
|
||||
puts e.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
if rc.instance_of?(Array)
|
||||
puts rc[1]
|
||||
exit rc.first
|
||||
@ -143,7 +143,7 @@ module CommandParser
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def help
|
||||
puts @usage
|
||||
puts
|
||||
@ -153,12 +153,12 @@ module CommandParser
|
||||
puts
|
||||
print_formatters
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def print_options
|
||||
puts "Options:"
|
||||
|
||||
|
||||
shown_opts = Array.new
|
||||
opt_format = "#{' '*5}%-25s %s"
|
||||
@commands.each{ |key,value|
|
||||
@ -173,22 +173,22 @@ module CommandParser
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@opts.each{ |o|
|
||||
printf opt_format, "#{o[:short]}, #{o[:large]}", o[:description]
|
||||
puts
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def print_commands
|
||||
puts "Commands:"
|
||||
|
||||
|
||||
cmd_format5 = "#{' '*5}%s"
|
||||
cmd_format10 = "#{' '*10}%s"
|
||||
@commands.each{ |key,value|
|
||||
printf cmd_format5, "* #{key}"
|
||||
puts
|
||||
|
||||
|
||||
args_str=value[:args_format].collect{ |a|
|
||||
if a.include?(nil)
|
||||
"[#{a.compact.join("|")}]"
|
||||
@ -198,12 +198,12 @@ module CommandParser
|
||||
}.join(' ')
|
||||
printf cmd_format10, "arguments: #{args_str}"
|
||||
puts
|
||||
|
||||
|
||||
value[:desc].split("\n").each { |l|
|
||||
printf cmd_format10, l
|
||||
puts
|
||||
}
|
||||
|
||||
|
||||
unless value[:options].empty?
|
||||
opts_str=value[:options].flatten.collect{|o|
|
||||
o[:name]
|
||||
@ -214,23 +214,23 @@ module CommandParser
|
||||
puts
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def print_formatters
|
||||
puts "argument formats:"
|
||||
|
||||
|
||||
cmd_format5 = "#{' '*5}%s"
|
||||
cmd_format10 = "#{' '*10}%s"
|
||||
@formats.each{ |key,value|
|
||||
printf cmd_format5, "* #{key}"
|
||||
puts
|
||||
|
||||
|
||||
value[:desc].split("\n").each { |l|
|
||||
printf cmd_format10, l
|
||||
puts
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def add_option(option)
|
||||
if option.instance_of?(Array)
|
||||
option.each { |o| @opts << o }
|
||||
@ -238,7 +238,7 @@ module CommandParser
|
||||
@opts << option
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def add_format(format, description, block)
|
||||
@formats[format] = {
|
||||
:desc => description,
|
||||
@ -272,7 +272,7 @@ module CommandParser
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def check_args!(name, arity, args_format)
|
||||
if @args.length < arity
|
||||
print "Command #{name} requires "
|
||||
@ -305,19 +305,19 @@ module CommandParser
|
||||
exit -1
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
unless argument
|
||||
puts error_msg if error_msg
|
||||
puts "command #{name}: argument #{id} must be one of #{format.join(', ')}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
|
||||
id+=1
|
||||
argument
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
@ -328,9 +328,9 @@ module CommandParser
|
||||
def format_file(arg)
|
||||
File.exists?(arg) ? [0,arg] : [-1]
|
||||
end
|
||||
|
||||
|
||||
REG_RANGE=/^(?:(?:\d+\.\.\d+|\d+),)*(?:\d+\.\.\d+|\d+)$/
|
||||
|
||||
|
||||
def format_range(arg)
|
||||
arg_s = arg.gsub(" ","").to_s
|
||||
return [-1] unless arg_s.match(REG_RANGE)
|
||||
@ -345,7 +345,7 @@ module CommandParser
|
||||
return [-1]
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
return 0,ids.uniq
|
||||
end
|
||||
end
|
||||
|
@ -20,14 +20,21 @@ require 'OpenNebula'
|
||||
include OpenNebula
|
||||
|
||||
module OpenNebulaHelper
|
||||
########################################################################
|
||||
# Options
|
||||
########################################################################
|
||||
XML={
|
||||
:name => "xml",
|
||||
:short => "-x",
|
||||
:large => "--xml",
|
||||
:description => "Show the resource in xml format"
|
||||
}
|
||||
|
||||
class OneHelper
|
||||
|
||||
########################################################################
|
||||
# Formatters descriptions
|
||||
########################################################################
|
||||
|
||||
class OneHelper
|
||||
def initialize
|
||||
@client = OpenNebula::Client.new
|
||||
@translation_hash = nil
|
||||
@ -37,21 +44,21 @@ module OpenNebulaHelper
|
||||
resource = factory
|
||||
|
||||
rc = resource.allocate(template)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
if OpenNebula.is_error?(rc)
|
||||
return -1, rc.message
|
||||
else
|
||||
puts "ID: #{resource.id.to_s}" if options[:verbose]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def list_pool(options)
|
||||
user_flag = options[:filter_flag] ? options[:filter_flag] : -2
|
||||
pool = factory_pool(user_flag)
|
||||
|
||||
rc = pool.info
|
||||
return -1, rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
if options[:xml]
|
||||
return 0, pool.to_xml(true)
|
||||
else
|
||||
@ -60,11 +67,11 @@ module OpenNebulaHelper
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show_resource(id, options)
|
||||
resource = retrieve_resource(id)
|
||||
return -1, resource.message if OpenNebula.is_error?(resource)
|
||||
|
||||
|
||||
if options[:xml]
|
||||
return 0, resource.to_xml(true)
|
||||
else
|
||||
@ -73,8 +80,8 @@ module OpenNebulaHelper
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
def perform_action(id, args, options, verbose, &block)
|
||||
|
||||
def perform_action(id, options, verbose, &block)
|
||||
resource = retrieve_resource(id)
|
||||
return -1, resource.message if OpenNebula.is_error?(resource)
|
||||
|
||||
@ -83,15 +90,15 @@ module OpenNebulaHelper
|
||||
return -1, rc.message
|
||||
else
|
||||
rname=Object.const_get(self.class.name)::RESOURCE
|
||||
puts "#{rname} #{id} #{verbose}" if options[:verbose]
|
||||
puts "#{rname} #{id}: #{verbose}" if options[:verbose]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
def perform_actions(ids,args,options,verbose,&block)
|
||||
|
||||
def perform_actions(ids,options,verbose,&block)
|
||||
exit_code = 0
|
||||
ids.each do |id|
|
||||
rc = perform_action(id,args,options,verbose,&block)
|
||||
rc = perform_action(id,options,verbose,&block)
|
||||
|
||||
unless rc[0]==0
|
||||
puts rc[1]
|
||||
@ -101,43 +108,43 @@ module OpenNebulaHelper
|
||||
|
||||
exit_code
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
def to_id(name, pool=nil)
|
||||
return 0, name if name.match(/^[0123456789]+$/)
|
||||
|
||||
|
||||
user_flag = -2
|
||||
pool = pool ? pool : factory_pool(user_flag)
|
||||
|
||||
|
||||
rc = pool.info
|
||||
return -1, rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
objects=pool.select {|object| object.name==name }
|
||||
|
||||
|
||||
if objects.length>0
|
||||
if objects.length>1
|
||||
rname=Object.const_get(self.class.name)::RESOURCE
|
||||
rname = Object.const_get(self.class.name)::RESOURCE
|
||||
return -1, "There are multiple #{rname}s with name #{name}."
|
||||
else
|
||||
result=objects.first.id
|
||||
result = objects.first.id
|
||||
end
|
||||
else
|
||||
rname=Object.const_get(self.class.name)::RESOURCE
|
||||
return -1, "#{rname} named #{name} not found."
|
||||
end
|
||||
|
||||
|
||||
return 0, result
|
||||
end
|
||||
|
||||
|
||||
def list_to_id(names)
|
||||
user_flag = -2
|
||||
pool = factory_pool(user_flag)
|
||||
|
||||
|
||||
rc = pool.info
|
||||
return -1, rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
result = names.split(',').collect { |name|
|
||||
rc = to_id(name)
|
||||
unless rc.first==0
|
||||
@ -145,10 +152,10 @@ module OpenNebulaHelper
|
||||
end
|
||||
rc[1]
|
||||
}
|
||||
|
||||
|
||||
return 0, result
|
||||
end
|
||||
|
||||
|
||||
def filterflag_to_i(str)
|
||||
filter_flag = case str
|
||||
when "a", "all" then "-2"
|
||||
@ -163,19 +170,19 @@ module OpenNebulaHelper
|
||||
user.length > 0 ? user.first.first : "-2"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return 0, filter_flag
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def retrieve_resource(id)
|
||||
resource = factory(id)
|
||||
|
||||
|
||||
rc = resource.info
|
||||
OpenNebula.is_error?(rc) ? rc : resource
|
||||
end
|
||||
|
||||
|
||||
def generate_translation_hash
|
||||
@translation_hash ||= {
|
||||
:users => generate_user_translation,
|
||||
@ -183,19 +190,19 @@ module OpenNebulaHelper
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
|
||||
def generate_user_translation
|
||||
user_pool = UserPool.new(@client)
|
||||
user_pool.info
|
||||
|
||||
|
||||
hash = Hash.new
|
||||
user_pool.each { |user|
|
||||
hash[user["ID"]]=user["NAME"]
|
||||
}
|
||||
hash
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def generate_group_translation
|
||||
group_pool = GroupPool.new(@client)
|
||||
group_pool.info
|
||||
@ -207,15 +214,15 @@ module OpenNebulaHelper
|
||||
hash
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def OpenNebulaHelper.public_to_str(str)
|
||||
if str.to_i == 1
|
||||
public_str = "Y"
|
||||
else
|
||||
public_str = "N"
|
||||
if str.to_i == 1
|
||||
public_str = "Y"
|
||||
else
|
||||
public_str = "N"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def OpenNebulaHelper.uid_to_str(uid, hash={})
|
||||
if hash[:users] && hash[:users][uid]
|
||||
hash[:users][uid]
|
||||
@ -223,7 +230,7 @@ module OpenNebulaHelper
|
||||
uid
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def OpenNebulaHelper.gid_to_str(gid, hash={})
|
||||
if hash[:groups] && hash[:groups][gid]
|
||||
hash[:groups][gid]
|
||||
@ -231,7 +238,7 @@ module OpenNebulaHelper
|
||||
gid
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def OpenNebulaHelper.time_to_str(time)
|
||||
value=time.to_i
|
||||
if value==0
|
||||
|
@ -18,14 +18,14 @@ require 'one_helper'
|
||||
|
||||
class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
RESOURCE = "VM"
|
||||
|
||||
|
||||
def create_resource(template_file, options)
|
||||
template=File.read(template_file)
|
||||
super(template, options)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::VirtualMachine.new_with_id(id, @client)
|
||||
@ -34,15 +34,15 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
OpenNebula::VirtualMachine.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::VirtualMachinePool.new(@client, user_flag)
|
||||
end
|
||||
|
||||
|
||||
def format_resource(vm)
|
||||
str_h1="%-80s"
|
||||
str="%-20s: %-20s"
|
||||
|
||||
|
||||
CLIHelper.print_header(str_h1 % ["VIRTUAL MACHINE #{vm['ID']} INFORMATION"])
|
||||
puts str % ["ID", vm.id.to_s]
|
||||
puts str % ["NAME", vm.name]
|
||||
@ -67,7 +67,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
CLIHelper.print_header(str_h1 % ["VIRTUAL MACHINE TEMPLATE"],false)
|
||||
puts vm.template_str
|
||||
end
|
||||
|
||||
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil, @translation_hash) do
|
||||
column :ID, "ONE identifier for Virtual Machine", :size=>4 do |d,e|
|
||||
@ -81,34 +81,34 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
column :USER, "Username of the Virtual Machine owner", :left, :size=>8 do |d,e|
|
||||
OpenNebulaHelper.uid_to_str(d["UID"],e)
|
||||
end
|
||||
|
||||
|
||||
column :GROUP, "Group of the Virtual Machine", :left, :size=>8 do |d,e|
|
||||
OpenNebulaHelper.gid_to_str(d["GID"],e)
|
||||
end
|
||||
|
||||
|
||||
column :STAT, "Actual status", :size=>4 do |d,e|
|
||||
d.status
|
||||
end
|
||||
|
||||
|
||||
column :CPU, "CPU percentage used by the VM", :size=>3 do |d,e|
|
||||
d["CPU"]
|
||||
end
|
||||
|
||||
|
||||
column :MEM, "Memory used by the VM", :size=>7 do |d,e|
|
||||
d["MEMORY"]
|
||||
end
|
||||
|
||||
|
||||
column :HOSTNAME, "Host where the VM is running", :size=>15 do |d,e|
|
||||
d["HISTORY/HOSTNAME"]
|
||||
end
|
||||
|
||||
|
||||
column :TIME, "Time since the VM was submitted", :size=>11 do |d,e|
|
||||
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]
|
||||
end
|
||||
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :STAT, :CPU, :MEM, :HOSTNAME, :TIME
|
||||
end
|
||||
|
||||
|
@ -18,14 +18,14 @@ require 'one_helper'
|
||||
|
||||
class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
RESOURCE = "VNET"
|
||||
|
||||
|
||||
def create_resource(template_file, options)
|
||||
template=File.read(template_file)
|
||||
super(template, options)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::VirtualNetwork.new_with_id(id, @client)
|
||||
@ -34,15 +34,15 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
OpenNebula::VirtualNetwork.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::VirtualNetworkPool.new(@client, user_flag)
|
||||
end
|
||||
|
||||
|
||||
def format_resource(vn)
|
||||
str_h1="%-80s"
|
||||
CLIHelper.print_header(str_h1 % ["VIRTUAL NETWORK #{vn.id.to_s} INFORMATION"])
|
||||
|
||||
|
||||
str="%-10s: %-20s"
|
||||
puts str % ["ID: ", vn.id.to_s]
|
||||
puts str % ["UID: ", vn["UID"]]
|
||||
@ -60,7 +60,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
puts leases_str
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def format_pool(pool, options)
|
||||
st=CLIHelper::ShowTable.new(nil, @translation_hash) do
|
||||
column :ID, "ONE identifier for Virtual Network", :size=>4 do |d,e|
|
||||
@ -74,37 +74,37 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
column :USER, "Username of the Virtual Network owner", :left, :size=>8 do |d,e|
|
||||
OpenNebulaHelper.uid_to_str(d["UID"],e)
|
||||
end
|
||||
|
||||
|
||||
column :GROUP, "Group of the Virtual Network", :left, :size=>8 do |d,e|
|
||||
OpenNebulaHelper.gid_to_str(d["GID"],e)
|
||||
end
|
||||
|
||||
|
||||
column :TYPE, "Type of Virtual Network", :size=>6 do |d,e|
|
||||
OneVNetHelper.type_to_str(d["TYPE"])
|
||||
end
|
||||
|
||||
|
||||
column :SIZE, "Size of the Virtual Network", :size=>6 do |d,e|
|
||||
d["SIZE"]
|
||||
end
|
||||
|
||||
|
||||
column :BRIDGE, "Bridge associated to the Virtual Network", :size=>6 do |d,e|
|
||||
d["BRIDGE"]
|
||||
end
|
||||
|
||||
|
||||
column :PUBLIC, "Whether the Virtual Network is public or not", :size=>1 do |d,e|
|
||||
OpenNebulaHelper.public_to_str(d['PUBLIC'])
|
||||
end
|
||||
|
||||
|
||||
column :LEASES, "Number of this Virtual Network's given leases", :size=>7 do |d,e|
|
||||
d["TOTAL_LEASES"]
|
||||
end
|
||||
|
||||
|
||||
default :ID, :USER, :GROUP, :NAME, :TYPE, :BRIDGE, :PUBLIC, :LEASES
|
||||
end
|
||||
|
||||
st.show(pool, options)
|
||||
end
|
||||
|
||||
|
||||
# TBD move this method to VirtualNetwork.rb (OCA)
|
||||
def self.type_to_str(type)
|
||||
if type=="0"
|
||||
|
@ -32,56 +32,56 @@ require 'one_helper/onevnet_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "onevnet COMMAND [args..] [options..]"
|
||||
|
||||
|
||||
helper = OneVNetHelper.new
|
||||
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS
|
||||
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
oneid_desc='OpenNebula Virtual Network name or id'
|
||||
set :format, :vnetid, oneid_desc do |arg|
|
||||
helper.to_id(arg)
|
||||
set :format, :vnetid, oneid_desc do |arg|
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
|
||||
onelistid_desc='Comma-separated list of OpenNebula Virtual Network names or ids'
|
||||
set :format, :vnetid_list, onelistid_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
set :format, :vnetid_list, onelistid_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
|
||||
filterflag_desc=<<-EOT
|
||||
a, all --> all the known Virtual Networks
|
||||
m, mine --> the Virtual Networks belonging to the user in ONE_AUTH
|
||||
g, group --> 'mine' plus the Virtual Networks belonging to the groups
|
||||
the user is member of
|
||||
uid --> Virtual Networks of the user identified by this uid
|
||||
user --> Virtual Networks of the user identified by the username
|
||||
a, all all the known Virtual Networks
|
||||
m, mine the Virtual Networks belonging to the user in ONE_AUTH
|
||||
g, group 'mine' plus the Virtual Networks belonging to the groups
|
||||
the user is member of
|
||||
uid Virtual Networks of the user identified by this uid
|
||||
user Virtual Networks of the user identified by the username
|
||||
EOT
|
||||
set :format, :filterflag, filterflag_desc do |arg|
|
||||
helper.filterflag_to_i(arg)
|
||||
set :format, :filterflag, filterflag_desc do |arg|
|
||||
helper.filterflag_to_i(arg)
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Commands
|
||||
########################################################################
|
||||
command :create, 'Create a new Virtual Network', :file do
|
||||
helper.create_resource(args.shift, options)
|
||||
end
|
||||
|
||||
command :show, 'Gets info from a Virtual Network', :oneid,
|
||||
|
||||
command :show, 'Gets info from a Virtual Network', :oneid,
|
||||
:options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args.shift,options)
|
||||
end
|
||||
|
||||
command :list, 'Lists Virtual Networks in the pool', [:filterflag, nil],
|
||||
|
||||
command :list, 'Lists Virtual Networks in the pool', [:filterflag, nil],
|
||||
:options=>CLIHelper::OPTIONS<<OpenNebulaHelper::XML do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
|
||||
command :publish, 'Publishes a Virtual Network', [:range,:vnetid_list] do
|
||||
helper.perform_actions(args[0],nil,options,"published") do |vn|
|
||||
vn.publish
|
||||
|
Loading…
x
Reference in New Issue
Block a user