zhengjiajie add the post method of project_host

This commit is contained in:
zhengjiajie
2018-09-20 19:10:51 +08:00
parent 7863b7c085
commit 8716cf3122
2 changed files with 61 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
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
})
}
+21
View File
@@ -0,0 +1,21 @@
package modules
import (
)
type ProjectNodeManager struct {
ResourceManager
}
var (
ProjectHosts ProjectNodeManager
)
func init() {
ProjectHosts = ProjectNodeManager{NewMonitorManager("project_host", "project_hosts",
[]string{"id", "host_id", "host_name", "ip", "vcpu_count", "vmem_size", "disk", "project", "status", "create_by", "update_by", "delete_by", "gmt_create", "gmt_modified", "gmt_delete", "project_id", "remark"},
[]string{})}
register(&ProjectHosts)
}