From 3b1ed0c48cb5cd27d176ff459c5abfd03c05a6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 7 Nov 2014 13:03:50 +0100 Subject: [PATCH] Feature #3264: Command oneshowback calculate --- src/cli/one_helper/oneacct_helper.rb | 28 ++++++++++++++---- src/cli/oneshowback | 44 +++++++++++++++++++++++++--- src/cli/onevm | 37 ----------------------- 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/cli/one_helper/oneacct_helper.rb b/src/cli/one_helper/oneacct_helper.rb index 4ded640687..86a5befab6 100644 --- a/src/cli/one_helper/oneacct_helper.rb +++ b/src/cli/one_helper/oneacct_helper.rb @@ -18,19 +18,35 @@ require 'one_helper' require 'optparse/time' class AcctHelper < OpenNebulaHelper::OneHelper - START_TIME = { + START_TIME_ACCT = { :name => "start_time", :short => "-s TIME", :large => "--start TIME" , - :description => "Start date and time to take into account", + :description => "First day of the data to retrieve", :format => Time } - END_TIME = { + END_TIME_ACCT = { :name => "end_time", :short => "-e TIME", :large => "--end TIME" , - :description => "End date and time", + :description => "Last day of the data to retrieve", + :format => Time + } + + START_TIME_SHOWBACK = { + :name => "start_time", + :short => "-s TIME", + :large => "--start TIME" , + :description => "First month of the data", + :format => Time + } + + END_TIME_SHOWBACK = { + :name => "end_time", + :short => "-e TIME", + :large => "--end TIME" , + :description => "Last month of the data", :format => Time } @@ -96,8 +112,8 @@ class AcctHelper < OpenNebulaHelper::OneHelper :description => "Split the output in a table for each VM" } - ACCT_OPTIONS = [START_TIME, END_TIME, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT] - SHOWBACK_OPTIONS = [START_TIME, END_TIME, USERFILTER, GROUP, XML, JSON] + ACCT_OPTIONS = [START_TIME_ACCT, END_TIME_ACCT, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT] + SHOWBACK_OPTIONS = [START_TIME_SHOWBACK, END_TIME_SHOWBACK, USERFILTER, GROUP, XML, JSON] ACCT_TABLE = CLIHelper::ShowTable.new("oneacct.yaml", nil) do column :UID, "User ID", :size=>4 do |d| diff --git a/src/cli/oneshowback b/src/cli/oneshowback index 4b8100ab46..874dfb67a6 100755 --- a/src/cli/oneshowback +++ b/src/cli/oneshowback @@ -33,7 +33,10 @@ require 'one_helper/oneacct_helper' require 'json' cmd = CommandParser::CmdParser.new(ARGV) do - usage "`oneshowback` []" + + @formats = Hash.new + + usage "`oneshowback` []" description "" version OpenNebulaHelper::ONE_VERSION @@ -43,11 +46,11 @@ cmd = CommandParser::CmdParser.new(ARGV) do helper.set_client(options) end - option AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS + + command :list, "Returns the showback records", :options => + AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS + [OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] + - OpenNebulaHelper::CLIENT_OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS do - main do if options[:describe] AcctHelper::SHOWBACK_TABLE.describe_columns exit(0) @@ -139,4 +142,37 @@ cmd = CommandParser::CmdParser.new(ARGV) do exit_code 0 end end + + command :"calculate", "Calculates the showback records", :options => + [AcctHelper::START_TIME_SHOWBACK, AcctHelper::START_TIME_SHOWBACK] do + + + start_month = -1 + start_year = -1 + + if (options[:start_time]) + start_month = options[:start_time].month + start_year = options[:start_time].year + end + + end_month = -1 + end_year = -1 + + if (options[:end_time]) + end_month = options[:end_time].month + end_year = options[:end_time].year + end + + rc = OpenNebula::VirtualMachinePool.new(helper.client). + calculate_showback(start_month, start_year, end_month, end_year) + + if OpenNebula.is_error?(rc) + warn rc.message + exit -1 + else + puts rc + exit_code 0 + end + + end end \ No newline at end of file diff --git a/src/cli/onevm b/src/cli/onevm index 9c0dc92e38..b0136bec3e 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -850,43 +850,6 @@ cmd=CommandParser::CmdParser.new(ARGV) do :format => Time } - calculate_showback_desc = <<-EOT.unindent - Development command to calculate showback data - EOT - - command :"calculate-showback", calculate_showback_desc, :options => - [START_TIME, END_TIME] do - - start_month = -1 - start_year = -1 - - if (options[:start_time]) - start_month = options[:start_time].month - start_year = options[:start_time].year - end - - end_month = -1 - end_year = -1 - - if (options[:end_time]) - end_month = options[:end_time].month - end_year = options[:end_time].year - end - - - rc = OpenNebula::VirtualMachinePool.new(helper.client). - calculate_showback(start_month, start_year, end_month, end_year) - - if OpenNebula.is_error?(rc) - warn rc.message - exit -1 - else - puts rc - exit 0 - end - - end - # Deprecated commands deprecated_command(:attachdisk, 'disk-attach')