mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 04:12:37 +09:00
Feature #3264: Command oneshowback calculate
This commit is contained in:
1 parent
69ed82f022
commit
3b1ed0c48c
3 files changed
+62
-47
No files matched your search
@@ -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|
|
||||
|
||||
+40
-4
@@ -33,7 +33,10 @@ require 'one_helper/oneacct_helper'
|
||||
require 'json'
|
||||
|
||||
cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneshowback` [<options>]"
|
||||
|
||||
@formats = Hash.new
|
||||
|
||||
usage "`oneshowback` <command> [<options>]"
|
||||
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
|
||||
@@ -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')
|
||||
|
||||
Reference in new issue
Block a user