mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automated cherry pick of #20595: Automated cherry pick of #20594: Fix/deploy reset password support loginaccount (#20596)
* fix(host): lvm resize add encrypt support * fix(region): deploy reset password add loginaccount
This commit is contained in:
@@ -753,6 +753,8 @@ type ServerDeployInputBase struct {
|
||||
// 支持特殊user data平台: Aliyun, Qcloud, Azure, Apsara, Ucloud
|
||||
// required: false
|
||||
UserData string `json:"user_data"`
|
||||
// swagger: ignore
|
||||
LoginAccount string `json:"login_account"`
|
||||
|
||||
// swagger: ignore
|
||||
Restart bool `json:"restart"`
|
||||
|
||||
@@ -779,6 +779,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)
|
||||
}
|
||||
}
|
||||
@@ -861,6 +864,14 @@ func (self *SGuest) PerformDeploy(
|
||||
doRestart := false
|
||||
if input.ResetPassword {
|
||||
doRestart = driver.IsNeedRestartForResetLoginInfo()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deployStatus, err := driver.GetDeployStatus()
|
||||
@@ -1806,6 +1817,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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -744,6 +744,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"`
|
||||
}
|
||||
@@ -760,6 +761,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)
|
||||
@@ -992,6 +994,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"`
|
||||
|
||||
Reference in New Issue
Block a user