fix(region): only kvm use qgs set password in guest running status (#15158)

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2022-10-12 14:55:03 +08:00
committed by GitHub
parent 9f65fd6abb
commit 6d3a592833
2 changed files with 3 additions and 6 deletions
+2 -5
View File
@@ -723,8 +723,7 @@ func (self *SGuest) PerformClone(ctx context.Context, userCred mcclient.TokenCre
}
func (self *SGuest) PerformSetPassword(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerSetPasswordInput) (jsonutils.JSONObject, error) {
switch self.Status {
case api.VM_RUNNING:
if self.Hypervisor == api.HYPERVISOR_KVM && self.Status == api.VM_RUNNING {
inputQga := &api.ServerQgaSetPasswordInput{
Username: input.Username,
Password: input.Password,
@@ -740,15 +739,13 @@ func (self *SGuest) PerformSetPassword(ctx context.Context, userCred mcclient.To
inputQga.Password = seclib2.RandomPassword2(12)
}
return self.PerformQgaSetPassword(ctx, userCred, query, inputQga)
case api.VM_READY:
} else {
inputDeploy := api.ServerDeployInput{
Password: input.Password,
ResetPassword: input.ResetPassword,
AutoStart: input.AutoStart,
}
return self.PerformDeploy(ctx, userCred, query, inputDeploy)
default:
return nil, httperrors.NewServerStatusError("Cannot deploy in status %s", self.Status)
}
}
@@ -98,7 +98,7 @@ func (self *GuestQgaSetPasswordTask) OnQgaSetUserPassword(ctx context.Context, g
guest.SetAllMetadata(ctx, info, self.UserCred)
}
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_SET_USER_PASSWORD, "", self.UserCred, true)
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_SET_USER_PASSWORD, "qga set password success", self.UserCred, true)
self.SetStageComplete(ctx, nil)
}