From 5f30f4feb5760cf4c0d168d9a2a6fa8981b53f05 Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 23 May 2019 21:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0worker-list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/workers.go | 33 ++++++++++++++++++++++++ pkg/mcclient/modules/mod_workers.go | 40 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 cmd/climc/shell/workers.go create mode 100644 pkg/mcclient/modules/mod_workers.go diff --git a/cmd/climc/shell/workers.go b/cmd/climc/shell/workers.go new file mode 100644 index 0000000000..ec5dbbc81d --- /dev/null +++ b/cmd/climc/shell/workers.go @@ -0,0 +1,33 @@ +// Copyright 2019 Yunion +// +// 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. + +package shell + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +func init() { + type WorkerListOptions struct { + } + R(&WorkerListOptions{}, "worker-list", "List workers", func(s *mcclient.ClientSession, args *WorkerListOptions) error { + result, err := modules.Workers.List(s, nil) + if err != nil { + return err + } + printList(result, modules.Workers.GetColumns(s)) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_workers.go b/pkg/mcclient/modules/mod_workers.go new file mode 100644 index 0000000000..89cb8ee9d7 --- /dev/null +++ b/pkg/mcclient/modules/mod_workers.go @@ -0,0 +1,40 @@ +// Copyright 2019 Yunion +// +// 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. + +package modules + +import ( + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" +) + +type WorkerManager struct { + ResourceManager +} + +var ( + Workers WorkerManager +) + +func (this *WorkerManager) List(s *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error) { + return this._list(s, this.KeywordPlural, this.Keyword) +} + +func init() { + Workers = WorkerManager{NewComputeManager("workers", "worker_stats", + []string{"name", "queue_cnt", "active_worker_cnt", "backlog", "detach_worker_cnt", "max_worker_cnt"}, + []string{})} + + registerCompute(&Workers) +}