mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-24 02:03:52 +03:00
Feature #3264: Create new command oneshowback
This commit is contained in:
parent
a5aa72359a
commit
69ed82f022
@ -591,6 +591,7 @@ BIN_FILES="src/nebula/oned \
|
||||
src/scheduler/src/sched/mm_sched \
|
||||
src/cli/onevm \
|
||||
src/cli/oneacct \
|
||||
src/cli/oneshowback \
|
||||
src/cli/onehost \
|
||||
src/cli/onevnet \
|
||||
src/cli/oneuser \
|
||||
@ -1458,7 +1459,8 @@ CLI_BIN_FILES="src/cli/onevm \
|
||||
src/cli/onezone \
|
||||
src/cli/oneflow \
|
||||
src/cli/oneflow-template \
|
||||
src/cli/oneacct"
|
||||
src/cli/oneacct \
|
||||
src/cli/oneshowback.rb"
|
||||
|
||||
CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
|
||||
src/cli/etc/onehost.yaml \
|
||||
@ -1471,7 +1473,8 @@ CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
|
||||
src/cli/etc/onedatastore.yaml \
|
||||
src/cli/etc/onecluster.yaml \
|
||||
src/cli/etc/onezone.yaml \
|
||||
src/cli/etc/oneacct.yaml"
|
||||
src/cli/etc/oneacct.yaml \
|
||||
src/cli/etc/oneshowback.yaml"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Sunstone files
|
||||
@ -1802,6 +1805,7 @@ ONEFLOW_LIB_MODELS_FILES="src/flow/lib/models/role.rb \
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
MAN_FILES="share/man/oneacct.1.gz \
|
||||
share/man/oneshowback.1.gz \
|
||||
share/man/oneacl.1.gz \
|
||||
share/man/onehost.1.gz \
|
||||
share/man/oneimage.1.gz \
|
||||
|
@ -48,6 +48,7 @@ env.Man('econe-terminate-instances')
|
||||
env.Man('econe-upload')
|
||||
|
||||
env.Man('oneacct')
|
||||
env.Man('oneshowback')
|
||||
env.Man('oneacl')
|
||||
env.Man('onecluster')
|
||||
env.Man('onedatastore')
|
||||
|
50
src/cli/etc/oneshowback.yaml
Normal file
50
src/cli/etc/oneshowback.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
:UID:
|
||||
:desc: User ID
|
||||
:size: 4
|
||||
|
||||
:USER_NAME:
|
||||
:desc: User name
|
||||
:size: 12
|
||||
|
||||
:GID:
|
||||
:desc: Group ID
|
||||
:size: 4
|
||||
|
||||
:GROUP_NAME:
|
||||
:desc: Group name
|
||||
:size: 12
|
||||
|
||||
:VM_ID:
|
||||
:desc: Virtual Machine ID
|
||||
:size: 6
|
||||
|
||||
:VM_NAME:
|
||||
:desc: Virtual Machine name
|
||||
:size: 12
|
||||
|
||||
:MONTH:
|
||||
:desc: Month
|
||||
:size: 5
|
||||
|
||||
:YEAR:
|
||||
:desc: Year
|
||||
:size: 5
|
||||
|
||||
:HOURS:
|
||||
:desc: Hours
|
||||
:size: 6
|
||||
|
||||
:COST:
|
||||
:desc: Cost
|
||||
:size: 15
|
||||
|
||||
:default:
|
||||
- :USER_NAME
|
||||
- :GROUP_NAME
|
||||
- :VM_ID
|
||||
- :VM_NAME
|
||||
- :MONTH
|
||||
- :YEAR
|
||||
- :HOURS
|
||||
- :COST
|
@ -153,8 +153,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
|
||||
default :VID, :HOSTNAME, :ACTION, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX
|
||||
end
|
||||
|
||||
# TODO: oneacct.yaml
|
||||
SHOWBACK_TABLE = CLIHelper::ShowTable.new("nofile.yaml", nil) do
|
||||
SHOWBACK_TABLE = CLIHelper::ShowTable.new("oneshowback.yaml", nil) do
|
||||
column :UID, "User ID", :size=>4 do |d|
|
||||
d["UID"]
|
||||
end
|
||||
|
103
src/cli/oneacct
103
src/cli/oneacct
@ -43,11 +43,11 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
command :acct, "Returns the accounting records", :options =>
|
||||
AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS +
|
||||
option AcctHelper::ACCT_OPTIONS + CommandParser::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS do
|
||||
OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
main do
|
||||
if options[:describe]
|
||||
AcctHelper::ACCT_TABLE.describe_columns
|
||||
exit(0)
|
||||
@ -140,101 +140,4 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
exit_code 0
|
||||
end
|
||||
end
|
||||
|
||||
command :showback, "Returns the showback records", :options =>
|
||||
AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS do
|
||||
|
||||
if options[:describe]
|
||||
AcctHelper::SHOWBACK_TABLE.describe_columns
|
||||
exit(0)
|
||||
end
|
||||
|
||||
filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
|
||||
|
||||
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
|
||||
|
||||
common_opts = {
|
||||
:start_month => start_month,
|
||||
:start_year => start_year,
|
||||
:end_month => end_month,
|
||||
:end_year => end_year,
|
||||
:group => options[:group],
|
||||
:xpath => options[:xpath]
|
||||
}
|
||||
|
||||
pool = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
|
||||
if options[:json] || options[:xml]
|
||||
xml_str = pool.showback_xml(filter_flag, common_opts)
|
||||
if OpenNebula.is_error?(xml_str)
|
||||
puts xml_str.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
if options[:json]
|
||||
xmldoc = XMLElement.new
|
||||
xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
|
||||
|
||||
puts JSON.pretty_generate(xmldoc.to_hash)
|
||||
elsif options[:xml]
|
||||
puts xml_str
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
else
|
||||
|
||||
order_by = Hash.new
|
||||
if !options[:csv]
|
||||
order_by[:order_by_1] = 'YEAR'
|
||||
order_by[:order_by_2] = 'MONTH'
|
||||
end
|
||||
|
||||
data_hash = pool.showback(filter_flag,
|
||||
common_opts.merge(order_by))
|
||||
if OpenNebula.is_error?(data_hash)
|
||||
puts data_hash.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
if options[:csv]
|
||||
a = Array.new
|
||||
|
||||
if data_hash['SHOWBACK_RECORDS']
|
||||
a = data_hash['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
end
|
||||
|
||||
AcctHelper::SHOWBACK_TABLE.show(a, options)
|
||||
exit(0)
|
||||
end
|
||||
|
||||
data_hash.each { |year, value|
|
||||
value.each { |month, showback_array|
|
||||
AcctHelper.print_month_header(year, month)
|
||||
|
||||
array = showback_array['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
AcctHelper::SHOWBACK_TABLE.show(array, options)
|
||||
puts
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
end
|
||||
end
|
142
src/cli/oneshowback
Executable file
142
src/cli/oneshowback
Executable file
@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/oneacct_helper'
|
||||
|
||||
require 'json'
|
||||
|
||||
cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneshowback` [<options>]"
|
||||
description ""
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper=OpenNebulaHelper::OneHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
option AcctHelper::SHOWBACK_OPTIONS + CommandParser::OPTIONS +
|
||||
[OpenNebulaHelper::DESCRIBE, CLIHelper::LIST, CLIHelper::CSV_OPT] +
|
||||
OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
main do
|
||||
if options[:describe]
|
||||
AcctHelper::SHOWBACK_TABLE.describe_columns
|
||||
exit(0)
|
||||
end
|
||||
|
||||
filter_flag = (options[:userfilter] || VirtualMachinePool::INFO_ALL)
|
||||
|
||||
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
|
||||
|
||||
common_opts = {
|
||||
:start_month => start_month,
|
||||
:start_year => start_year,
|
||||
:end_month => end_month,
|
||||
:end_year => end_year,
|
||||
:group => options[:group],
|
||||
:xpath => options[:xpath]
|
||||
}
|
||||
|
||||
pool = OpenNebula::VirtualMachinePool.new(helper.client)
|
||||
|
||||
if options[:json] || options[:xml]
|
||||
xml_str = pool.showback_xml(filter_flag, common_opts)
|
||||
if OpenNebula.is_error?(xml_str)
|
||||
puts xml_str.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
if options[:json]
|
||||
xmldoc = XMLElement.new
|
||||
xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
|
||||
|
||||
puts JSON.pretty_generate(xmldoc.to_hash)
|
||||
elsif options[:xml]
|
||||
puts xml_str
|
||||
end
|
||||
|
||||
exit_code 0
|
||||
else
|
||||
|
||||
order_by = Hash.new
|
||||
if !options[:csv]
|
||||
order_by[:order_by_1] = 'YEAR'
|
||||
order_by[:order_by_2] = 'MONTH'
|
||||
end
|
||||
|
||||
data_hash = pool.showback(filter_flag,
|
||||
common_opts.merge(order_by))
|
||||
if OpenNebula.is_error?(data_hash)
|
||||
puts data_hash.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
if options[:csv]
|
||||
a = Array.new
|
||||
|
||||
if data_hash['SHOWBACK_RECORDS']
|
||||
a = data_hash['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
end
|
||||
|
||||
AcctHelper::SHOWBACK_TABLE.show(a, options)
|
||||
exit(0)
|
||||
end
|
||||
|
||||
data_hash.each { |year, value|
|
||||
value.each { |month, showback_array|
|
||||
AcctHelper.print_month_header(year, month)
|
||||
|
||||
array = showback_array['SHOWBACK_RECORDS']['SHOWBACK']
|
||||
AcctHelper::SHOWBACK_TABLE.show(array, options)
|
||||
puts
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit_code 0
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user