Fix/deploy reset password support loginaccount (#20594)

* fix(host): lvm resize add encrypt support

* fix(region): deploy reset password add loginaccount
This commit is contained in:
wanyaoqi
2024-06-25 10:56:44 +08:00
committed by GitHub
parent b14879faab
commit 11ee966fbc
4 changed files with 44 additions and 3 deletions
+2
View File
@@ -748,6 +748,8 @@ type ServerDeployInputBase struct {
ResetPassword bool `json:"reset_password"`
// 重置指定密码
Password string `json:"password"`
// swagger: ignore
LoginAccount string `json:"login_account"`
// swagger: ignore
Restart bool `json:"restart"`
+22
View File
@@ -745,6 +745,9 @@ func (self *SGuest) PerformSetPassword(ctx context.Context, userCred mcclient.To
inputDeploy.AutoStart = input.AutoStart
inputDeploy.Password = input.Password
inputDeploy.ResetPassword = input.ResetPassword
if input.Username != "" {
inputDeploy.LoginAccount = input.Username
}
return self.PerformDeploy(ctx, userCred, query, inputDeploy)
}
}
@@ -821,6 +824,15 @@ func (self *SGuest) PerformDeploy(
// 变更密码/密钥时需要Restart才能生效。更新普通字段不需要Restart, Azure需要在运行状态下操作
doRestart := false
if input.ResetPassword {
if len(input.LoginAccount) > 0 {
if len(input.LoginAccount) > 32 {
return nil, httperrors.NewInputParameterError("login_account is longer than 32 chars")
}
if err := GuestManager.ValidateNameLoginAccount(input.LoginAccount); err != nil {
return nil, err
}
}
doRestart = self.GetDriver().IsNeedRestartForResetLoginInfo()
}
@@ -1703,6 +1715,16 @@ func (self *SGuest) PerformRebuildRoot(
}
input.ResetPassword = resetPasswd
if input.ResetPassword {
if len(input.LoginAccount) > 0 {
if len(input.LoginAccount) > 32 {
return nil, httperrors.NewInputParameterError("login_account is longer than 32 chars")
}
if err := GuestManager.ValidateNameLoginAccount(input.LoginAccount); err != nil {
return nil, err
}
}
}
return nil, self.StartRebuildRootTask(ctx, userCred, input.ImageId, needStop, autoStart, allDisks, &input.ServerDeployInputBase)
}
+17 -3
View File
@@ -276,14 +276,28 @@ func (d *SLVMDisk) Resize(ctx context.Context, params interface{}) (jsonutils.JS
if err != nil {
return nil, errors.Wrap(err, "lv resize")
}
resizeFsInfo := &deployapi.DiskInfo{
Path: d.GetPath(),
}
if diskInfo.Contains("encrypt_info") {
var encryptInfo apis.SEncryptInfo
err := diskInfo.Unmarshal(&encryptInfo, "encrypt_info")
if err != nil {
log.Errorf("fail to fetch encryptInfo %s", err)
return nil, errors.Wrap(err, "Unmarshal encrpt_info")
} else {
qemuImg.SetPassword(encryptInfo.Key)
resizeFsInfo.EncryptPassword = encryptInfo.Key
resizeFsInfo.EncryptAlg = string(encryptInfo.Alg)
}
}
err = qemuImg.Resize(int(sizeMb))
if err != nil {
return nil, errors.Wrap(err, "qemuImg resize")
}
resizeFsInfo := &deployapi.DiskInfo{
Path: d.GetPath(),
}
if err := d.ResizeFs(resizeFsInfo); err != nil {
log.Errorf("Resize fs %s fail %s", d.GetPath(), err)
}
+3
View File
@@ -731,6 +731,7 @@ type ServerDeployOptions struct {
Deploy []string `help:"Specify deploy files in virtual server file system" json:"-"`
ResetPassword bool `help:"Force reset password"`
Password string `help:"Default user password"`
LoginAccount string `help:"Guest login account"`
AutoStart bool `help:"Auto start server after deployed"`
DeployTelegraf bool `help:"Deploy telegraf if guest os supported"`
}
@@ -747,6 +748,7 @@ func (opts *ServerDeployOptions) Params() (jsonutils.JSONObject, error) {
params.ResetPassword = opts.ResetPassword
params.Password = opts.Password
params.DeployTelegraf = opts.DeployTelegraf
params.LoginAccount = opts.LoginAccount
}
{
deployInfos, err := ParseServerDeployInfoList(opts.Deploy)
@@ -979,6 +981,7 @@ type ServerRebuildRootOptions struct {
ImageId string `help:"New root Image template ID" json:"image_id" token:"image"`
Keypair string `help:"ssh Keypair used for login"`
Password string `help:"Default user password"`
LoginAccount string `help:"Guest login account"`
NoAccountInit *bool `help:"Not reset account password"`
AutoStart *bool `help:"Auto start server after it is created"`
AllDisks *bool `help:"Rebuild all disks including data disks"`