From 71affd88f4696a772a04107660bb7e47608c5d08 Mon Sep 17 00:00:00 2001 From: zhengjiajie Date: Fri, 14 Sep 2018 12:17:17 +0800 Subject: [PATCH 1/4] zhengjiajie submit resource result export --- cmd/climc/shell/res_results.go | 94 +++++++++++++++++++++++++ pkg/mcclient/modules/mod_res_results.go | 13 ++++ 2 files changed, 107 insertions(+) create mode 100644 cmd/climc/shell/res_results.go create mode 100644 pkg/mcclient/modules/mod_res_results.go diff --git a/cmd/climc/shell/res_results.go b/cmd/climc/shell/res_results.go new file mode 100644 index 0000000000..6330f612a4 --- /dev/null +++ b/cmd/climc/shell/res_results.go @@ -0,0 +1,94 @@ +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 ResResultsListOptions 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"` + ProjectId string `"help":"project_id of the query"` + } + R(&ResResultsListOptions{}, "resresult-list", "List all res results ", func(s *mcclient.ClientSession, args *ResResultsListOptions) 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.ProjectId) > 0 { + params.Add(jsonutils.NewString(args.ProjectId), "project_id") + } + + result, err := modules.ResResults.List(s, params) + if err != nil { + return err + } + + printList(result, modules.ResResults.GetColumns(s)) + return nil + }) + + + type ResResultUpdateOptions struct { + ID string `help:"ID of the query"` + StatMonth string `"help":"stat_month of the query"` + StartDate string `"help":"start_date of the query"` + EndDate string `"help":"end_date of the query"` + ProjectId string `"help":"project_id of the query"` + + ItemKey string `"help":"item_key of the query"` + ItemText string `"help":"item_text of the query"` + } + R(&ResResultUpdateOptions{}, "resresult-export", "Update a resresult export", func(s *mcclient.ClientSession, args *ResResultUpdateOptions) error { + params := jsonutils.NewDict() + 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.ProjectId) > 0 { + params.Add(jsonutils.NewString(args.ProjectId), "project_id") + } + if len(args.ItemKey) > 0 { + params.Add(jsonutils.NewString(args.ItemKey), "item_key") + } + if len(args.ItemText) > 0 { + params.Add(jsonutils.NewString(args.ItemText), "item_text") + } + resResult, err := modules.ResResults.Put(s, args.ID, params) + if err != nil { + return err + } + printObject(resResult) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_res_results.go b/pkg/mcclient/modules/mod_res_results.go new file mode 100644 index 0000000000..a043e79043 --- /dev/null +++ b/pkg/mcclient/modules/mod_res_results.go @@ -0,0 +1,13 @@ +package modules + +var ( + ResResults ResourceManager +) + +func init() { + ResResults = NewMeterManager("res_result", "res_results", + []string{"stat_month", "start_date", "end_date", "filter", "project_id"}, + []string{}, + ) + register(&ResResults) +} From a9965699ca7431fd828a79ab7fe0e4e9ef312f0f Mon Sep 17 00:00:00 2001 From: zhengjiajie Date: Fri, 14 Sep 2018 12:30:27 +0800 Subject: [PATCH 2/4] ftm code --- cmd/climc/shell/res_results.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/climc/shell/res_results.go b/cmd/climc/shell/res_results.go index 6330f612a4..e5402b220c 100644 --- a/cmd/climc/shell/res_results.go +++ b/cmd/climc/shell/res_results.go @@ -31,14 +31,12 @@ func init() { 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.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.ProjectId) > 0 { params.Add(jsonutils.NewString(args.ProjectId), "project_id") } @@ -72,12 +70,12 @@ func init() { 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.ProjectId) > 0 { - params.Add(jsonutils.NewString(args.ProjectId), "project_id") - } + if len(args.EndDate) > 0 { + params.Add(jsonutils.NewString(args.EndDate), "end_date") + } + if len(args.ProjectId) > 0 { + params.Add(jsonutils.NewString(args.ProjectId), "project_id") + } if len(args.ItemKey) > 0 { params.Add(jsonutils.NewString(args.ItemKey), "item_key") } From ef725ad1556cca0dda37967bd277b606017a8a8a Mon Sep 17 00:00:00 2001 From: zhengjiajie Date: Fri, 14 Sep 2018 12:38:34 +0800 Subject: [PATCH 3/4] fmt code --- cmd/climc/shell/res_results.go | 36 ++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/cmd/climc/shell/res_results.go b/cmd/climc/shell/res_results.go index e5402b220c..7ad971e1f9 100644 --- a/cmd/climc/shell/res_results.go +++ b/cmd/climc/shell/res_results.go @@ -8,13 +8,13 @@ import ( ) func init() { - + type ResResultsListOptions 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"` - ProjectId string `"help":"project_id of the query"` + StatMonth string `"help":"stat_month of the query"` + StartDate string `"help":"start_date of the query"` + EndDate string `"help":"end_date of the query"` + ProjectId string `"help":"project_id of the query"` } R(&ResResultsListOptions{}, "resresult-list", "List all res results ", func(s *mcclient.ClientSession, args *ResResultsListOptions) error { var params *jsonutils.JSONDict @@ -27,7 +27,6 @@ func init() { } } - if len(args.StatMonth) > 0 { params.Add(jsonutils.NewString(args.StatMonth), "stat_month") } @@ -50,26 +49,25 @@ func init() { return nil }) - type ResResultUpdateOptions struct { - ID string `help:"ID of the query"` - StatMonth string `"help":"stat_month of the query"` - StartDate string `"help":"start_date of the query"` - EndDate string `"help":"end_date of the query"` - ProjectId string `"help":"project_id of the query"` + ID string `help:"ID of the query"` + StatMonth string `"help":"stat_month of the query"` + StartDate string `"help":"start_date of the query"` + EndDate string `"help":"end_date of the query"` + ProjectId string `"help":"project_id of the query"` - ItemKey string `"help":"item_key of the query"` - ItemText string `"help":"item_text of the query"` + ItemKey string `"help":"item_key of the query"` + ItemText string `"help":"item_text of the query"` } R(&ResResultUpdateOptions{}, "resresult-export", "Update a resresult export", func(s *mcclient.ClientSession, args *ResResultUpdateOptions) error { params := jsonutils.NewDict() if len(args.StatMonth) > 0 { - params.Add(jsonutils.NewString(args.StatMonth), "stat_month") - } + params.Add(jsonutils.NewString(args.StatMonth), "stat_month") + } - if len(args.StartDate) > 0 { - params.Add(jsonutils.NewString(args.StartDate), "start_date") - } + 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") } From 0ff0e22a4c8e71393e04d8ae069743a0d37c7516 Mon Sep 17 00:00:00 2001 From: zhengjiajie Date: Fri, 14 Sep 2018 19:06:30 +0800 Subject: [PATCH 4/4] zhengjiajie modify code --- cmd/climc/shell/res_results.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/climc/shell/res_results.go b/cmd/climc/shell/res_results.go index 7ad971e1f9..c64c29f218 100644 --- a/cmd/climc/shell/res_results.go +++ b/cmd/climc/shell/res_results.go @@ -11,10 +11,10 @@ func init() { type ResResultsListOptions 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"` - ProjectId string `"help":"project_id of the query"` + StatMonth string `help:"stat_month of the query"` + StartDate string `help:"start_date of the query"` + EndDate string `help:"end_date of the query"` + ProjectId string `help:"project_id of the query"` } R(&ResResultsListOptions{}, "resresult-list", "List all res results ", func(s *mcclient.ClientSession, args *ResResultsListOptions) error { var params *jsonutils.JSONDict @@ -51,13 +51,13 @@ func init() { type ResResultUpdateOptions struct { ID string `help:"ID of the query"` - StatMonth string `"help":"stat_month of the query"` - StartDate string `"help":"start_date of the query"` - EndDate string `"help":"end_date of the query"` - ProjectId string `"help":"project_id of the query"` + StatMonth string `help:"stat_month of the query"` + StartDate string `help:"start_date of the query"` + EndDate string `help:"end_date of the query"` + ProjectId string `help:"project_id of the query"` - ItemKey string `"help":"item_key of the query"` - ItemText string `"help":"item_text of the query"` + ItemKey string `help:"item_key of the query"` + ItemText string `help:"item_text of the query"` } R(&ResResultUpdateOptions{}, "resresult-export", "Update a resresult export", func(s *mcclient.ClientSession, args *ResResultUpdateOptions) error { params := jsonutils.NewDict()