From e15bcc9d371e828097b0be29de12ec35dbda5a09 Mon Sep 17 00:00:00 2001 From: zhengjiajie Date: Sat, 29 Sep 2018 19:20:09 +0800 Subject: [PATCH] add meter dashboard data api --- cmd/climc/shell/account_balances.go | 59 ++++++++++++++++++++ pkg/mcclient/modules/mod_account_balances.go | 13 +++++ 2 files changed, 72 insertions(+) create mode 100644 cmd/climc/shell/account_balances.go create mode 100644 pkg/mcclient/modules/mod_account_balances.go diff --git a/cmd/climc/shell/account_balances.go b/cmd/climc/shell/account_balances.go new file mode 100644 index 0000000000..4346049bcb --- /dev/null +++ b/cmd/climc/shell/account_balances.go @@ -0,0 +1,59 @@ +package shell + +import ( + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +func init() { + + type AccountBalancesListOptions struct { + options.BaseListOptions + StatMonth string `help:"stat_month of the query"` + StartDate string `help:"start_date of the query"` + EndDate string `help:"end_date of the query"` + QueryType string `help:"query_type of the query"` + Platform string `help:"platform of the query"` + ProjectId string `help:"project_id of the query"` + } + R(&AccountBalancesListOptions{}, "accountbalances-list", "List all account balances ", func(s *mcclient.ClientSession, args *AccountBalancesListOptions) error { + var params *jsonutils.JSONDict + { + var err error + params, err = args.BaseListOptions.Params() + if err != nil { + return err + + } + } + + if len(args.StatMonth) > 0 { + params.Add(jsonutils.NewString(args.StatMonth), "stat_month") + } + if len(args.StartDate) > 0 { + params.Add(jsonutils.NewString(args.StartDate), "start_date") + } + if len(args.EndDate) > 0 { + params.Add(jsonutils.NewString(args.EndDate), "end_date") + } + if len(args.QueryType) > 0 { + params.Add(jsonutils.NewString(args.QueryType), "query_type") + } + if len(args.Platform) > 0 { + params.Add(jsonutils.NewString(args.Platform), "platform") + } + if len(args.ProjectId) > 0 { + params.Add(jsonutils.NewString(args.ProjectId), "project_id") + } + + result, err := modules.AccountBalances.List(s, params) + if err != nil { + return err + } + + printList(result, modules.AccountBalances.GetColumns(s)) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_account_balances.go b/pkg/mcclient/modules/mod_account_balances.go new file mode 100644 index 0000000000..56415212af --- /dev/null +++ b/pkg/mcclient/modules/mod_account_balances.go @@ -0,0 +1,13 @@ +package modules + +var ( + AccountBalances ResourceManager +) + +func init() { + AccountBalances = NewMeterManager("account_balance", "account_balances", + []string{"account_type", "available_amount", "current_outcome", "current_income"}, + []string{}, + ) + register(&AccountBalances) +}