mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
feat(devtool): support batch applying for virtual machines
This commit is contained in:
@@ -24,6 +24,7 @@ func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.DevToolScripts).WithKeyword("devtool-script")
|
||||
cmd.List(new(options.ScriptListOptions))
|
||||
cmd.Perform("apply", new(options.ScriptApplyOptions))
|
||||
cmd.Perform("batch-apply", new(options.ScriptBatchApplyOptions))
|
||||
cmd1 := shell.NewResourceCmd(&modules.DevToolScriptApplyRecords).WithKeyword("devtool-script-record")
|
||||
cmd1.List(new(options.ScriptApplyRecordListOptions))
|
||||
}
|
||||
|
||||
@@ -29,6 +29,21 @@ type ScriptApplyOutput struct {
|
||||
ScriptApplyId string
|
||||
}
|
||||
|
||||
type ScriptBatchApplyInput struct {
|
||||
ServerIds []string
|
||||
}
|
||||
|
||||
type ScriptBatchApplyOutput struct {
|
||||
Results []ScriptBatchApplyResult
|
||||
}
|
||||
|
||||
type ScriptBatchApplyResult struct {
|
||||
ServerId string
|
||||
Succeed bool
|
||||
Reason string
|
||||
ScriptApplyId string
|
||||
}
|
||||
|
||||
type ScriptApplyRecoredListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
// description: Id of Script
|
||||
|
||||
@@ -152,6 +152,36 @@ func (s *SScript) PerformApply(ctx context.Context, userCred mcclient.TokenCrede
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (s *SScript) AllowPerformBatchApply(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return s.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, s, "batch-apply")
|
||||
}
|
||||
|
||||
func (s *SScript) PerformBatchApply(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ScriptBatchApplyInput) (api.ScriptBatchApplyOutput, error) {
|
||||
output := api.ScriptBatchApplyOutput{
|
||||
Results: make([]api.ScriptBatchApplyResult, len(input.ServerIds)),
|
||||
}
|
||||
var argsGenerator string
|
||||
if s.Name == MonitorAgent {
|
||||
argsGenerator = MonitorAgent
|
||||
}
|
||||
for i, serverId := range input.ServerIds {
|
||||
output.Results[i].ServerId = serverId
|
||||
sa, err := ScriptApplyManager.createScriptApply(ctx, s.Id, serverId, nil, argsGenerator)
|
||||
if err != nil {
|
||||
output.Results[i].Reason = err.Error()
|
||||
continue
|
||||
}
|
||||
err = sa.StartApply(ctx, userCred)
|
||||
if err != nil {
|
||||
output.Results[i].Reason = err.Error()
|
||||
continue
|
||||
}
|
||||
output.Results[i].Succeed = true
|
||||
output.Results[i].ScriptApplyId = sa.Id
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
type sServerInfo struct {
|
||||
ServerId string
|
||||
VpcId string
|
||||
|
||||
@@ -41,10 +41,7 @@ func (so *ScriptOptions) Params() (jsonutils.JSONObject, error) {
|
||||
}
|
||||
|
||||
type SscriptApplyOptions struct {
|
||||
SERVERID string `help:"server id" json:"server_id"`
|
||||
EipFirst bool `help:"whether to use eip first"`
|
||||
ProxyEndpointId string `help:"proxy endpoint id"`
|
||||
AutoChooseProxyEndpoint bool `help:"automatically choose proxy endpoint"`
|
||||
SERVERID string `help:"server id" json:"server_id"`
|
||||
}
|
||||
|
||||
type ScriptApplyOptions struct {
|
||||
@@ -56,6 +53,19 @@ func (so *ScriptApplyOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(so.SscriptApplyOptions), nil
|
||||
}
|
||||
|
||||
type SscriptBatchApplyOptions struct {
|
||||
ServerIds []string `help:"server id list"`
|
||||
}
|
||||
|
||||
type ScriptBatchApplyOptions struct {
|
||||
ScriptOptions
|
||||
SscriptBatchApplyOptions
|
||||
}
|
||||
|
||||
func (so *ScriptBatchApplyOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(so.SscriptBatchApplyOptions), nil
|
||||
}
|
||||
|
||||
type ScriptApplyRecordListOptions struct {
|
||||
options.BaseListOptions
|
||||
ScriptId string
|
||||
|
||||
Reference in New Issue
Block a user