mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 23:41:52 +08:00
fix(region): guest start check vcpu is enough
This commit is contained in:
@@ -1028,11 +1028,15 @@ func (self *SGuest) PerformStart(
|
||||
}
|
||||
if !self.guestDisksStorageTypeIsShared() {
|
||||
host, _ := self.GetHost()
|
||||
guestsMem, err := host.GetNotReadyGuestsMemorySize()
|
||||
guestStats, err := host.GetNotReadyGuestsStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if float32(guestsMem+self.VmemSize) > host.GetVirtualMemorySize() {
|
||||
|
||||
if float32(guestStats.GuestVcpuCount+self.VcpuCount) > host.GetVirtualCPUCount() {
|
||||
return nil, httperrors.NewInsufficientResourceError("host virtual cpu not enough")
|
||||
}
|
||||
if float32(guestStats.GuestVmemSize+self.VmemSize) > host.GetVirtualMemorySize() {
|
||||
return nil, httperrors.NewInsufficientResourceError("host virtual memory not enough")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1664,7 +1664,7 @@ func (hh *SHost) GetRunningGuestCount() (int, error) {
|
||||
return q.CountWithError()
|
||||
}
|
||||
|
||||
func (hh *SHost) GetNotReadyGuestsMemorySize() (int, error) {
|
||||
func (hh *SHost) GetNotReadyGuestsStat() (*SHostGuestResourceUsage, error) {
|
||||
guests := GuestManager.Query().SubQuery()
|
||||
q := guests.Query(sqlchemy.COUNT("guest_count"),
|
||||
sqlchemy.SUM("guest_vcpu_count", guests.Field("vcpu_count")),
|
||||
@@ -1676,9 +1676,9 @@ func (hh *SHost) GetNotReadyGuestsMemorySize() (int, error) {
|
||||
stat := SHostGuestResourceUsage{}
|
||||
err := q.First(&stat)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
return nil, err
|
||||
}
|
||||
return stat.GuestVmemSize, nil
|
||||
return &stat, nil
|
||||
}
|
||||
|
||||
func (hh *SHost) GetRunningGuestResourceUsage() *SHostGuestResourceUsage {
|
||||
|
||||
Reference in New Issue
Block a user