From 6b4c215d667a15d71ecd4cea9abbe01b2d5dffb9 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Sun, 26 Apr 2020 20:52:42 +0800 Subject: [PATCH] host fix cmt bound, minor fix --- pkg/apis/compute/guest_const.go | 1 + pkg/apis/compute/host.go | 4 ++++ pkg/cloudcommon/db/caller.go | 4 ++-- pkg/cloudcommon/db/standalone.go | 6 ++++++ pkg/compute/models/hosts.go | 4 ++-- pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go | 9 +++++---- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index 5a45399ca4..d7291ff76c 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -135,6 +135,7 @@ const ( VM_CONVERT = "convert" VM_CONVERTING = "converting" VM_CONVERT_FAILED = "convert_failed" + VM_CONVERTED = "converted" SHUTDOWN_STOP = "stop" SHUTDOWN_TERMINATE = "terminate" diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index 7c3ebb267a..2e021e472b 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -143,6 +143,10 @@ type HostDetails struct { CpuCommitRate float64 `json:"cpu_commit_rate"` // 内存超分率 MemCommitRate float64 `json:"mem_commit_rate"` + // CPU超售比 + CpuCommitBound float32 `json:"cpu_commit_bound"` + // 内存超售比 + MemCommitBound float32 `json:"mem_commint_bound"` // 存储大小 Storage int64 `json:"storage"` // 已使用存储大小 diff --git a/pkg/cloudcommon/db/caller.go b/pkg/cloudcommon/db/caller.go index 91e7d5245e..2e97300cf4 100644 --- a/pkg/cloudcommon/db/caller.go +++ b/pkg/cloudcommon/db/caller.go @@ -291,8 +291,8 @@ func FetchCustomizeColumns( } retVal := make([]*jsonutils.JSONDict, ret[0].Len()) for i := 0; i < ret[0].Len(); i += 1 { - jsonDict := jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict) - jsonDict.Update(ValueToJSONDict(ret[0].Index(i))) + jsonDict := ValueToJSONDict(ret[0].Index(i)) + jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict)) retVal[i] = jsonDict } return retVal, nil diff --git a/pkg/cloudcommon/db/standalone.go b/pkg/cloudcommon/db/standalone.go index 0bdd420852..cf1aa27afa 100644 --- a/pkg/cloudcommon/db/standalone.go +++ b/pkg/cloudcommon/db/standalone.go @@ -417,6 +417,12 @@ func (model *SStandaloneResourceBase) AllowPerformSetUserMetadata(ctx context.Co func (model *SStandaloneResourceBase) PerformSetUserMetadata(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformSetUserMetadataInput) (jsonutils.JSONObject, error) { dictStore := make(map[string]interface{}) for k, v := range input { + if len(k) > 64-len(USER_TAG_PREFIX) { + return nil, httperrors.NewInputParameterError("input key too long > %d", 64-len(USER_TAG_PREFIX)) + } + if len(v) > 65535 { + return nil, httperrors.NewInputParameterError("input value too long > %d", 65535) + } dictStore[USER_TAG_PREFIX+k] = v } err := model.SetUserMetadataAll(ctx, dictStore, userCred) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 32389e3cd3..3c7caf2b99 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -2585,8 +2585,8 @@ func (self *SHost) getMoreDetails(ctx context.Context, out api.HostDetails, show out.Spec = self.GetHardwareSpecification() // custom cpu mem commit bound - out.CpuCmtbound = self.GetCPUOvercommitBound() - out.MemCmtbound = self.GetMemoryOvercommitBound() + out.CpuCommitBound = self.GetCPUOvercommitBound() + out.MemCommitBound = self.GetMemoryOvercommitBound() // extra = self.SManagedResourceBase.getExtraDetails(ctx, extra) diff --git a/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go b/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go index c49bfe59ed..1f8e95e986 100644 --- a/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go +++ b/pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go @@ -72,6 +72,7 @@ func (self *GuestConvertEsxiToKvmTask) taskFailed(ctx context.Context, guest *mo targetGuest.SetStatus(self.UserCred, api.VM_CONVERT_FAILED, reason) db.OpsLog.LogEvent(guest, db.ACT_VM_CONVERT_FAIL, reason, self.UserCred) logclient.AddSimpleActionLog(guest, logclient.ACT_VM_CONVERT, reason, self.UserCred, false) + logclient.AddSimpleActionLog(targetGuest, logclient.ACT_VM_CONVERT, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) } @@ -185,20 +186,20 @@ func (self *GuestConvertEsxiToKvmTask) OnHostCreateGuestFailed( } func (self *GuestConvertEsxiToKvmTask) TaskComplete(ctx context.Context, guest, targetGuest *models.SGuest) { - guest.SetStatus(self.UserCred, api.VM_READY, "") + guest.SetStatus(self.UserCred, api.VM_CONVERTED, "") guest.SetMetadata(ctx, api.SERVER_META_CONVERTED_SERVER, targetGuest.Id, self.UserCred) if osProfile := guest.GetMetadata("__os_profile__", self.UserCred); len(osProfile) > 0 { - guest.SetMetadata(ctx, "__os_profile__", osProfile, self.UserCred) + targetGuest.SetMetadata(ctx, "__os_profile__", osProfile, self.UserCred) } if account := guest.GetMetadata(api.VM_METADATA_LOGIN_ACCOUNT, self.UserCred); len(account) > 0 { - guest.SetMetadata(ctx, api.VM_METADATA_LOGIN_ACCOUNT, account, self.UserCred) + targetGuest.SetMetadata(ctx, api.VM_METADATA_LOGIN_ACCOUNT, account, self.UserCred) } if loginKey := guest.GetMetadata(api.VM_METADATA_LOGIN_KEY, self.UserCred); len(loginKey) > 0 { passwd, _ := utils.DescryptAESBase64(guest.Id, loginKey) if len(passwd) > 0 { secret, err := utils.EncryptAESBase64(targetGuest.Id, passwd) if err == nil { - guest.SetMetadata(ctx, api.VM_METADATA_LOGIN_KEY, secret, self.UserCred) + targetGuest.SetMetadata(ctx, api.VM_METADATA_LOGIN_KEY, secret, self.UserCred) } } }