From 21d4fab7e173109569a2a3adbae3afefd550f8f7 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 7 Jun 2011 17:01:20 +0200 Subject: [PATCH] feature #661: Update onevnet command --- src/cli/onevnet | 378 ++++++++---------------------------------------- 1 file changed, 63 insertions(+), 315 deletions(-) diff --git a/src/cli/onevnet b/src/cli/onevnet index 48682d624b..d0d81dc8b2 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -25,342 +25,90 @@ else end $: << RUBY_LIB_LOCATION +$: << RUBY_LIB_LOCATION+"/cli" +require 'command_parser' +require 'one_helper/onevnet_helper' -require 'OpenNebula' -require 'client_utilities' -require 'command_parse' - - -ShowTableVN={ - :id => { - :name => "ID", - :desc => "ONE identifier for virtual network", - :size => 4, - :proc => lambda {|d,e| d.id } - }, - :name => { - :name => "NAME", - :desc => "name of the virtual network", - :size => 15, - :left => true, - :proc => lambda {|d,e| d.name } - }, - :user => { - :name => "USER", - :desc => "Username of the virtual network owner", - :size => 8, - :left => true, - :proc => lambda {|d,e| d["USERNAME"] } - }, - :type => { - :name => "TYPE", - :desc => "NType of virtual network", - :size => 6, - :proc => lambda {|d,e| - if(d["TYPE"] == "0") - return "Ranged" - else - if (d["TYPE"] == "1") - return "Fixed" - end - end - } - }, - :size => { - :name => "SIZE", - :desc => "Number of hosts (free + used) in the virtual network", - :size => 6, - :proc => lambda {|d,e| d["SIZE"] } - }, - :bridge => { - :name => "BRIDGE", - :desc => "Bridge associated to the virtual network", - :size => 6, - :proc => lambda {|d,e| d["BRIDGE"] } - }, - :public => { - :name => "PUBLIC", - :desc => "Whether the Image is public or not", - :size => 1, - :proc => lambda {|d,e| if d["PUBLIC"].to_i == 1 then "Y" else "N" end} - }, - :totalleases => { - :name => "#LEASES", - :desc => "Number of this virtual network's given leases", - :size => 7, - :proc => lambda {|d,e| d["TOTAL_LEASES"] } - }, - - :default => [:id, :user, :name, :type, :bridge, :public, :totalleases] -} - -class VNShow - def initialize(filter_flag="-2") - @vnpool=OpenNebula::VirtualNetworkPool.new(get_one_client, - filter_flag.to_i) - @table=ShowTable.new(ShowTableVN) +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) end - def header_vn_small - scr_bold - scr_underline - print @table.header_str - scr_restore - puts "" + 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) end - def list_short(options=nil) - res=@vnpool.info - if options - @table.columns=options[:columns] if options[:columns] - end - - if OpenNebula.is_error?(res) - result=res - else - result=res - header_vn_small - if options[:filter_flag] - vns=@vnpool.select{|element| - element["USERNAME"]==options[:filter_flag] - } - else - vns=@vnpool - end - puts @table.data_str(vns, options) - result - end - end -end - -class OneVNParse < CommandParse - - COMMANDS_HELP=<<-EOT - -Description: - -This command enables the user to manage virtual networks in the OpenNebula -server. It provides functionality to create, get information and delete a -particular network or to list available and used IP's. - - -Commands: - -* create (Creates a new virtual network) - onevnet create