mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #3754 from wanyaoqi/bugfix/wyq/instance-snapshot-1118
bugfix: fix login key incorrect on clone
This commit is contained in:
@@ -4252,8 +4252,7 @@ func (self *SGuest) StartInstanceSnapshotAndCloneTask(
|
||||
}
|
||||
|
||||
func (manager *SGuestManager) CreateGuestFromInstanceSnapshot(
|
||||
ctx context.Context, userCred mcclient.TokenCredential, guestParams *jsonutils.JSONDict,
|
||||
isp *SInstanceSnapshot, index int,
|
||||
ctx context.Context, userCred mcclient.TokenCredential, guestParams *jsonutils.JSONDict, isp *SInstanceSnapshot,
|
||||
) (*SGuest, *jsonutils.JSONDict, error) {
|
||||
lockman.LockClass(ctx, manager, isp.ProjectId)
|
||||
defer lockman.ReleaseClass(ctx, manager, isp.ProjectId)
|
||||
@@ -4262,7 +4261,7 @@ func (manager *SGuestManager) CreateGuestFromInstanceSnapshot(
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("No new guest name provider")
|
||||
}
|
||||
if guestName, err = db.GenerateName2(manager, isp.GetOwnerId(), guestName, nil, index); err != nil {
|
||||
if guestName, err = db.GenerateName(manager, isp.GetOwnerId(), guestName); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -4276,6 +4275,10 @@ func (manager *SGuestManager) CreateGuestFromInstanceSnapshot(
|
||||
if isp.ServerMetadata != nil {
|
||||
metadata := make(map[string]interface{}, 0)
|
||||
isp.ServerMetadata.Unmarshal(metadata)
|
||||
if passwd, ok := metadata["passwd"]; ok {
|
||||
delete(metadata, "passwd")
|
||||
metadata["login_key"], _ = utils.EncryptAESBase64(guest.Id, passwd.(string))
|
||||
}
|
||||
metadata["__base_instance_snapshot_id"] = isp.Id
|
||||
guest.SetAllMetadata(ctx, metadata, userCred)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -170,8 +171,12 @@ func (manager *SInstanceSnapshotManager) CreateInstanceSnapshot(
|
||||
instanceSnapshot.ServerConfig = jsonutils.Marshal(guestSchedInput.ServerConfig)
|
||||
serverMetadata := jsonutils.NewDict()
|
||||
if loginAccount := guest.GetMetadata("login_account", nil); len(loginAccount) > 0 {
|
||||
serverMetadata.Set("login_account", jsonutils.NewString(loginAccount))
|
||||
serverMetadata.Set("login_key", jsonutils.NewString(guest.GetMetadata("login_key", nil)))
|
||||
loginKey := guest.GetMetadata("login_key", nil)
|
||||
passwd, e := utils.DescryptAESBase64(guest.Id, loginKey)
|
||||
if e == nil {
|
||||
serverMetadata.Set("login_account", jsonutils.NewString(loginAccount))
|
||||
serverMetadata.Set("passwd", jsonutils.NewString(passwd))
|
||||
}
|
||||
}
|
||||
if osArch := guest.GetMetadata("os_arch", nil); len(osArch) > 0 {
|
||||
serverMetadata.Set("os_arch", jsonutils.NewString(osArch))
|
||||
|
||||
@@ -121,7 +121,7 @@ func (self *InstanceSnapshotAndCloneTask) doGuestCreate(
|
||||
)
|
||||
for i := 0; i < count; i++ {
|
||||
newGuest, input, err := models.GuestManager.CreateGuestFromInstanceSnapshot(
|
||||
ctx, self.UserCred, dictParmas.DeepCopy().(*jsonutils.JSONDict), isp, i+1)
|
||||
ctx, self.UserCred, dictParmas.DeepCopy().(*jsonutils.JSONDict), isp)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
errStr += err.Error() + "\n"
|
||||
|
||||
@@ -232,6 +232,7 @@ func (s *SDeployService) PrepareEnv() error {
|
||||
}
|
||||
nbd.Init()
|
||||
|
||||
// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-bdi
|
||||
for i := 0; i < 16; i++ {
|
||||
nbdBdi := fmt.Sprintf("/sys/block/nbd%d/bdi/", i)
|
||||
sysutils.SetSysConfig(nbdBdi+"max_ratio", "0")
|
||||
|
||||
Reference in New Issue
Block a user