mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: cleanup codes
This commit is contained in:
+1
-3
@@ -28,15 +28,13 @@ import (
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/events"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/identity"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/image"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/itsm"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/k8s"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/logger"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/misc"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/monitor"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/notifyv2"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/quota"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/scheduler"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/servicetree"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/suggestion"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/vpcproxy"
|
||||
_ "yunion.io/x/onecloud/cmd/climc/shell/yunionconf"
|
||||
)
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type InstanceListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&InstanceListOptions{}, "instance-list", "List instances", func(s *mcclient.ClientSession, suboptions *InstanceListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = suboptions.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Instances.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Instances.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 使用文件创建部署
|
||||
*/
|
||||
type DeploymentCreateOptions struct {
|
||||
FILE string `help:"The local bpmn filename to Upload"`
|
||||
TenantID string `help:"ID of tenant"`
|
||||
}
|
||||
R(&DeploymentCreateOptions{}, "process-deployment-create", "Create deployment by upload BPMN file", func(s *mcclient.ClientSession, args *DeploymentCreateOptions) error {
|
||||
// TODO
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除指定ID的部署
|
||||
*/
|
||||
type DeploymentDeleteOptions struct {
|
||||
ID string `help:"ID of process deployment"`
|
||||
Cascade bool `help:"Whether to cascade delete process instance, history process instance and jobs" required:"true" choices:"true|false"`
|
||||
}
|
||||
R(&DeploymentDeleteOptions{}, "process-deployment-delete", "Delete process deployment by ID", func(s *mcclient.ClientSession, args *DeploymentDeleteOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Cascade {
|
||||
params.Add(jsonutils.JSONTrue, "cascade")
|
||||
} else {
|
||||
params.Add(jsonutils.JSONFalse, "cascade")
|
||||
}
|
||||
result, e := modules.ProcessDeployments.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出部署
|
||||
*/
|
||||
type DeploymentListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&DeploymentListOptions{}, "process-deployment-list", "List process deployment", func(s *mcclient.ClientSession, args *DeploymentListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.ProcessDeployments.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.ProcessDeployments.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的部署
|
||||
*/
|
||||
type DeploymentShowOptions struct {
|
||||
ID string `help:"ID of the process deployment"`
|
||||
}
|
||||
R(&DeploymentShowOptions{}, "process-deployment-show", "Show deployment", func(s *mcclient.ClientSession, args *DeploymentShowOptions) error {
|
||||
result, err := modules.ProcessDeployments.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ExtraProcessInstanceListOptions struct {
|
||||
ID string `help:"ID of ExtraProcessInstance"`
|
||||
UserId string `help:"ID of user"`
|
||||
}
|
||||
R(&ExtraProcessInstanceListOptions{}, "itsm_extra_process_instance_list", "extra process instance list",
|
||||
func(s *mcclient.ClientSession, args *ExtraProcessInstanceListOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.ID) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ID), "id")
|
||||
}
|
||||
if len(args.UserId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.UserId), "user_id")
|
||||
}
|
||||
|
||||
ret, err := modules.ExtraProcessInstance.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(ret, modules.ExtraProcessInstance.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type ExtraProcessInstanceShowOptions struct {
|
||||
ID string `help:"ID of ExtraProcessInstance" required:"true"`
|
||||
}
|
||||
R(&ExtraProcessInstanceShowOptions{}, "itsm_extra_process_instance_list", "extra process instance list",
|
||||
func(s *mcclient.ClientSession, args *ExtraProcessInstanceShowOptions) error {
|
||||
ret, err := modules.ExtraProcessInstance.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ExtraUserCreateOptions struct {
|
||||
UserName string `help:"user name" required:"true"`
|
||||
Pwd string `help:"password" required:"true"`
|
||||
Url string `help:"url" required:"true"`
|
||||
Type string `help:"extra order type" required:"true"`
|
||||
}
|
||||
R(&ExtraUserCreateOptions{}, "itsm_extra_user_create", "extra user create",
|
||||
func(s *mcclient.ClientSession, args *ExtraUserCreateOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
ret, err := modules.ExtraUsers.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type ExtraUserListOptions struct {
|
||||
ID string `help:"ID of user"`
|
||||
}
|
||||
R(&ExtraUserListOptions{}, "itsm_extra_user_list", "extra user list",
|
||||
func(s *mcclient.ClientSession, args *ExtraUserListOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
if len(args.ID) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ID), "id")
|
||||
}
|
||||
ret, err := modules.ExtraUsers.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(ret, modules.ExtraUsers.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 列出历史流程实例
|
||||
*/
|
||||
type HistoricProcessInstanceListOptions struct {
|
||||
ProcessDefinitionKey string `help:"Process definition key"`
|
||||
UserId string `help:"ID of user"`
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&HistoricProcessInstanceListOptions{}, "historic-process-instance-list", "List historic process definition", func(s *mcclient.ClientSession, args *HistoricProcessInstanceListOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.ProcessDefinitionKey) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ProcessDefinitionKey), "process_definition_key")
|
||||
}
|
||||
if len(args.UserId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.UserId), "user_id")
|
||||
}
|
||||
result, err := modules.HistoricProcessInstance.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.HistoricProcessInstance.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的历史流程实例
|
||||
*/
|
||||
type HistoricProcessInstanceShowOptions struct {
|
||||
ID string `help:"ID of the historic process instance"`
|
||||
}
|
||||
R(&HistoricProcessInstanceShowOptions{}, "historic-process-instance-show", "Show historic process definition", func(s *mcclient.ClientSession, args *HistoricProcessInstanceShowOptions) error {
|
||||
result, err := modules.HistoricProcessInstance.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type HistoricProcessInstanceStaticticsOptions struct {
|
||||
ID string `help:"ID of user"`
|
||||
}
|
||||
R(&HistoricProcessInstanceStaticticsOptions{}, "historic-process-instance-statistics", "Show statistics for historic process instance", func(s *mcclient.ClientSession, args *HistoricProcessInstanceStaticticsOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.ID), "user_id")
|
||||
|
||||
rst, err := modules.HistoricProcessInstance.GetStatistics(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 列出历史任务实例
|
||||
*/
|
||||
type HistoricProcessInstanceListOptions struct {
|
||||
ProcessInstanceId string `help:"ID of process instance"`
|
||||
UserId string `help:"ID of user"`
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&HistoricProcessInstanceListOptions{}, "historic-task-instance-list", "List historic process instance", func(s *mcclient.ClientSession, args *HistoricProcessInstanceListOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.ProcessInstanceId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ProcessInstanceId), "process_instance_id")
|
||||
}
|
||||
if len(args.UserId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.UserId), "user_id")
|
||||
}
|
||||
result, err := modules.HistoricTaskInstances.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.HistoricTaskInstances.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的历史任务实例
|
||||
*/
|
||||
type HistoricProcessInstanceShowOptions struct {
|
||||
ID string `help:"ID of the historic task instance"`
|
||||
}
|
||||
R(&HistoricProcessInstanceShowOptions{}, "historic-task-instance-show", "Show historic task instance", func(s *mcclient.ClientSession, args *HistoricProcessInstanceShowOptions) error {
|
||||
result, err := modules.HistoricTaskInstances.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 删除指定ID的流程定义
|
||||
*/
|
||||
type ProcessDefinitionDeleteOptions struct {
|
||||
ID string `help:"ID of process definition, deletes the process definition which belongs to the given process definition id"`
|
||||
Cascade bool `help:"Whether to cascade delete process instance, if set to true, all process instances (including) history are deleted" required:"true" choices:"true|false"`
|
||||
}
|
||||
R(&ProcessDefinitionDeleteOptions{}, "process-definition-delete", "Delete process definition by ID", func(s *mcclient.ClientSession, args *ProcessDefinitionDeleteOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Cascade {
|
||||
params.Add(jsonutils.JSONTrue, "cascade")
|
||||
} else {
|
||||
params.Add(jsonutils.JSONFalse, "cascade")
|
||||
}
|
||||
result, e := modules.ProcessDefinitions.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改指定的流程定义的激活/挂起状态
|
||||
*/
|
||||
type NodealertUpdateOptions struct {
|
||||
ID string `help:"ID of process definition"`
|
||||
state string `help:"State of the process definition" choices:"activate|suspend"`
|
||||
}
|
||||
R(&NodealertUpdateOptions{}, "process-definition-change-state", "Update the state of the process definition", func(s *mcclient.ClientSession, args *NodealertUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.state), "state")
|
||||
result, err := modules.ProcessDefinitions.Put(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出流程定义
|
||||
*/
|
||||
type ProcessDefinitionListOptions struct {
|
||||
ProcessDefinitionKey string `help:"Key of process definition"`
|
||||
UserId string `help:"ID of user who start the process definition"`
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ProcessDefinitionListOptions{}, "process-definition-list", "List process definition", func(s *mcclient.ClientSession, args *ProcessDefinitionListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.ProcessDefinitionKey) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ProcessDefinitionKey), "process_definition_key")
|
||||
}
|
||||
if len(args.UserId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.UserId), "user_id")
|
||||
}
|
||||
result, err := modules.ProcessDefinitions.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.ProcessDefinitions.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的流程定义
|
||||
*/
|
||||
type ProcessDefinitionShowOptions struct {
|
||||
ID string `help:"ID of the process definition"`
|
||||
}
|
||||
R(&ProcessDefinitionShowOptions{}, "process-definition-show", "Show process definition", func(s *mcclient.ClientSession, args *ProcessDefinitionShowOptions) error {
|
||||
result, err := modules.ProcessDefinitions.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 创建流程实例(发起流程)
|
||||
*/
|
||||
type ProcessInstanceCreateOptions struct {
|
||||
PROCESS_DEFINITION_KEY string `help:"Key of the process definition"`
|
||||
INITIATOR string `help:"ID of user who launch the process instance"`
|
||||
SERVER_CREATE_PARAMTER string `help:"Onecloud server create spec json string"`
|
||||
UserId string `help:"ID of user"`
|
||||
RoleId string `help:"ID of role"`
|
||||
ProjectId string `help:"ID of project"`
|
||||
Percent string `help:"Great than Percent of nrOfCompletedInstances/nrOfInstances"`
|
||||
}
|
||||
R(&ProcessInstanceCreateOptions{}, "process-instance-create", "Create process instance", func(s *mcclient.ClientSession, args *ProcessInstanceCreateOptions) error {
|
||||
variables_params := jsonutils.NewDict()
|
||||
variables_params.Add(jsonutils.NewString(args.PROCESS_DEFINITION_KEY), "process_definition_key")
|
||||
variables_params.Add(jsonutils.NewString(args.INITIATOR), "initiator")
|
||||
variables_params.Add(jsonutils.NewString(args.SERVER_CREATE_PARAMTER), "server-create-paramter")
|
||||
if len(args.UserId) > 0 {
|
||||
variables_params.Add(jsonutils.NewString(args.UserId), "user-id")
|
||||
} else {
|
||||
if len(args.RoleId) > 0 {
|
||||
variables_params.Add(jsonutils.NewString(args.RoleId), "role-id")
|
||||
}
|
||||
if len(args.ProjectId) > 0 {
|
||||
variables_params.Add(jsonutils.NewString(args.ProjectId), "project-id")
|
||||
}
|
||||
}
|
||||
if len(args.Percent) > 0 {
|
||||
variables_params.Add(jsonutils.NewString(args.Percent), "percent")
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(variables_params, "variables")
|
||||
result, err := modules.ProcessInstance.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除指定ID的流程实例
|
||||
*/
|
||||
type ProcessInstanceDeleteOptions struct {
|
||||
ID string `help:"ID of process process"`
|
||||
DeleteReason string `help:"Reason why delete the process instance" required:"true" choices:"true|false"`
|
||||
}
|
||||
R(&ProcessInstanceDeleteOptions{}, "process-instance-delete", "Delete process instance by ID", func(s *mcclient.ClientSession, args *ProcessInstanceDeleteOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.DeleteReason) > 0 {
|
||||
params.Add(jsonutils.NewString(args.DeleteReason), "delete_reason")
|
||||
}
|
||||
result, e := modules.ProcessInstance.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出流程实例
|
||||
*/
|
||||
type ProcessInstanceListOptions struct {
|
||||
ProcessDefinitionId string `help:"ID of process definition"`
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ProcessInstanceListOptions{}, "process-instance-list", "List process instance", func(s *mcclient.ClientSession, args *ProcessInstanceListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.ProcessDefinitionId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ProcessDefinitionId), "process_definition_id")
|
||||
}
|
||||
result, err := modules.ProcessInstance.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.ProcessInstance.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的流程实例
|
||||
*/
|
||||
type ProcessInstanceShowOptions struct {
|
||||
ID string `help:"ID of the process instance"`
|
||||
}
|
||||
R(&ProcessInstanceShowOptions{}, "process-instance-show", "Show process instance", func(s *mcclient.ClientSession, args *ProcessInstanceShowOptions) error {
|
||||
result, err := modules.ProcessInstance.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 处理任务
|
||||
*/
|
||||
type TaskOperOperateOptions struct {
|
||||
ID string `help:"ID of task"`
|
||||
APPROVAL_DECISION bool `help:"Approval decision"`
|
||||
ApprovalProposal string `help:"Approval proposal"`
|
||||
}
|
||||
R(&TaskOperOperateOptions{}, "process-task-operate", "Operate task", func(s *mcclient.ClientSession, args *TaskOperOperateOptions) error {
|
||||
variables_params := jsonutils.NewDict()
|
||||
if args.APPROVAL_DECISION {
|
||||
variables_params.Add(jsonutils.JSONTrue, "approved")
|
||||
} else {
|
||||
variables_params.Add(jsonutils.JSONFalse, "approved")
|
||||
}
|
||||
if len(args.ApprovalProposal) > 0 {
|
||||
variables_params.Add(jsonutils.NewString(args.ApprovalProposal), "comment")
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(variables_params, "variables")
|
||||
result, err := modules.ProcessTasks.Put(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出任务
|
||||
*/
|
||||
type TaskListOptions struct {
|
||||
UserId string `help:"Id of user"`
|
||||
GroupId string `help:"ID of group"`
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&TaskListOptions{}, "process-task-list", "List task", func(s *mcclient.ClientSession, args *TaskListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.UserId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.UserId), "user_id")
|
||||
}
|
||||
if len(args.GroupId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.GroupId), "group_id")
|
||||
}
|
||||
result, err := modules.ProcessTasks.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.ProcessTasks.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定ID的任务
|
||||
*/
|
||||
type TaskShowOptions struct {
|
||||
ID string `help:"ID of the task"`
|
||||
}
|
||||
R(&TaskShowOptions{}, "process-task-show", "Show task details", func(s *mcclient.ClientSession, args *TaskShowOptions) error {
|
||||
result, err := modules.ProcessTasks.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type OperationListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&OperationListOptions{}, "operation-list", "List operations", func(s *mcclient.ClientSession, suboptions *OperationListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = suboptions.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Operations.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Operations.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type OperationUpdateOptions struct {
|
||||
TASK_ID string `help:"TASK_ID of process" `
|
||||
Content string `help:"Content of process" default:""`
|
||||
Result string `help:"Result of process" default:""`
|
||||
}
|
||||
R(&OperationUpdateOptions{}, "operation-update", "Update operation", func(s *mcclient.ClientSession, args *OperationUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
// params.Add(jsonutils.NewString(args.TASK_ID), "task_id")
|
||||
params.Add(jsonutils.NewString(args.Content), "content")
|
||||
params.Add(jsonutils.NewString(args.Result), "result")
|
||||
|
||||
obj, err := modules.Operations.Put(s, args.TASK_ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(obj)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
type OperationShowOptions struct {
|
||||
INSTANCE_ID string `help:"INSTANCE_ID of process" `
|
||||
}
|
||||
|
||||
R(&OperationShowOptions{}, "operation-show", "Show operation details", func(s *mcclient.ClientSession, args *OperationShowOptions) error {
|
||||
result, err := modules.Operations.Get(s, args.INSTANCE_ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type OperationCreateOptions struct {
|
||||
DeviceCode string `help:"DeviceCode of process"`
|
||||
ResourceSum int64 `help:"ResourceSum of process, default: 0" default:"0"`
|
||||
TemplateId string `help:"TemplateId of process" `
|
||||
Cpu int64 `help:"Cpu of process, default: 0" default:"0"`
|
||||
Memery int64 `help:"Memery of process, default: 0" default:"0"`
|
||||
Disk int64 `help:"Disk of process, default: 0" default:"0"`
|
||||
ProjectId string `help:"ProjectId of process" `
|
||||
Remark string `help:"Remark of process" `
|
||||
OPERATE_TYPE string `help:"OPERATE_TYPE of process" choices:"apply|config|template|delete"`
|
||||
Schedule string `help:"Schedule of process"`
|
||||
}
|
||||
|
||||
R(&OperationCreateOptions{}, "operation-create", "Create a operation", func(s *mcclient.ClientSession, args *OperationCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
params.Add(jsonutils.NewString(args.OPERATE_TYPE), "operate_type")
|
||||
|
||||
if len(args.DeviceCode) > 0 {
|
||||
params.Add(jsonutils.NewString(args.DeviceCode), "device_code")
|
||||
}
|
||||
|
||||
if args.ResourceSum > 0 {
|
||||
params.Add(jsonutils.NewInt(args.ResourceSum), "resource_sum")
|
||||
}
|
||||
|
||||
if len(args.TemplateId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.TemplateId), "template_id")
|
||||
}
|
||||
|
||||
if args.Cpu > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Cpu), "cpu")
|
||||
}
|
||||
|
||||
if args.Memery > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Memery), "memery")
|
||||
}
|
||||
|
||||
if args.Disk > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Disk), "disk")
|
||||
}
|
||||
|
||||
if len(args.ProjectId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ProjectId), "project_id")
|
||||
}
|
||||
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
|
||||
if len(args.Schedule) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Schedule), "schedule")
|
||||
}
|
||||
|
||||
operation, err := modules.Operations.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(operation)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type TaskListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&TaskListOptions{}, "process-list", "List processes", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = suboptions.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Processes.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Processes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type ProcessShowOptions struct {
|
||||
ID string `help:"ID or Name of the process to show"`
|
||||
}
|
||||
R(&ProcessShowOptions{}, "process-show", "Show process details", func(s *mcclient.ClientSession, args *ProcessShowOptions) error {
|
||||
result, err := modules.Processes.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// 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 itsm
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type TaskListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&TaskListOptions{}, "prosesslog-list", "List processlogs", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = suboptions.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Processlogs.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Processlogs.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
// 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 misc
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionagent"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type CopyrightUpdateOptions struct {
|
||||
Copyright string `help:"The copyright"`
|
||||
Email string `help:"The Email"`
|
||||
Docs *string `help:"the Docs website address"`
|
||||
License *string `help:"the license generator website address"`
|
||||
BrandCn *string `help:"the brand name in Chinese"`
|
||||
BrandEn *string `help:"the brand name in English"`
|
||||
}
|
||||
|
||||
R(&CopyrightUpdateOptions{}, "copyright-update", "update copyright", func(s *mcclient.ClientSession, args *CopyrightUpdateOptions) error {
|
||||
if !s.HasSystemAdminPrivilege() {
|
||||
return fmt.Errorf("require admin privilege")
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
if args.Docs != nil {
|
||||
params.Add(jsonutils.NewString(*args.Docs), "docs")
|
||||
}
|
||||
|
||||
if args.License != nil {
|
||||
params.Add(jsonutils.NewString(*args.License), "license")
|
||||
}
|
||||
|
||||
if args.BrandCn != nil {
|
||||
params.Add(jsonutils.NewString(*args.BrandCn), "brand_cn")
|
||||
}
|
||||
|
||||
if args.BrandEn != nil {
|
||||
params.Add(jsonutils.NewString(*args.BrandEn), "brand_en")
|
||||
}
|
||||
|
||||
if len(args.Copyright) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Copyright), "copyright")
|
||||
}
|
||||
|
||||
if len(args.Email) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Email), "email")
|
||||
}
|
||||
|
||||
r, err := yunionagent.Copyright.Update(s, "copyright", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(r)
|
||||
return nil
|
||||
})
|
||||
|
||||
type EnterpriseUpdateOptions struct {
|
||||
Name string `help:"Enterprise name"`
|
||||
Copyright string `help:"The Email"`
|
||||
Logo string `help:"logo file path"`
|
||||
LoginLogo string `help:"login page logo file path"`
|
||||
Favicon string `help:"favicon path"`
|
||||
}
|
||||
|
||||
R(&EnterpriseUpdateOptions{}, "infos-update", "update enterprise info", func(s *mcclient.ClientSession, args *EnterpriseUpdateOptions) error {
|
||||
var b bytes.Buffer
|
||||
w := multipart.NewWriter(&b)
|
||||
if len(args.Name) > 0 {
|
||||
w.WriteField("name", args.Name)
|
||||
}
|
||||
|
||||
if len(args.Copyright) > 0 {
|
||||
w.WriteField("copyright", args.Copyright)
|
||||
}
|
||||
|
||||
writeFile := func(filedName, filePath string) error {
|
||||
if len(filePath) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
c, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var v string
|
||||
c64 := base64.StdEncoding.EncodeToString(c)
|
||||
ext := filepath.Ext(filePath)
|
||||
switch ext {
|
||||
case ".png":
|
||||
v = fmt.Sprintf("data:image/png;base64,%s", c64)
|
||||
case ".jpg":
|
||||
v = fmt.Sprintf("data:image/jpg;base64,%s", c64)
|
||||
default:
|
||||
return fmt.Errorf("only support png/jpg image")
|
||||
}
|
||||
|
||||
err = w.WriteField(filedName, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := writeFile("logo", args.Logo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := writeFile("login_logo", args.LoginLogo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := writeFile("favicon", args.Favicon); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
header := make(http.Header)
|
||||
header.Set("content-type", fmt.Sprintf("multipart/form-data; boundary=%s", w.Boundary()))
|
||||
w.Close()
|
||||
|
||||
ret, err := yunionagent.Info.Update(s, header, bufio.NewReader(&b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
// 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 misc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionagent"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type LicenseListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
|
||||
R(&LicenseListOptions{}, "licenses-list", "show licenses", func(s *mcclient.ClientSession, args *LicenseListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lics, err := yunionagent.License.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(lics, yunionagent.License.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type LicenseUploadOptions struct {
|
||||
FILE string
|
||||
}
|
||||
|
||||
R(&LicenseUploadOptions{}, "license-upload", "Upload license", func(s *mcclient.ClientSession, args *LicenseUploadOptions) error {
|
||||
bodyBuf := &bytes.Buffer{}
|
||||
bodyWriter := multipart.NewWriter(bodyBuf)
|
||||
fileWriter, err := bodyWriter.CreateFormFile("license", args.FILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fh, err := os.Open(args.FILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fh.Close()
|
||||
_, err = io.Copy(fileWriter, fh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contentType := bodyWriter.FormDataContentType()
|
||||
bodyWriter.Close()
|
||||
|
||||
header := http.Header{}
|
||||
header.Set("Content-Type", contentType)
|
||||
lic, err := yunionagent.License.Upload(s, header, bodyBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(lic)
|
||||
return nil
|
||||
})
|
||||
|
||||
type LicenseShowOptions struct {
|
||||
SERVICE string `help:"service name" choices:"compute|service_tree"`
|
||||
}
|
||||
|
||||
R(&LicenseShowOptions{}, "licenses-show", "show actived license", func(s *mcclient.ClientSession, args *LicenseShowOptions) error {
|
||||
lic, e := yunionagent.License.Get(s, args.SERVICE, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
printObject(lic)
|
||||
return nil
|
||||
})
|
||||
|
||||
type LicenseStatusOptions struct {
|
||||
SERVICE string `help:"service name" choices:"compute|service_tree"`
|
||||
}
|
||||
|
||||
R(&LicenseStatusOptions{}, "licenses-usage", "show license usages status", func(s *mcclient.ClientSession, args *LicenseStatusOptions) error {
|
||||
status, err := yunionagent.License.GetSpecific(s, args.SERVICE, "status", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(status)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// 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 misc
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionagent"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/yunionagent"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&yunionagent.Notice).WithKeyword("notice")
|
||||
cmd.List(&options.NoticeListOptions{})
|
||||
cmd.Create(&options.NoticeCreateOptions{})
|
||||
cmd.Update(&options.NoticesUpdateOptions{})
|
||||
cmd.Delete(&options.NoticeOptions{})
|
||||
}
|
||||
@@ -19,32 +19,9 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/itsm"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type TaskListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&TaskListOptions{}, "task-list", "List taskman", func(s *mcclient.ClientSession, suboptions *TaskListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = suboptions.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := itsm.Tasks.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, itsm.Tasks.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type RegionTaskListOptions struct {
|
||||
ObjName string `help:"object name"`
|
||||
ObjId string `help:"object id"`
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// 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 misc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/autoupdate"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type SUpdateListOptions struct {
|
||||
options.BaseListOptions
|
||||
Region string `help:"cloud region ID or Name"`
|
||||
}
|
||||
|
||||
R(&SUpdateListOptions{}, "update-list", "List updates", func(s *mcclient.ClientSession, args *SUpdateListOptions) error {
|
||||
// TODO filer by region
|
||||
result, err := modules.Updates.List(s, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.Updates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type SUpdatePerformOptions struct {
|
||||
Cmp bool `help:"update Controller And all the Compute nodes automatically"`
|
||||
CmpOnly bool `help:"Updates only computes nodes, excluding controller nodes"`
|
||||
}
|
||||
|
||||
R(&SUpdatePerformOptions{}, "update-perform", "Update the Controler", func(s *mcclient.ClientSession, args *SUpdatePerformOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
if args.Cmp && args.CmpOnly {
|
||||
return fmt.Errorf("--cmp and --cmp-only can't go together")
|
||||
}
|
||||
|
||||
if args.Cmp {
|
||||
params.Add(jsonutils.JSONTrue, "cmp")
|
||||
} else if args.CmpOnly {
|
||||
params.Add(jsonutils.JSONTrue, "cmp_only")
|
||||
}
|
||||
|
||||
modules.Updates.PerformAction(s, "", "", params)
|
||||
|
||||
result, err := modules.Updates.List(s, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Updates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -25,8 +25,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/identity"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionagent"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -44,7 +42,6 @@ func init() {
|
||||
|
||||
type VersionListOptions struct {
|
||||
}
|
||||
|
||||
R(&VersionListOptions{}, "version-list", "query all backend service version", func(s *mcclient.ClientSession, args *VersionListOptions) error {
|
||||
services := []jsonutils.JSONObject{}
|
||||
params := map[string]interface{}{}
|
||||
@@ -78,33 +75,4 @@ func init() {
|
||||
printObject(jsonutils.Marshal(vers))
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.VersionListOptions{}, "yunionagent-version-list", "show versions of backend services", func(s *mcclient.ClientSession, opts *options.VersionListOptions) error {
|
||||
if len(opts.Region) == 0 {
|
||||
opts.Region = s.GetRegion()
|
||||
}
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := yunionagent.Version.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, []string{})
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.VersionGetOptions{}, "yunionagent-version-show", "Show service version", func(s *mcclient.ClientSession, opts *options.VersionGetOptions) error {
|
||||
result, err := yunionagent.Version.Get(s, opts.Service, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ver, err := result.GetString()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s\n", ver)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// 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 misc
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/websocket"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type SWebsocketNotifyOptions struct {
|
||||
Cmp bool `help:"websocket all the compute nodes automatically"`
|
||||
}
|
||||
|
||||
R(&SWebsocketNotifyOptions{}, "websocket-notify", "post a Websocket msg", func(s *mcclient.ClientSession, args *SWebsocketNotifyOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Cmp {
|
||||
params.Add(jsonutils.JSONTrue, "cmp")
|
||||
}
|
||||
|
||||
_, err := websocket.Websockets.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package itsm
|
||||
package quota
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package compute
|
||||
package quota
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/quota"
|
||||
)
|
||||
|
||||
type ComputeQuotaKeys struct {
|
||||
@@ -1,67 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
/**
|
||||
* 列出报警事件
|
||||
*/
|
||||
R(&options.AlarmEventListOptions{}, "alarmevent-list", "List all alarm's event", func(s *mcclient.ClientSession, opts *options.AlarmEventListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.AlarmEvents.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.AlarmEvents.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/*
|
||||
* 修改报警事件ACK确认状态
|
||||
*/
|
||||
type AlarmEventUpdateOptions struct {
|
||||
ID string `help:"ID of the alarm event"`
|
||||
STATUS int64 `help:"Alarm event ack status" choices:"0|1"`
|
||||
}
|
||||
R(&AlarmEventUpdateOptions{}, "alarmevent-ack-update", "Update ack status of alarm event", func(s *mcclient.ClientSession, args *AlarmEventUpdateOptions) error {
|
||||
arr := jsonutils.NewArray()
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(args.ID), "id")
|
||||
tmpObj.Add(jsonutils.NewInt(args.STATUS), "ack_status")
|
||||
arr.Add(tmpObj)
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(arr, "alarm_events")
|
||||
|
||||
alarmevent, err := modules.AlarmEvents.DoBatchUpdate(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarmevent)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建报警日志
|
||||
*/
|
||||
type AlarmLogDetailOptions struct {
|
||||
NODE_NAME string `help:"Name of the host"`
|
||||
Lables string `help:"Labels of the service tree node"`
|
||||
Metric_Name string `help:"Metric name of the alarm"`
|
||||
Start_Time string `help:"Alarm start time"`
|
||||
This_Time string `help:"Alarm this time"`
|
||||
Alarm_Ways string `help:"Alarm ways"`
|
||||
Alarm_Level string `help:"Alarm level"`
|
||||
Alarm_Status string `help:"Alarm status"`
|
||||
Receive_Person string `help:"Alarm receive person"`
|
||||
Reason string `help:"Alarm reason, aka alarm rule content"`
|
||||
Alarm_Id string `help:"Alarm ID"`
|
||||
Host_Id string `help:"ID of the host"`
|
||||
}
|
||||
R(&AlarmLogDetailOptions{}, "alarmlog-create", "Create a alarm log", func(s *mcclient.ClientSession, args *AlarmLogDetailOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NODE_NAME), "node_name")
|
||||
if len(args.Lables) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Lables), "labels")
|
||||
}
|
||||
if len(args.Metric_Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Metric_Name), "metric_name")
|
||||
}
|
||||
if len(args.Start_Time) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Start_Time), "start_time")
|
||||
}
|
||||
if len(args.This_Time) > 0 {
|
||||
params.Add(jsonutils.NewString(args.This_Time), "this_time")
|
||||
}
|
||||
if len(args.Alarm_Ways) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Alarm_Ways), "alarm_ways")
|
||||
}
|
||||
if len(args.Alarm_Level) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Alarm_Level), "alarm_level")
|
||||
}
|
||||
if len(args.Alarm_Status) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Alarm_Status), "alarm_status")
|
||||
}
|
||||
if len(args.Receive_Person) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Receive_Person), "receive_person")
|
||||
}
|
||||
if len(args.Reason) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Reason), "reason")
|
||||
}
|
||||
if len(args.Alarm_Id) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Alarm_Id), "alarm_id")
|
||||
}
|
||||
if len(args.Host_Id) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Host_Id), "host_id")
|
||||
}
|
||||
alarmlog, err := modules.AlarmLogs.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarmlog)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出报警日志
|
||||
*/
|
||||
type AlarmLogListOptions struct {
|
||||
options.BaseListOptions
|
||||
Host string `help:"Name of the host"`
|
||||
Id int64 `help:"ID of tree node"`
|
||||
Label []string `help:"Labels to this tree node"`
|
||||
Metric string `help:"Metric name"`
|
||||
StartTimeSince string `help:"Start time since the alarm event"`
|
||||
StartTimeUntil string `help:"Start time until the alarm event"`
|
||||
ThisTimeSince string `help:"This time since the alarm event"`
|
||||
ThisTimeUntil string `help:"This time until the alarm event"`
|
||||
}
|
||||
R(&AlarmLogListOptions{}, "alarmlog-list", "List all alarm's event", func(s *mcclient.ClientSession, args *AlarmLogListOptions) error {
|
||||
params, err := args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.Host) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Host), "host")
|
||||
}
|
||||
if len(args.Label) > 0 {
|
||||
names := []string{"corp", "owt", "pdl", "srv", "env"}
|
||||
segs := make([]string, len(args.Label))
|
||||
|
||||
for i := 0; i < len(args.Label); i += 1 {
|
||||
sublabel := args.Label[:i+1]
|
||||
pid, _ := modules.TreeNodes.GetNodeIDByLabels(s, sublabel)
|
||||
if pid < 0 {
|
||||
return fmt.Errorf("Invalid node data")
|
||||
}
|
||||
segs[i] = fmt.Sprintf("%s=%d", names[i], pid)
|
||||
}
|
||||
|
||||
node_labels := strings.Join(segs, ",")
|
||||
|
||||
params.Add(jsonutils.NewString(node_labels), "node_labels")
|
||||
}
|
||||
if len(args.Metric) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Metric), "metric")
|
||||
}
|
||||
if len(args.StartTimeSince) > 0 {
|
||||
params.Add(jsonutils.NewString(args.StartTimeSince), "start_time_since")
|
||||
}
|
||||
if len(args.StartTimeUntil) > 0 {
|
||||
params.Add(jsonutils.NewString(args.StartTimeUntil), "start_time_until")
|
||||
}
|
||||
if len(args.ThisTimeSince) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ThisTimeSince), "this_time_since")
|
||||
}
|
||||
if len(args.ThisTimeUntil) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ThisTimeUntil), "this_time_until")
|
||||
}
|
||||
|
||||
result, err := modules.AlarmLogs.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.AlarmLogs.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建报警规则
|
||||
*/
|
||||
type AlarmDetailOptions struct {
|
||||
METRICNAME string `help:"Metric name of the alarm"`
|
||||
ALARMCONDITION string `help:"Alarm condition template of the alarm"`
|
||||
TEMPLATE string `help:"Alarm condition template of the alarm"`
|
||||
ALARMLEVEL string `help:"Alarm level of the alarm"`
|
||||
CONTACT_TYPE string `help:"Alarm contact type"`
|
||||
EXPIRESECONDS int64 `help:"Expire seconds of the alarm"`
|
||||
ESCALATESECONDS int64 `help:"Escalate seconds of the alarm"`
|
||||
ALARMTEMPLATE_ID string `help:"ID of the alarm template"`
|
||||
Remark string `help:"Remark or description of the new alarm"`
|
||||
}
|
||||
R(&AlarmDetailOptions{}, "alarm-create", "Create a alarm", func(s *mcclient.ClientSession, args *AlarmDetailOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.METRICNAME), "metric_name")
|
||||
params.Add(jsonutils.NewString(args.ALARMCONDITION), "alarm_condition")
|
||||
params.Add(jsonutils.NewString(args.TEMPLATE), "template")
|
||||
params.Add(jsonutils.NewString(args.ALARMLEVEL), "alarm_level")
|
||||
params.Add(jsonutils.NewString(args.CONTACT_TYPE), "contact_type")
|
||||
params.Add(jsonutils.NewInt(args.EXPIRESECONDS), "expire_seconds")
|
||||
params.Add(jsonutils.NewInt(args.ESCALATESECONDS), "escalate_seconds")
|
||||
params.Add(jsonutils.NewString(args.ALARMTEMPLATE_ID), "alarm_template_id")
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
alarm, err := modules.Alarms.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarm)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除指定ID的报警规则
|
||||
*/
|
||||
type AlarmDeleteOptions struct {
|
||||
ID string `help:"ID of alarm"`
|
||||
}
|
||||
R(&AlarmDeleteOptions{}, "alarm-delete", "Delete a alarm", func(s *mcclient.ClientSession, args *AlarmDeleteOptions) error {
|
||||
alarm, e := modules.Alarms.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(alarm)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改指定ID的报警规则
|
||||
*/
|
||||
type AlarmUpdateOptions struct {
|
||||
ID string `help:"ID of the alarm"`
|
||||
Name string `help:"Name of the new alarm"`
|
||||
MetricName string `help:"Metric name of the alarm"`
|
||||
AlarmCondition string `help:"Alarm condition template of the alarm"`
|
||||
Template string `help:"Alarm condition template of the alarm"`
|
||||
AlarmLevel string `help:"Alarm level of the alarm"`
|
||||
ContactType string `help:"Alarm contact type"`
|
||||
ExpireSeconds int64 `help:"Expire seconds of the alarm"`
|
||||
EscalateSeconds int64 `help:"Escalate seconds of the alarm"`
|
||||
Remark string `help:"Remark or description of the new alarm"`
|
||||
}
|
||||
R(&AlarmUpdateOptions{}, "alarm-update", "Update a alarm", func(s *mcclient.ClientSession, args *AlarmUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
if len(args.MetricName) > 0 {
|
||||
params.Add(jsonutils.NewString(args.MetricName), "metric_name")
|
||||
}
|
||||
if len(args.AlarmCondition) > 0 {
|
||||
params.Add(jsonutils.NewString(args.AlarmCondition), "alarm_condition")
|
||||
}
|
||||
if len(args.Template) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Template), "template")
|
||||
}
|
||||
if len(args.AlarmLevel) > 0 {
|
||||
params.Add(jsonutils.NewString(args.AlarmLevel), "alarm_level")
|
||||
}
|
||||
if len(args.ContactType) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ContactType), "contact_type")
|
||||
}
|
||||
if args.ExpireSeconds > 0 {
|
||||
params.Add(jsonutils.NewInt(args.ExpireSeconds), "expire_seconds")
|
||||
}
|
||||
if args.EscalateSeconds > 0 {
|
||||
params.Add(jsonutils.NewInt(args.EscalateSeconds), "escalate_seconds")
|
||||
}
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
|
||||
alarm, err := modules.Labels.Patch(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarm)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出报警规则
|
||||
*/
|
||||
type AlarmListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&AlarmListOptions{}, "alarm-list", "List all alarms", func(s *mcclient.ClientSession, args *AlarmListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Alarms.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Alarms.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 根据ID查询报警规则
|
||||
*/
|
||||
type AlarmShowOptions struct {
|
||||
ID string `help:"ID of the alarm to show"`
|
||||
}
|
||||
R(&AlarmShowOptions{}, "alarm-show", "Show alarm details", func(s *mcclient.ClientSession, args *AlarmShowOptions) error {
|
||||
result, err := modules.Alarms.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建报警模板
|
||||
*/
|
||||
type AlarmTemplateOptions struct {
|
||||
NAME string `help:"Name of the new alarm-template"`
|
||||
BELONGTO string `help:"Detect the service-tree-node' labels which alarm-template belong to"`
|
||||
Description string `help:"Description of the alarm-template"`
|
||||
}
|
||||
R(&AlarmTemplateOptions{}, "alarmtemplate-create", "Create a alarm-template", func(s *mcclient.ClientSession, args *AlarmTemplateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "alarm_template_name")
|
||||
params.Add(jsonutils.NewString(args.BELONGTO), "belongto")
|
||||
if len(args.Description) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Description), "alarm_template_desc")
|
||||
}
|
||||
alarmTemplate, err := modules.AlarmTemplates.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarmTemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除指定ID的报警模板
|
||||
*/
|
||||
type AlarmTemplateDeleteOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
}
|
||||
R(&AlarmTemplateDeleteOptions{}, "alarmtemplate-delete", "Delete a alarm-template", func(s *mcclient.ClientSession, args *AlarmTemplateDeleteOptions) error {
|
||||
alarmTemplate, e := modules.AlarmTemplates.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(alarmTemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改指定ID的报警模板
|
||||
*/
|
||||
type AlarmTemplateUpdateOptions struct {
|
||||
ID string `help:"ID of the alarm-template"`
|
||||
Name string `help:"New name of the new alarm-template"`
|
||||
Description string `help:"New description of the alarm-template"`
|
||||
}
|
||||
R(&AlarmTemplateUpdateOptions{}, "alarmtemplate-update", "Update a alarm-template", func(s *mcclient.ClientSession, args *AlarmTemplateUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "alarm_template_name")
|
||||
}
|
||||
if len(args.Description) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Description), "alarm_template_desc")
|
||||
}
|
||||
|
||||
alarmTemplate, err := modules.AlarmTemplates.Put(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(alarmTemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出报警模板
|
||||
*/
|
||||
type AlarmTemplateListOptions struct {
|
||||
options.BaseListOptions
|
||||
LIST_TYPE string `help:"Type of list: avaliable|applied|created "`
|
||||
LABELS string `help:"Labels for node(split by comma)"`
|
||||
}
|
||||
R(&AlarmTemplateListOptions{}, "alarmtemplate-list", "List all alarm templates ", func(s *mcclient.ClientSession, args *AlarmTemplateListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
params.Add(jsonutils.NewString(args.LIST_TYPE), "type")
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
|
||||
result, err := modules.AlarmTemplates.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.AlarmTemplates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 根据ID查询报警模板(查看报警模板详情)
|
||||
*/
|
||||
type AlarmTemplateShowOptions struct {
|
||||
ID string `help:"ID of the alarm-template to show"`
|
||||
}
|
||||
R(&AlarmTemplateShowOptions{}, "alarmtemplate-show", "Show alarm template details", func(s *mcclient.ClientSession, args *AlarmTemplateShowOptions) error {
|
||||
result, err := modules.AlarmTemplates.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看报警模板下的报警项
|
||||
*/
|
||||
type AlarmTemplateBaseOptions struct {
|
||||
ID string `help:"ID of the alarm template"`
|
||||
}
|
||||
R(&AlarmTemplateBaseOptions{}, "alarmtemplate-alarm-list", "List alarms of alarm template", func(s *mcclient.ClientSession, args *AlarmTemplateBaseOptions) error {
|
||||
result, err := modules.AlarmTemplateAlarms.ListDescendent(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Alarms.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 向指定的报警模板中添加报警项(添加报警项)
|
||||
*/
|
||||
type AlarmTemplateAlarmOptions struct {
|
||||
ALARMTEMPLATE_ID string `help:"ID of alarm-template"`
|
||||
ALARM_ID string `help:"ID of alarm"`
|
||||
}
|
||||
R(&AlarmTemplateAlarmOptions{}, "add-alarm-to-template", "Add alarm to alarm-template", func(s *mcclient.ClientSession, args *AlarmTemplateAlarmOptions) error {
|
||||
_, err := modules.AlarmTemplateAlarms.Attach(s, args.ALARMTEMPLATE_ID, args.ALARM_ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 从指定的报警模板中删除报警项(删除报警项)
|
||||
*/
|
||||
R(&AlarmTemplateAlarmOptions{}, "remove-alarm-from-template", "Remove alarm from alarm-template", func(s *mcclient.ClientSession, args *AlarmTemplateAlarmOptions) error {
|
||||
_, err := modules.Alarms.DeleteInContext(s, args.ALARM_ID, nil, &modules.AlarmTemplates, args.ALARMTEMPLATE_ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 给服务树节点增加报警模板
|
||||
*/
|
||||
type AlarmTemplateNodeAddOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
Labels []string `help:"Labels for node" nargs:"+"`
|
||||
Receiver1 string `help:"Primary alarm receiver" nargs:"+"`
|
||||
Receiver2 string `help:"Secondary alarm receiver"`
|
||||
}
|
||||
R(&AlarmTemplateNodeAddOptions{}, "bind-template-to-node", "Bind alarm-template to service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateNodeAddOptions) error {
|
||||
labels := jsonutils.NewDict()
|
||||
for _, f := range args.Labels {
|
||||
parts := strings.Split(f, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(labels, "labels")
|
||||
params.Add(jsonutils.NewString(args.Receiver1), "tier1_receivers")
|
||||
params.Add(jsonutils.NewString(args.Receiver2), "tier2_receivers")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "add-labels", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 将报警模板从服务数节点移除
|
||||
*/
|
||||
type AlarmTemplateRemoveFromNodeOptions struct {
|
||||
ID string `help:"ID of the alarm-template"`
|
||||
Labels []string `help:"Node labels" nargs:"+"`
|
||||
}
|
||||
R(&AlarmTemplateRemoveFromNodeOptions{}, "unbind-template-from-node", "Unbind alarm-template from service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateRemoveFromNodeOptions) error {
|
||||
labels := jsonutils.NewDict()
|
||||
for _, f := range args.Labels {
|
||||
parts := strings.Split(f, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(labels, "labels")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "remove-labels", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 给服务树编辑模板详情
|
||||
*/
|
||||
type AlarmTemplateNodeUpdateOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
Labels []string `help:"Labels for node" nargs:"+"`
|
||||
Receiver1 string `help:"Primary alarm receiver"`
|
||||
Receiver2 string `help:"Secondary alarm receiver"`
|
||||
}
|
||||
R(&AlarmTemplateNodeUpdateOptions{}, "update-template-for-node", "Update alarm-template for service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateNodeUpdateOptions) error {
|
||||
labels := jsonutils.NewDict()
|
||||
for _, f := range args.Labels {
|
||||
parts := strings.Split(f, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(labels, "labels")
|
||||
params.Add(jsonutils.NewString(args.Receiver1), "tier1_receivers")
|
||||
params.Add(jsonutils.NewString(args.Receiver2), "tier2_receivers")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "update-labels", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看此模板有哪些label正在使用
|
||||
*/
|
||||
type AlarmTemplateLabelListOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
}
|
||||
R(&AlarmTemplateLabelListOptions{}, "labels-for-alarmtemplate", "List all the labels for the alarm-templates", func(s *mcclient.ClientSession, args *AlarmTemplateLabelListOptions) error {
|
||||
result, err := modules.AlarmTemplates.GetSpecific(s, args.ID, "labels", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 为树务树节点添加报警模板
|
||||
*/
|
||||
type AlarmTemplateAddToNodeOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
LABELS string `help:"Labels for node"`
|
||||
Status int64 `help:"Enabled or disabled binding status" choices:"1|0"`
|
||||
}
|
||||
R(&AlarmTemplateAddToNodeOptions{}, "add-alarmtemplate-to-treenode", "Bind alarm-template to service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateAddToNodeOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
if args.Status > 0 {
|
||||
params.Add(jsonutils.NewInt(args.Status), "enabled")
|
||||
}
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "add-to-treenode", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 从树务树节点删除报警模板
|
||||
*/
|
||||
type AlarmTemplateDeleteFromNodeOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
LABELS string `help:"Labels for node"`
|
||||
}
|
||||
R(&AlarmTemplateDeleteFromNodeOptions{}, "delete-alarmtemplate-from-treenode", "UnBind alarm-template from service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateDeleteFromNodeOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "delete-from-treenode", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 克隆报警模板到服务树节点
|
||||
*/
|
||||
type AlarmTemplateeCloneToNodeOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
LABELS string `help:"Labels for node"`
|
||||
}
|
||||
R(&AlarmTemplateeCloneToNodeOptions{}, "clone-alarmtemplate-to-treenode", "Bind alarm-template to service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateeCloneToNodeOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "clone-to-treenode", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改树务树节点绑定的报警模板状态
|
||||
*/
|
||||
type AlarmTemplateDChangeStatusNodeOptions struct {
|
||||
ID string `help:"ID of alarm-template"`
|
||||
LABELS string `help:"Labels for node"`
|
||||
STATUS int64 `help:"Enabled or disabled binding status, choices is 1|0"`
|
||||
}
|
||||
R(&AlarmTemplateDChangeStatusNodeOptions{}, "change-status-alarmtemplate-for-treenode", "UnBind alarm-template from service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateDChangeStatusNodeOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
params.Add(jsonutils.NewInt(args.STATUS), "enabled")
|
||||
|
||||
_, err := modules.AlarmTemplates.PerformAction(s, args.ID, "change-bind-status", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改报警模板下的报警规则的状态
|
||||
*/
|
||||
type AlarmTemplateAlarmEnabledOptions struct {
|
||||
ALARMTEMPLATE_ID string `help:"ID of alarm-template"`
|
||||
ALARM_ID string `help:"ID of alarm"`
|
||||
ENABLED int64 `help:"Enabled or disabled binding status, choices is 1|0"`
|
||||
}
|
||||
R(&AlarmTemplateAlarmEnabledOptions{}, "change-alarm-enabled", "UnBind alarm-template from service-tree node", func(s *mcclient.ClientSession, args *AlarmTemplateAlarmEnabledOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewInt(args.ENABLED), "enabled")
|
||||
|
||||
_, err := modules.AlarmTemplateAlarms.Update(s, args.ALARMTEMPLATE_ID, args.ALARM_ID, nil, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/util/printutils"
|
||||
)
|
||||
|
||||
var (
|
||||
R = shell.R
|
||||
printList = printutils.PrintJSONList
|
||||
printObject = printutils.PrintJSONObject
|
||||
printBatchResults = printutils.PrintJSONBatchResults
|
||||
|
||||
InvalidUpdateError = shell.InvalidUpdateError
|
||||
printObjectRecursive = printutils.PrintJSONObjectRecursive
|
||||
)
|
||||
@@ -1,121 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 新建一个标签
|
||||
*/
|
||||
type LabelCreateOptions struct {
|
||||
NAME string `help:"Name of the new label"`
|
||||
VALUETYPE string `help:"Label value's type such as int, float, string, bool, choices"`
|
||||
Remark string `help:"Remark or description of the new label"`
|
||||
}
|
||||
R(&LabelCreateOptions{}, "label-create", "Create a label", func(s *mcclient.ClientSession, args *LabelCreateOptions) error {
|
||||
mod, err := modulebase.GetModule(s, "labels")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString(args.VALUETYPE), "value_type")
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
|
||||
label, err := mod.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(label)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除指定name的标签(删除指定name的标签)
|
||||
*/
|
||||
type LabelDeleteOptions struct {
|
||||
NAME string `help:"Name of label"`
|
||||
}
|
||||
R(&LabelDeleteOptions{}, "label-delete", "Delete a label", func(s *mcclient.ClientSession, args *LabelDeleteOptions) error {
|
||||
label, e := modules.Labels.Delete(s, args.NAME, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(label)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改标签(修改指定name的标签)
|
||||
*/
|
||||
type LabelUpdateOptions struct {
|
||||
NAME string `help:"Name of the label"`
|
||||
ValueType string `help:"Label value's type such as int, float, string, bool, choices"`
|
||||
Remark string `help:"Remark or description of the new label"`
|
||||
}
|
||||
R(&LabelUpdateOptions{}, "label-update", "Update a label", func(s *mcclient.ClientSession, args *LabelUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
if len(args.ValueType) > 0 {
|
||||
params.Add(jsonutils.NewString(args.ValueType), "value_type")
|
||||
}
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
|
||||
label, err := modules.Labels.Patch(s, args.NAME, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(label)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出所有的标签
|
||||
*/
|
||||
type LabelListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&LabelListOptions{}, "label-list", "List labels", func(s *mcclient.ClientSession, args *LabelListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Labels.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Labels.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出指定监控类型下的全部指标类型
|
||||
*/
|
||||
type MonitorTypesBaseOptions struct {
|
||||
ID string `help:"ID of the monitor type"`
|
||||
}
|
||||
R(&MonitorTypesBaseOptions{}, "monitortype-metrictype-list", "List metric types of the monitor type", func(s *mcclient.ClientSession, args *MonitorTypesBaseOptions) error {
|
||||
result, err := modules.MetricsTypes.ListInContext(s, nil, &modules.MonitorTypes, args.ID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.MetricsTypes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出指定指标类型下的全部指标
|
||||
*/
|
||||
type MetricTypesBaseOptions struct {
|
||||
ID string `help:"ID of the metric type"`
|
||||
}
|
||||
R(&MetricTypesBaseOptions{}, "metrictype-metric-list", "List metric types of the monitor type", func(s *mcclient.ClientSession, args *MetricTypesBaseOptions) error {
|
||||
result, err := modules.Metrics.ListInContext(s, nil, &modules.MetricsTypes, args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Metrics.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出所有监控指标
|
||||
*/
|
||||
type MetricsListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&MetricsListOptions{}, "metric-list", "List all metrics", func(s *mcclient.ClientSession, args *MetricsListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.Metrics.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.Metrics.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看监控指标详情
|
||||
*/
|
||||
type MetricsShowOptions struct {
|
||||
options.BaseListOptions
|
||||
ID string `help:"The ID of the metric"`
|
||||
}
|
||||
R(&MetricsShowOptions{}, "metric-show", "Show metric details", func(s *mcclient.ClientSession, args *MetricsShowOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.Metrics.Get(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 根据name查看监控指标详情
|
||||
*/
|
||||
type MetricsShowByNameOptions struct {
|
||||
options.BaseListOptions
|
||||
NAME string `help:"The NAME of the metric"`
|
||||
}
|
||||
R(&MetricsShowByNameOptions{}, "metric-details", "Show metric details by name", func(s *mcclient.ClientSession, args *MetricsShowByNameOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.Metrics.GetSpecific(s, "", args.NAME, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 添加/修改树节点的统计指标(配置服务树某个节点都有什么监控指标)
|
||||
*/
|
||||
type MonitorMetricsUpdateOptions struct {
|
||||
LABEL []string `help:"Labels to this tree node"`
|
||||
MetricName []string `help:"Metric names to add to" nargs:"+"`
|
||||
}
|
||||
R(&MonitorMetricsUpdateOptions{}, "monitor-metrics-set", "Set monitor metric for the tree-node", func(s *mcclient.ClientSession, args *MonitorMetricsUpdateOptions) error {
|
||||
names := []string{"corp", "owt", "pdl", "srv", "env"}
|
||||
segs := make([]string, len(args.LABEL))
|
||||
|
||||
for i := 0; i < len(args.LABEL); i += 1 {
|
||||
sublabel := args.LABEL[:i+1]
|
||||
pid, _ := modules.TreeNodes.GetNodeIDByLabels(s, sublabel)
|
||||
segs[i] = fmt.Sprintf("%s=%d", names[i], pid)
|
||||
}
|
||||
|
||||
node_labels := strings.Join(segs, ",")
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(node_labels), "node_labels")
|
||||
arr := jsonutils.NewArray()
|
||||
if len(args.MetricName) > 0 {
|
||||
for _, f := range args.MetricName {
|
||||
arr.Add(jsonutils.NewString(f))
|
||||
}
|
||||
}
|
||||
params.Add(arr, "metrics")
|
||||
|
||||
rst, err := modules.MonitorMetrics.Create(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出全部的监控类型
|
||||
*/
|
||||
type MonitorTypesOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&MonitorTypesOptions{}, "monitortype-list", "List all monitor types", func(s *mcclient.ClientSession, args *MonitorTypesOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.MonitorTypes.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.MonitorTypes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出所有监控数据源
|
||||
*/
|
||||
type MonitorInputsListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&MonitorInputsListOptions{}, "monitorinputs-list", "List all monitor-inputs", func(s *mcclient.ClientSession, args *MonitorInputsListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.MonitorInputs.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.MonitorInputs.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看监控数据源下的监控项
|
||||
*/
|
||||
type MonitorInputsShowOptions struct {
|
||||
options.BaseListOptions
|
||||
ID string `help:"The ID of the monitor-input"`
|
||||
}
|
||||
R(&MonitorInputsShowOptions{}, "monitorinputs-metrics-list", "List all metrics for the monitor-inputs", func(s *mcclient.ClientSession, args *MonitorInputsShowOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.MonitorInputs.GetSpecific(s, args.ID, "metrics", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建监控模板
|
||||
*/
|
||||
type MonitorTemplateCreateOptions struct {
|
||||
NAME string `help:"The name of the monitor-template"`
|
||||
Desc string `help:"Description of the monitor-template"`
|
||||
MonitorInputs []string `help:"Monitor-inputs add to the monitor-template"`
|
||||
}
|
||||
R(&MonitorTemplateCreateOptions{}, "monitortemplate-create", "Create or update contact for user", func(s *mcclient.ClientSession, args *MonitorTemplateCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "monitor_template_name")
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "monitor_template_desc")
|
||||
}
|
||||
if len(args.MonitorInputs) > 0 {
|
||||
monitors := jsonutils.NewDict()
|
||||
for _, f := range args.MonitorInputs {
|
||||
parts := strings.Split(f, "=")
|
||||
monitors.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
params.Add(monitors, "monitors")
|
||||
}
|
||||
|
||||
monitortemplate, err := modules.MonitorTemplates.Create(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(monitortemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出监控模板
|
||||
*/
|
||||
type MonitorTemplateListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&MonitorTemplateListOptions{}, "monitortemplate-list", "List all monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.MonitorTemplates.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.MonitorTemplates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看监控模板详情
|
||||
*/
|
||||
type MonitorTemplateShowOptions struct {
|
||||
options.BaseListOptions
|
||||
ID string `help:"The ID of the monitor-template"`
|
||||
}
|
||||
R(&MonitorTemplateShowOptions{}, "monitortemplate-show", "Show monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateShowOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.MonitorTemplates.Get(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看模板下的监控项
|
||||
*/
|
||||
type MonitorTemplateMonitorInputsListOptions struct {
|
||||
MONITOR_TEMPLATE_ID string `help:"The ID of the monitor-template"`
|
||||
}
|
||||
R(&MonitorTemplateMonitorInputsListOptions{}, "monitortemplate-monitorinput-list", "Get monitor-inputs of a monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateMonitorInputsListOptions) error {
|
||||
result, err := modules.MonitorTemplateInputs.ListDescendent(s, args.MONITOR_TEMPLATE_ID, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.MonitorInputs.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 更新监控模板信息
|
||||
*/
|
||||
type MonitorTemplateUpdateOptions struct {
|
||||
ID string `help:"The ID of the monitor-template"`
|
||||
NAME string `help:"The name of the monitor-template"`
|
||||
Desc string `help:"Description of the monitor-template"`
|
||||
MonitorInputs []string `help:"Monitor-inputs attached to the monitor-template"`
|
||||
}
|
||||
R(&MonitorTemplateUpdateOptions{}, "monitortemplate-update", "Update a monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "monitor_template_name")
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "monitor_template_desc")
|
||||
}
|
||||
if len(args.MonitorInputs) > 0 {
|
||||
monitors := jsonutils.NewDict()
|
||||
for _, f := range args.MonitorInputs {
|
||||
parts := strings.Split(f, "=")
|
||||
monitors.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
params.Add(monitors, "monitors")
|
||||
}
|
||||
|
||||
monitortemplate, err := modules.MonitorTemplates.Put(s, args.ID, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(monitortemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 向监控模板中添加监控项
|
||||
*/
|
||||
type MonitorTemplateMonitorInputsOptions struct {
|
||||
MONITOR_TEMPLATE_ID string `help:"The ID of the monitor-template"`
|
||||
MONITOR_INPUT_NAME string `help:"The name of the monitor-input"`
|
||||
MonitorConfig string `help:"The config of the monitor-input"`
|
||||
}
|
||||
R(&MonitorTemplateMonitorInputsOptions{}, "monitortemplate-attach-monitorinput", "Add a monitor-input to a monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateMonitorInputsOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.MonitorConfig) > 0 {
|
||||
|
||||
params.Add(jsonutils.NewString(args.MonitorConfig), "monitor_conf_value")
|
||||
}
|
||||
|
||||
monitor_template_inputs, err := modules.MonitorTemplateInputs.Update(s, args.MONITOR_TEMPLATE_ID, args.MONITOR_INPUT_NAME, nil, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(monitor_template_inputs)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 从监控模板中删除监控项
|
||||
*/
|
||||
R(&MonitorTemplateMonitorInputsOptions{}, "monitortemplate-detach-monitorinput", "Add a monitor-input to a monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateMonitorInputsOptions) error {
|
||||
_, err := modules.MonitorInputs.DeleteInContext(s, args.MONITOR_INPUT_NAME, nil, &modules.MonitorTemplates, args.MONITOR_TEMPLATE_ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除监控模板
|
||||
*/
|
||||
type MonitorTemplateDeleteOptions struct {
|
||||
ID string `help:"The ID of the monitor-template"`
|
||||
}
|
||||
R(&MonitorTemplateDeleteOptions{}, "monitortemplate-delete", "Delete a monitor-template", func(s *mcclient.ClientSession, args *MonitorTemplateDeleteOptions) error {
|
||||
monitortemplate, e := modules.MonitorInputs.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
printObject(monitortemplate)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 查看所有的监控节点 | 列出匹配标签的节点列表
|
||||
*/
|
||||
type NodeListOptions struct {
|
||||
options.BaseListOptions
|
||||
Labels []string `help:"Node labels"`
|
||||
}
|
||||
R(&NodeListOptions{}, "node-list", "List all nodes", func(s *mcclient.ClientSession, args *NodeListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
if len(args.Labels) > 0 {
|
||||
for _, f := range args.Labels {
|
||||
parts := strings.Split(f, "=")
|
||||
params.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.Nodes.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Nodes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看节点的标签
|
||||
*/
|
||||
type NodeBaseOptions struct {
|
||||
ID string `help:"ID of the node"`
|
||||
}
|
||||
R(&NodeBaseOptions{}, "list-labels-for-node", "List labels for the node", func(s *mcclient.ClientSession, args *NodeBaseOptions) error {
|
||||
result, err := modules.Labels.ListInContext(s, nil, &modules.Nodes, args.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Labels.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 新增标签
|
||||
*/
|
||||
type NodeLabelsAddOptions struct {
|
||||
ID string `help:"ID of node"`
|
||||
LABELS []string `help:"Node labels"`
|
||||
}
|
||||
R(&NodeLabelsAddOptions{}, "add-labels-to-node", "Add labels to node", func(s *mcclient.ClientSession, args *NodeLabelsAddOptions) error {
|
||||
labels := jsonutils.NewDict()
|
||||
for _, f := range args.LABELS {
|
||||
parts := strings.Split(f, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(labels, "labels")
|
||||
|
||||
_, err := modules.Nodes.PerformAction(s, args.ID, "add-labels", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 批量新增标签
|
||||
*/
|
||||
type NodeLabelsBatchOptions struct {
|
||||
NAMES []string `help:"Node names"`
|
||||
Labels []string `help:"Node labels" nargs:"+"`
|
||||
}
|
||||
R(&NodeLabelsBatchOptions{}, "batch-add-labels-to-node", "Batch add labels to nodes", func(s *mcclient.ClientSession, args *NodeLabelsBatchOptions) error {
|
||||
nodes := jsonutils.NewArray()
|
||||
labels := jsonutils.NewDict()
|
||||
|
||||
for _, n := range args.NAMES {
|
||||
nodes.Add(jsonutils.NewString(n))
|
||||
}
|
||||
|
||||
for _, l := range args.Labels {
|
||||
parts := strings.Split(l, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(nodes, "nodes")
|
||||
params.Add(labels, "labels")
|
||||
|
||||
ret := modules.Nodes.BatchPerformActionInContexts(s, args.NAMES, "add-labels", params, nil)
|
||||
printBatchResults(ret, modules.Nodes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 移除标签
|
||||
*/
|
||||
type NodeLabelRemoveOptions struct {
|
||||
ID string `help:"ID of node"`
|
||||
LABELS []string `help:"Node labels"`
|
||||
}
|
||||
R(&NodeLabelRemoveOptions{}, "remove-labels-from-node", "Remove labels from node", func(s *mcclient.ClientSession, args *NodeLabelRemoveOptions) error {
|
||||
labels := jsonutils.NewDict()
|
||||
for _, f := range args.LABELS {
|
||||
parts := strings.Split(f, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(labels, "labels")
|
||||
|
||||
_, err := modules.Nodes.PerformAction(s, args.ID, "remove-labels", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 批量移除标签
|
||||
*/
|
||||
R(&NodeLabelsBatchOptions{}, "batch-remove-labels-from-node", "Batch remove labels from nodes", func(s *mcclient.ClientSession, args *NodeLabelsBatchOptions) error {
|
||||
nodes := jsonutils.NewArray()
|
||||
labels := jsonutils.NewDict()
|
||||
|
||||
for _, n := range args.NAMES {
|
||||
nodes.Add(jsonutils.NewString(n))
|
||||
}
|
||||
|
||||
for _, l := range args.Labels {
|
||||
parts := strings.Split(l, "=")
|
||||
labels.Add(jsonutils.NewString(parts[1]), parts[0])
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(nodes, "nodes")
|
||||
params.Add(labels, "labels")
|
||||
|
||||
ret := modules.Nodes.BatchPerformActionInContexts(s, args.NAMES, "remove-labels", params, nil)
|
||||
printBatchResults(ret, modules.Nodes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type NodeCreateOptions struct {
|
||||
NAME string `help:"Node name"`
|
||||
IP string `help:"Node IP"`
|
||||
ResType string `help:"Resource type" choices:"host|guest"`
|
||||
}
|
||||
R(&NodeCreateOptions{}, "node-create", "Create a monitor node record", func(s *mcclient.ClientSession, args *NodeCreateOptions) error {
|
||||
data, err := modules.Nodes.NewNode(s, args.NAME, args.IP, args.ResType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(data)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type Top5Options struct {
|
||||
NODE_LABELS string `help:"Service tree tree-node labels"`
|
||||
}
|
||||
R(&Top5Options{}, "performance-top5", "Show performance top5", func(s *mcclient.ClientSession, args *Top5Options) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NODE_LABELS), "node_labels")
|
||||
|
||||
result, err := modules.Performances.GetTop5(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出所有监控指标
|
||||
*/
|
||||
type ProjectAdminListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ProjectAdminListOptions{}, "projectadmin-list", "List all Project Admins", func(s *mcclient.ClientSession, args *ProjectAdminListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.ProjectAdmin.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.ProjectAdmin.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出所有监控指标
|
||||
*/
|
||||
type ProjectAdminCandidateListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ProjectAdminCandidateListOptions{}, "projectadmincandidate-list", "List all Project Admin Candidates", func(s *mcclient.ClientSession, args *ProjectAdminCandidateListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.ProjectAdminCandidate.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.ProjectAdminCandidate.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* move host to one tree-node
|
||||
*/
|
||||
type ProjectHostCreateOptions struct {
|
||||
LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
HOST_NAME []string `help:"Host names to move to"`
|
||||
}
|
||||
R(&ProjectHostCreateOptions{}, "projecthost-create", "move host to tree-node", func(s *mcclient.ClientSession, args *ProjectHostCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
arr := jsonutils.NewArray()
|
||||
if len(args.HOST_NAME) > 0 {
|
||||
for _, f := range args.HOST_NAME {
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(f), "host_name")
|
||||
arr.Add(tmpObj)
|
||||
}
|
||||
}
|
||||
params.Add(arr, "service_hosts")
|
||||
|
||||
rst, err := modules.ProjectHosts.Create(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 向服务树节点添加报警接收人
|
||||
*/
|
||||
type TreeNodeRecipientsCreateOptions struct {
|
||||
NODE_LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
USER_TYPE string `help:"User type, user|group "`
|
||||
RECIPIENT_ID string `help:"User id or group id"`
|
||||
RECIPIENT_TYPE string `help:"junior(slight) or senior(serious)"`
|
||||
}
|
||||
R(&TreeNodeRecipientsCreateOptions{}, "treenode-recipient-create", "Add recipients to tree-node", func(s *mcclient.ClientSession, args *TreeNodeRecipientsCreateOptions) error {
|
||||
arr := jsonutils.NewArray()
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(args.RECIPIENT_ID), "recipient_id")
|
||||
tmpObj.Add(jsonutils.NewString(args.USER_TYPE), "type")
|
||||
arr.Add(tmpObj)
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NODE_LABELS), "node_labels")
|
||||
params.Add(jsonutils.NewString(args.RECIPIENT_TYPE), "recipient_type")
|
||||
params.Add(arr, "recipients")
|
||||
|
||||
rst, err := modules.Recipients.Create(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 从服务树节点移除报警接收人
|
||||
*/
|
||||
type TreeNodeRecipientsDeleteOptions struct {
|
||||
NODE_LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
USER_TYPE string `help:"User type, user|group "`
|
||||
RECIPIENT_ID string `help:"User id or group id"`
|
||||
RECIPIENT_TYPE string `help:"junior(slight) or senior(serious)"`
|
||||
}
|
||||
R(&TreeNodeRecipientsDeleteOptions{}, "treenode-recipient-delete", "Remove recipients from tree-node", func(s *mcclient.ClientSession, args *TreeNodeRecipientsDeleteOptions) error {
|
||||
arr := jsonutils.NewArray()
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(args.RECIPIENT_ID), "recipient_id")
|
||||
tmpObj.Add(jsonutils.NewString(args.RECIPIENT_TYPE), "recipient_type")
|
||||
tmpObj.Add(jsonutils.NewString(args.USER_TYPE), "type")
|
||||
arr.Add(tmpObj)
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NODE_LABELS), "node_labels")
|
||||
params.Add(arr, "recipients")
|
||||
|
||||
rst, err := modules.Recipients.DoDeleteRecipient(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查询树节点的报警接收人信息
|
||||
*/
|
||||
type TreeNodeRecipientsListOptions struct {
|
||||
options.BaseListOptions
|
||||
LIST_TYPE string `help:"Type of list: junior|senior"`
|
||||
LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
}
|
||||
R(&TreeNodeRecipientsListOptions{}, "treenode-recipient-list", "List recipient for the tree-node ", func(s *mcclient.ClientSession, args *TreeNodeRecipientsListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
params.Add(jsonutils.NewString(args.LIST_TYPE), "type")
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
|
||||
result, err := modules.Recipients.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.Recipients.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 向指定的服务树节点添加机器
|
||||
*/
|
||||
type ServiceHostCreateOptions struct {
|
||||
LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
HOST_NAME []string `help:"Host names to add to"`
|
||||
}
|
||||
R(&ServiceHostCreateOptions{}, "servicehost-create", "Add host to tree-node", func(s *mcclient.ClientSession, args *ServiceHostCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
arr := jsonutils.NewArray()
|
||||
if len(args.HOST_NAME) > 0 {
|
||||
for _, f := range args.HOST_NAME {
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(f), "host_name")
|
||||
arr.Add(tmpObj)
|
||||
}
|
||||
}
|
||||
params.Add(arr, "service_hosts")
|
||||
|
||||
rst, err := modules.ServiceHosts.Create(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 从服务树节点删除机器
|
||||
*/
|
||||
type ServiceHostDeleteOptions struct {
|
||||
LABELS string `help:"Labels for tree-node(split by comma)"`
|
||||
HOST_NAME []string `help:"Host names to remove from"`
|
||||
}
|
||||
R(&ServiceHostDeleteOptions{}, "servicehost-delete", "Remove host from tree-node", func(s *mcclient.ClientSession, args *ServiceHostDeleteOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.LABELS), "node_labels")
|
||||
arr := jsonutils.NewArray()
|
||||
if len(args.HOST_NAME) > 0 {
|
||||
for _, f := range args.HOST_NAME {
|
||||
tmpObj := jsonutils.NewDict()
|
||||
tmpObj.Add(jsonutils.NewString(f), "host_name")
|
||||
arr.Add(tmpObj)
|
||||
}
|
||||
}
|
||||
params.Add(arr, "service_hosts")
|
||||
|
||||
rst, err := modules.ServiceHosts.DoDeleteServiceHost(s, params)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(rst)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看指定服务树节点的机器
|
||||
*/
|
||||
type ServiceHostListOptions struct {
|
||||
options.BaseListOptions
|
||||
Labels string `help:"Labels for tree-node(split by comma)"`
|
||||
}
|
||||
R(&ServiceHostListOptions{}, "servicehost-list", "List all hosts for the tree-node", func(s *mcclient.ClientSession, args *ServiceHostListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
if len(args.Labels) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Labels), "node_labels")
|
||||
}
|
||||
|
||||
result, err := modules.ServiceHosts.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.ServiceHosts.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 列出所有监控指标
|
||||
*/
|
||||
type ServiceNameSuggestionListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ServiceNameSuggestionListOptions{}, "servicenamesuggestion-list", "List all serviceNameSuggestion", func(s *mcclient.ClientSession, args *ServiceNameSuggestionListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.ServiceNameSuggestion.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printList(result, modules.ServiceNameSuggestion.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建新的服务树
|
||||
*/
|
||||
type ServiceTreeCreateOptions struct {
|
||||
NAME string `help:"Name of the new service tree"`
|
||||
STRUCT string `help:"Struct of the service tree"`
|
||||
Remark string `help:"Remark or description of the new service tree"`
|
||||
}
|
||||
R(&ServiceTreeCreateOptions{}, "servicetree-create", "Create a service tree", func(s *mcclient.ClientSession, args *ServiceTreeCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "service_tree_name")
|
||||
params.Add(jsonutils.NewString(args.STRUCT), "service_tree_struct")
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
serviceTree, err := modules.ServiceTrees.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(serviceTree)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除一个服务树
|
||||
*/
|
||||
type ServiceTreeDeleteOptions struct {
|
||||
ID string `help:"ID of alarm template"`
|
||||
}
|
||||
R(&ServiceTreeDeleteOptions{}, "servicetree-delete", "Delete a service tree", func(s *mcclient.ClientSession, args *ServiceTreeDeleteOptions) error {
|
||||
serviceTree, e := modules.ServiceTrees.Delete(s, args.ID, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printObject(serviceTree)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改服务树的配置信息
|
||||
*/
|
||||
type ServiceTreeUpdateOptions struct {
|
||||
ID string `help:"ID of the service tree"`
|
||||
Name string `help:"Name of the service-tree"`
|
||||
Struct string `help:"Struct of the service-tree"`
|
||||
Remark string `help:"Remark or description of the service-tree"`
|
||||
}
|
||||
R(&ServiceTreeUpdateOptions{}, "servicetree-update", "Update a service tree", func(s *mcclient.ClientSession, args *ServiceTreeUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "service_tree_name")
|
||||
}
|
||||
if len(args.Struct) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Struct), "service_tree_struct")
|
||||
}
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
|
||||
serviceTree, err := modules.ServiceTrees.Patch(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(serviceTree)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 列出服务树
|
||||
*/
|
||||
type ServiceTreeListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ServiceTreeListOptions{}, "servicetree-list", "List all service tree", func(s *mcclient.ClientSession, args *ServiceTreeListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.ServiceTrees.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.ServiceTrees.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看服务树配置详情
|
||||
*/
|
||||
type ServiceTreeShowOptions struct {
|
||||
ID string `help:"ID of the service-tree"`
|
||||
}
|
||||
R(&ServiceTreeShowOptions{}, "servicetree-show", "Show service tree details", func(s *mcclient.ClientSession, args *ServiceTreeShowOptions) error {
|
||||
result, err := modules.ServiceTrees.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/identity"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/servicetree"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
/**
|
||||
* 创建新的服务树节点
|
||||
*/
|
||||
type ServiceTreeCreateOptions struct {
|
||||
NAME string `help:"Name of the new service-tree node"`
|
||||
Pid int64 `help:"PID of the service-tree node" default:"-1"`
|
||||
Label []string `help:"Labels to this node"`
|
||||
Project string `help:"Project id of the if create PDL node"`
|
||||
Remark string `help:"Remark or description of the new service-tree node"`
|
||||
}
|
||||
R(&ServiceTreeCreateOptions{}, "servicetree-node-create", "Create a service-tree node", func(s *mcclient.ClientSession, args *ServiceTreeCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
pid := args.Pid
|
||||
var err error
|
||||
if pid < 0 {
|
||||
if len(args.Label) <= 0 {
|
||||
return fmt.Errorf("Must provide either pid or labels")
|
||||
}
|
||||
pid, err = modules.TreeNodes.GetNodeIDByLabels(s, args.Label)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pid < 0 {
|
||||
return fmt.Errorf("Invalid labels: %s", args.Label)
|
||||
}
|
||||
}
|
||||
params.Add(jsonutils.NewInt(pid), "pid")
|
||||
if len(args.Project) > 0 {
|
||||
projId, err := identity.Projects.GetId(s, args.Project, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Add(jsonutils.NewString(projId), "project_id")
|
||||
}
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
serviceTree, err := modules.TreeNodes.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(serviceTree)
|
||||
return nil
|
||||
})
|
||||
|
||||
type ServiceTreeNodeListOptions struct {
|
||||
options.BaseListOptions
|
||||
Label string `help:"Label of node"`
|
||||
Pid int64 `help:"Pid of node" default:"-1"`
|
||||
}
|
||||
R(&ServiceTreeNodeListOptions{}, "servicetree-node-list", "List servicetree nodes", func(s *mcclient.ClientSession, args *ServiceTreeNodeListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
if args.Pid >= 0 {
|
||||
params.Add(jsonutils.NewInt(args.Pid), "pid")
|
||||
}
|
||||
if len(args.Label) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Label), "name")
|
||||
}
|
||||
result, err := modules.TreeNodes.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.TreeNodes.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 查看服务树节点配置详情
|
||||
*/
|
||||
type ServiceTreeNodeShowOptions struct {
|
||||
Id int64 `help:"ID of tree node"`
|
||||
Label []string `help:"Labels to this tree node"`
|
||||
}
|
||||
R(&ServiceTreeNodeShowOptions{}, "servicetree-node-show", "Show details of a servicetree node", func(s *mcclient.ClientSession, args *ServiceTreeNodeShowOptions) error {
|
||||
pid := args.Id
|
||||
var err error
|
||||
if pid <= 0 {
|
||||
pid, err = modules.TreeNodes.GetNodeIDByLabels(s, args.Label)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pid <= 0 {
|
||||
return fmt.Errorf("Invalid tree node ID")
|
||||
}
|
||||
}
|
||||
idstr := strconv.Itoa(int(pid))
|
||||
result, err := modules.TreeNodes.Get(s, idstr, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改服务树节点配置信息
|
||||
*/
|
||||
type ServiceTreeNodeUpdateOptions struct {
|
||||
ServiceTreeNodeShowOptions
|
||||
Name string `help:"Name of the service-tree"`
|
||||
Project string `help:"Project associate with this tree node"`
|
||||
Remark string `help:"Remark or description of the service-tree"`
|
||||
}
|
||||
R(&ServiceTreeNodeUpdateOptions{}, "servicetree-node-update", "Update a servicetree node", func(s *mcclient.ClientSession, args *ServiceTreeNodeUpdateOptions) error {
|
||||
pid := args.Id
|
||||
var err error
|
||||
if pid <= 0 {
|
||||
pid, err = modules.TreeNodes.GetNodeIDByLabels(s, args.Label)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pid <= 0 {
|
||||
return fmt.Errorf("Invalid tree node ID")
|
||||
}
|
||||
}
|
||||
idstr := strconv.Itoa(int(pid))
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
if len(args.Project) > 0 {
|
||||
projId, err := identity.Projects.GetId(s, args.Project, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Add(jsonutils.NewString(projId), "project_id")
|
||||
}
|
||||
if len(args.Remark) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Remark), "remark")
|
||||
}
|
||||
result, err := modules.TreeNodes.Update(s, idstr, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 修改服务树节点的项目类型
|
||||
*/
|
||||
type ServiceTreeNodeChangeProjectTypeOptions struct {
|
||||
PROJECTID string `help:"ID of project"`
|
||||
PROJECTTYPE string `help:"TYPE of project" choices:"CreateNewProject|RelatedExisting"`
|
||||
}
|
||||
R(&ServiceTreeNodeChangeProjectTypeOptions{}, "servicetree-node-change-project-type", "servicetree-node-change-project-type", func(s *mcclient.ClientSession, args *ServiceTreeNodeChangeProjectTypeOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.PROJECTTYPE), "project_type")
|
||||
_, err := modules.TreeNodes.PerformAction(s, args.PROJECTID, "change-project-type", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
/**
|
||||
* 删除一个服务树节点
|
||||
*/
|
||||
R(&ServiceTreeNodeShowOptions{}, "servicetree-node-delete", "Delete a servicetree node", func(s *mcclient.ClientSession, args *ServiceTreeNodeShowOptions) error {
|
||||
pid := args.Id
|
||||
var err error
|
||||
if pid <= 0 {
|
||||
pid, err = modules.TreeNodes.GetNodeIDByLabels(s, args.Label)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pid <= 0 {
|
||||
return fmt.Errorf("Invalid tree node ID")
|
||||
}
|
||||
}
|
||||
idstr := strconv.Itoa(int(pid))
|
||||
result, err := modules.TreeNodes.Delete(s, idstr, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// 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 servicetree
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudwatcher"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
type UnderutilizedInstancesListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&UnderutilizedInstancesListOptions{}, "underutilized-instances-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
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// 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 suggestion
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/suggestion"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/suggestion"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(modules.AnalysisPredictManager)
|
||||
cmd.Get("", new(options.AnalysisPredictConfigOptions))
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// 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 suggestion
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(monitor.SuggestSysAlertManager)
|
||||
cmd.List(new(options.SuggestSysAlertListOptions))
|
||||
cmd.Show(new(options.SSuggestAlertShowOptions))
|
||||
cmd.Perform("ignore", new(options.SuggestAlertIgnoreOptions))
|
||||
cmd.BatchDelete(new(options.SuggestAlertBatchDeleteOptions))
|
||||
cmd_ := shell.NewResourceCmd(monitor.SuggestSysAlertCostManager)
|
||||
cmd_.Get("", new(options.SuggestAlertCostOptions))
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// 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 suggestion
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/suggestion"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/monitor"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
cmd := shell.NewResourceCmd(modules.SuggestSysRuleManager)
|
||||
cmd.List(new(options.SuggestRuleListOptions))
|
||||
cmd.Show(new(options.SuggestRuleShowOptions))
|
||||
cmd.Perform("enable", new(options.SuggestRuleShowOptions))
|
||||
cmd.Perform("disable", new(options.SuggestRuleShowOptions))
|
||||
cmd.BatchDelete(new(options.CommonAlertDeleteOptions))
|
||||
cmd.Perform("config", new(options.SuggestRuleConfigOptions))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user