From 5071e8ae6a3b1570437127d894745d7586374c14 Mon Sep 17 00:00:00 2001 From: ningyu Date: Mon, 19 Nov 2018 20:56:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0cloudmon=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=92=8Cclimc=20underutilizedinstances-list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/underutilizedinstances.go | 34 +++++++++++++++++++ pkg/mcclient/modules/managers.go | 9 +++++ .../modules/mod_underutilizedinstances.go | 13 +++++++ 3 files changed, 56 insertions(+) create mode 100644 cmd/climc/shell/underutilizedinstances.go create mode 100644 pkg/mcclient/modules/mod_underutilizedinstances.go diff --git a/cmd/climc/shell/underutilizedinstances.go b/cmd/climc/shell/underutilizedinstances.go new file mode 100644 index 0000000000..a8bebb1e87 --- /dev/null +++ b/cmd/climc/shell/underutilizedinstances.go @@ -0,0 +1,34 @@ +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 UnderutilizedInstancesListOptions struct { + options.BaseListOptions + } + R(&UnderutilizedInstancesListOptions{}, "underutilizedinstances-list", "List underutilized instances", func(s *mcclient.ClientSession, args *UnderutilizedInstancesListOptions) error { + var params *jsonutils.JSONDict + { + var err error + params, err = args.BaseListOptions.Params() + if err != nil { + return err + + } + } + result, err := modules.UnderutilizedInstances.List(s, params) + if err != nil { + return err + } + + printList(result, modules.UnderutilizedInstances.GetColumns(s)) + return nil + }) + +} diff --git a/pkg/mcclient/modules/managers.go b/pkg/mcclient/modules/managers.go index cf51952d23..6172530fc7 100644 --- a/pkg/mcclient/modules/managers.go +++ b/pkg/mcclient/modules/managers.go @@ -25,6 +25,15 @@ func NewMonitorManager(keyword, keywordPlural string, columns, adminColumns []st Keyword: keyword, KeywordPlural: keywordPlural} } +func NewCloudmonManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { + return ResourceManager{ + BaseManager: BaseManager{columns: columns, + adminColumns: adminColumns, + version: "v1", + serviceType: "cloudmon"}, + Keyword: keyword, KeywordPlural: keywordPlural} +} + func NewNotifyManager(keyword, keywordPlural string, columns, adminColumns []string) ResourceManager { return ResourceManager{ BaseManager: BaseManager{columns: columns, diff --git a/pkg/mcclient/modules/mod_underutilizedinstances.go b/pkg/mcclient/modules/mod_underutilizedinstances.go new file mode 100644 index 0000000000..8c0e6af42f --- /dev/null +++ b/pkg/mcclient/modules/mod_underutilizedinstances.go @@ -0,0 +1,13 @@ +package modules + +var ( + UnderutilizedInstances ResourceManager +) + +func init() { + UnderutilizedInstances = NewCloudmonManager("underutilizedinstance", "underutilizedinstances", + []string{"id", "vm_id", "vm_name", "time", "advices", "vm_cpu", "vm_disk", "vm_memory", "vm_provider"}, + []string{}) + + register(&UnderutilizedInstances) +} From d1680ade9512ee37e6e8d4a0624ed9f813a3b7ac Mon Sep 17 00:00:00 2001 From: ningyu Date: Mon, 19 Nov 2018 21:11:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=9C=AA=E5=85=85?= =?UTF-8?q?=E5=88=86=E5=88=A9=E7=94=A8=E7=9A=84=E5=AE=9E=E4=BE=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8API=E7=9A=84climc=E5=91=BD=E5=90=8D=EF=BC=8C=E7=9B=AE?= =?UTF-8?q?=E7=9A=84=E6=98=AF=E9=81=BF=E5=85=8D=E8=BF=87=E9=95=BF=E4=B8=8D?= =?UTF-8?q?=E6=98=93=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/underutilizedinstances.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/climc/shell/underutilizedinstances.go b/cmd/climc/shell/underutilizedinstances.go index a8bebb1e87..84fd17ed08 100644 --- a/cmd/climc/shell/underutilizedinstances.go +++ b/cmd/climc/shell/underutilizedinstances.go @@ -12,7 +12,7 @@ func init() { type UnderutilizedInstancesListOptions struct { options.BaseListOptions } - R(&UnderutilizedInstancesListOptions{}, "underutilizedinstances-list", "List underutilized instances", func(s *mcclient.ClientSession, args *UnderutilizedInstancesListOptions) error { + R(&UnderutilizedInstancesListOptions{}, "underutilized-instances-list", "List underutilized instances", func(s *mcclient.ClientSession, args *UnderutilizedInstancesListOptions) error { var params *jsonutils.JSONDict { var err error