mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 02:26:39 +08:00
fix: cpuCmtbound sync for zstack
This commit is contained in:
@@ -230,6 +230,7 @@ type ICloudHost interface {
|
||||
GetCpuCmtbound() float32
|
||||
GetMemSizeMB() int
|
||||
GetMemCmtbound() float32
|
||||
GetReservedMemoryMb() int
|
||||
GetStorageSizeMB() int
|
||||
GetStorageType() string
|
||||
GetHostType() string
|
||||
|
||||
@@ -1423,6 +1423,10 @@ func (self *SHost) syncWithCloudHost(ctx context.Context, userCred mcclient.Toke
|
||||
self.MemCmtbound = memCmt
|
||||
}
|
||||
|
||||
if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
|
||||
self.MemReserved = reservedMem
|
||||
}
|
||||
|
||||
self.IsEmulated = extHost.IsEmulated()
|
||||
self.Enabled = extHost.GetEnabled()
|
||||
|
||||
@@ -1524,6 +1528,10 @@ func (manager *SHostManager) newFromCloudHost(ctx context.Context, userCred mccl
|
||||
host.MemCmtbound = memCmt
|
||||
}
|
||||
|
||||
if reservedMem := extHost.GetReservedMemoryMb(); reservedMem > 0 {
|
||||
host.MemReserved = reservedMem
|
||||
}
|
||||
|
||||
host.ManagerId = provider.Id
|
||||
host.IsEmulated = extHost.IsEmulated()
|
||||
|
||||
|
||||
@@ -24,3 +24,7 @@ func (self *SHostBase) GetCpuCmtbound() float32 {
|
||||
func (self *SHostBase) GetMemCmtbound() float32 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
func (self *SHostBase) GetReservedMemoryMb() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -56,6 +57,7 @@ type SResource struct {
|
||||
}
|
||||
|
||||
type SHost struct {
|
||||
multicloud.SHostBase
|
||||
zone *SZone
|
||||
|
||||
CpuInfo string
|
||||
|
||||
@@ -200,7 +200,26 @@ func (host *SHost) GetSN() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (host *SHost) GetReservedMemoryMb() int {
|
||||
host.zone.fetchHostCmtbound()
|
||||
return host.zone.reservedMemeoryMb
|
||||
}
|
||||
|
||||
func (host *SHost) GetCpuCmtbound() float32 {
|
||||
host.zone.fetchHostCmtbound()
|
||||
return host.zone.cpuCmtbound
|
||||
}
|
||||
|
||||
func (host *SHost) GetMemCmtbound() float32 {
|
||||
host.zone.fetchHostCmtbound()
|
||||
return host.zone.memCmtbound
|
||||
}
|
||||
|
||||
func (host *SHost) GetCpuCount() int {
|
||||
cpuCmtBound := host.GetCpuCmtbound()
|
||||
if cpuCmtBound > 0 {
|
||||
return int(float32(host.TotalCPUCapacity) / cpuCmtBound)
|
||||
}
|
||||
return host.TotalCPUCapacity
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
package zstack
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/fileutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -25,8 +29,11 @@ type SZone struct {
|
||||
region *SRegion
|
||||
|
||||
ZStackBasic
|
||||
Type string
|
||||
State string
|
||||
Type string
|
||||
State string
|
||||
cpuCmtbound float32
|
||||
memCmtbound float32
|
||||
reservedMemeoryMb int
|
||||
|
||||
iwires []cloudprovider.ICloudWire
|
||||
istorages []cloudprovider.ICloudStorage
|
||||
@@ -70,6 +77,32 @@ func (zone *SZone) GetIRegion() cloudprovider.ICloudRegion {
|
||||
return zone.region
|
||||
}
|
||||
|
||||
func (zone *SZone) fetchHostCmtbound() {
|
||||
if zone.cpuCmtbound > 0 || zone.memCmtbound > 0 || zone.reservedMemeoryMb > 0 {
|
||||
return
|
||||
}
|
||||
configurations, err := zone.region.GetConfigrations()
|
||||
if err != nil {
|
||||
log.Errorf("failed to get global configurations error: %v", err)
|
||||
return
|
||||
}
|
||||
for _, config := range configurations {
|
||||
if config.Name == "cpu.overProvisioning.ratio" && config.Category == "host" {
|
||||
if cpuCmtbound, err := strconv.ParseFloat(config.Value, 32); err == nil {
|
||||
zone.cpuCmtbound = float32(cpuCmtbound)
|
||||
}
|
||||
}
|
||||
if config.Name == "reservedMemory" && config.Category == "kvm" {
|
||||
zone.reservedMemeoryMb, _ = fileutils.GetSizeMb(config.Value, 'M', 1024)
|
||||
}
|
||||
if config.Name == "overProvisioning.memory" && config.Category == "mevoco" {
|
||||
if memCmtbound, err := strconv.ParseFloat(config.Value, 32); err == nil {
|
||||
zone.memCmtbound = float32(memCmtbound)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (zone *SZone) fetchStorages(clusterId string) error {
|
||||
storages, err := zone.region.getIStorages(zone.UUID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user