region: storage support set schedtags (#223)

This commit is contained in:
Zexi Li
2019-04-08 10:25:31 +08:00
committed by yunion-ci-robot
parent bf0274779b
commit 599aa4a6f6
8 changed files with 191 additions and 99 deletions
-17
View File
@@ -518,21 +518,4 @@ func init() {
printObject(result)
return nil
})
type HostSetSchedtagOptions struct {
ID string `help:"ID or Name of host"`
Schedtag []string `help:"Ids of schedtag"`
}
R(&HostSetSchedtagOptions{}, "host-set-schedtag", "Set schedtags to a host", func(s *mcclient.ClientSession, args *HostSetSchedtagOptions) error {
params := jsonutils.NewDict()
for idx, tag := range args.Schedtag {
params.Add(jsonutils.NewString(tag), fmt.Sprintf("schedtag.%d", idx))
}
result, err := modules.Hosts.PerformAction(s, args.ID, "set-schedtag", params)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+20
View File
@@ -35,6 +35,7 @@ func (h *schedtagModelHelper) register() {
h.list(man.Slave, man.Slave.GetKeyword())
h.add(man, man.Slave.GetKeyword())
h.remove(man, man.Slave.GetKeyword())
h.setTags(man, man.Slave.GetKeyword())
}
}
@@ -97,6 +98,25 @@ func (h *schedtagModelHelper) remove(man modules.JointResourceManager, kw string
})
}
func (h *schedtagModelHelper) setTags(man modules.JointResourceManager, kw string) {
R(
&options.SchedtagSetOptions{},
fmt.Sprintf("%s-set-schedtag", kw),
fmt.Sprintf("Set schedtags to %v", kw),
func(s *mcclient.ClientSession, args *options.SchedtagSetOptions) error {
params, err := args.Params()
if err != nil {
return err
}
ret, err := man.Slave.PerformAction(s, args.ID, "set-schedtag", params)
if err != nil {
return err
}
printObject(ret)
return nil
})
}
func init() {
newSchedtagModelHelper(
modules.Schedtaghosts,
-1
View File
@@ -228,5 +228,4 @@ func init() {
printObject(storage)
return nil
})
}