diff --git a/pkg/compute/guestdrivers/base.go b/pkg/compute/guestdrivers/base.go index 57ad930a22..0277cfee2c 100644 --- a/pkg/compute/guestdrivers/base.go +++ b/pkg/compute/guestdrivers/base.go @@ -314,6 +314,10 @@ func (self *SBaseGuestDriver) IsWindowsUserDataTypeNeedEncode() bool { return false } +func (self *SBaseGuestDriver) IsSupportdDcryptPasswordFromSecretKey() bool { + return true +} + func (self *SBaseGuestDriver) GetUserDataType() string { return cloudprovider.CLOUD_CONFIG } diff --git a/pkg/compute/guestdrivers/qcloud.go b/pkg/compute/guestdrivers/qcloud.go index 32b875912d..d8938899dc 100644 --- a/pkg/compute/guestdrivers/qcloud.go +++ b/pkg/compute/guestdrivers/qcloud.go @@ -226,6 +226,10 @@ func (self *SQcloudGuestDriver) GetGuestInitialStateAfterRebuild() string { return api.VM_RUNNING } +func (self *SQcloudGuestDriver) IsSupportdDcryptPasswordFromSecretKey() bool { + return false +} + func (self *SQcloudGuestDriver) GetUserDataType() string { return cloudprovider.CLOUD_SHELL } diff --git a/pkg/compute/models/guestdrivers.go b/pkg/compute/models/guestdrivers.go index 2ee79197bc..226e11aa16 100644 --- a/pkg/compute/models/guestdrivers.go +++ b/pkg/compute/models/guestdrivers.go @@ -142,6 +142,8 @@ type IGuestDriver interface { IsRebuildRootSupportChangeImage() bool IsRebuildRootSupportChangeUEFI() bool + IsSupportdDcryptPasswordFromSecretKey() bool + RequestDeleteDetachedDisk(ctx context.Context, disk *SDisk, task taskman.ITask, isPurge bool) error StartGuestDetachdiskTask(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, params *jsonutils.JSONDict, parentTaskId string) error StartGuestAttachDiskTask(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, params *jsonutils.JSONDict, parentTaskId string) error diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 3d1acd0aa9..791d8195a7 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -4271,40 +4271,49 @@ func (self *SGuest) saveOsType(userCred mcclient.TokenCredential, osType string) return err } +type sDeployInfo struct { + Os string + Account string + Key string + Distro string + Version string + Arch string + Language string +} + func (self *SGuest) SaveDeployInfo(ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject) { + deployInfo := sDeployInfo{} + data.Unmarshal(&deployInfo) info := make(map[string]interface{}) - if data.Contains("os") { - osName, _ := data.GetString("os") - self.saveOsType(userCred, osName) - info["os_name"] = osName + if len(deployInfo.Os) > 0 { + self.saveOsType(userCred, deployInfo.Os) + info["os_name"] = deployInfo.Os } - if data.Contains("account") { - account, _ := data.GetString("account") - info["login_account"] = account - if data.Contains("key") { - key, _ := data.GetString("key") - info["login_key"] = key + driver := self.GetDriver() + if len(deployInfo.Account) > 0 { + info["login_account"] = deployInfo.Account + if len(deployInfo.Key) > 0 { + info["login_key"] = deployInfo.Key + if len(self.KeypairId) > 0 && !driver.IsSupportdDcryptPasswordFromSecretKey() { // Tencent Cloud does not support simultaneous setting of secret keys and passwords + info["login_key"], _ = seclib2.EncryptBase64(self.GetKeypairPublicKey(), "") + } info["login_key_timestamp"] = timeutils.UtcNow() } else { info["login_key"] = "none" info["login_key_timestamp"] = "none" } } - if data.Contains("distro") { - dist, _ := data.GetString("distro") - info["os_distribution"] = dist + if len(deployInfo.Distro) > 0 { + info["os_distribution"] = deployInfo.Distro } - if data.Contains("version") { - ver, _ := data.GetString("version") - info["os_version"] = ver + if len(deployInfo.Version) > 0 { + info["os_version"] = deployInfo.Version } - if data.Contains("arch") { - arch, _ := data.GetString("arch") - info["os_arch"] = arch + if len(deployInfo.Arch) > 0 { + info["os_arch"] = deployInfo.Arch } - if data.Contains("language") { - lang, _ := data.GetString("language") - info["os_language"] = lang + if len(deployInfo.Language) > 0 { + info["os_language"] = deployInfo.Language } self.SetAllMetadata(ctx, info, userCred) self.saveOldPassword(ctx, userCred)