Skip to content

Commit

Permalink
host fix cmt bound, minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Apr 26, 2020
1 parent 03824a1 commit b05d228
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/apis/compute/guest_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/compute/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
// 已使用存储大小
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudcommon/db/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/cloudcommon/db/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions pkg/compute/tasks/guest_convert_esxi_to_kvm_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit b05d228

Please sign in to comment.