mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8722 from wanyaoqi/feature/wyq/misc-1110
misc bugfix: add log note, show reserved memory, specific bash start guest
This commit is contained in:
+56
-28
@@ -2513,28 +2513,47 @@ func (manager *SHostManager) totalCountQ(
|
||||
}
|
||||
q = q.Filter(cond(hosts.Field("is_baremetal")))
|
||||
}
|
||||
isolatedDevices := IsolatedDeviceManager.Query().SubQuery()
|
||||
iq := isolatedDevices.Query(
|
||||
isolatedDevices.Field("host_id"),
|
||||
isolatedDevices.Field("reserved_memory", "isolated_reserved_memory"),
|
||||
isolatedDevices.Field("reserved_cpu", "isolated_reserved_cpu"),
|
||||
isolatedDevices.Field("reserved_storage", "isolated_reserved_storage"),
|
||||
).IsNullOrEmpty("guest_id").SubQuery()
|
||||
q = q.LeftJoin(iq, sqlchemy.Equals(q.Field("id"), iq.Field("host_id")))
|
||||
q.AppendField(
|
||||
iq.Field("isolated_reserved_memory"),
|
||||
iq.Field("isolated_reserved_cpu"),
|
||||
iq.Field("isolated_reserved_storage"),
|
||||
)
|
||||
q = AttachUsageQuery(q, hosts, hostTypes, resourceTypes, providers, brands, cloudEnv, rangeObjs)
|
||||
return q
|
||||
}
|
||||
|
||||
type HostStat struct {
|
||||
MemSize int
|
||||
MemReserved int
|
||||
MemCmtbound float32
|
||||
CpuCount int
|
||||
CpuReserved int
|
||||
CpuCmtbound float32
|
||||
StorageSize int
|
||||
MemSize int
|
||||
MemReserved int
|
||||
MemCmtbound float32
|
||||
CpuCount int
|
||||
CpuReserved int
|
||||
CpuCmtbound float32
|
||||
StorageSize int
|
||||
IsolatedReservedMemory int64
|
||||
IsolatedReservedCpu int64
|
||||
IsolatedReservedStorage int64
|
||||
}
|
||||
|
||||
type HostsCountStat struct {
|
||||
StorageSize int64
|
||||
Count int64
|
||||
Memory int64
|
||||
MemoryVirtual float64
|
||||
MemoryReserved int64
|
||||
CPU int64
|
||||
CPUVirtual float64
|
||||
StorageSize int64
|
||||
Count int64
|
||||
Memory int64
|
||||
MemoryVirtual float64
|
||||
MemoryReserved int64
|
||||
CPU int64
|
||||
CPUVirtual float64
|
||||
IsolatedReservedMemory int64
|
||||
IsolatedReservedCpu int64
|
||||
IsolatedReservedStorage int64
|
||||
}
|
||||
|
||||
func (manager *SHostManager) calculateCount(q *sqlchemy.SQuery) HostsCountStat {
|
||||
@@ -2548,13 +2567,16 @@ func (manager *SHostManager) calculateCount(q *sqlchemy.SQuery) HostsCountStat {
|
||||
return aSize
|
||||
}
|
||||
var (
|
||||
tStore int64 = 0
|
||||
tCnt int64 = 0
|
||||
tMem int64 = 0
|
||||
tVmem float64 = 0.0
|
||||
rMem int64 = 0
|
||||
tCPU int64 = 0
|
||||
tVCPU float64 = 0.0
|
||||
tStore int64 = 0
|
||||
tCnt int64 = 0
|
||||
tMem int64 = 0
|
||||
tVmem float64 = 0.0
|
||||
rMem int64 = 0
|
||||
tCPU int64 = 0
|
||||
tVCPU float64 = 0.0
|
||||
irMem int64 = 0
|
||||
irCpu int64 = 0
|
||||
irStore int64 = 0
|
||||
)
|
||||
stats := make([]HostStat, 0)
|
||||
err := q.All(&stats)
|
||||
@@ -2582,15 +2604,21 @@ func (manager *SHostManager) calculateCount(q *sqlchemy.SQuery) HostsCountStat {
|
||||
rMem += int64(stat.MemReserved)
|
||||
tVmem += float64(float32(aMem) * stat.MemCmtbound)
|
||||
tVCPU += float64(float32(aCpu) * stat.CpuCmtbound)
|
||||
irMem += stat.IsolatedReservedMemory
|
||||
irCpu += stat.IsolatedReservedCpu
|
||||
irStore += stat.IsolatedReservedStorage
|
||||
}
|
||||
return HostsCountStat{
|
||||
StorageSize: tStore,
|
||||
Count: tCnt,
|
||||
Memory: tMem,
|
||||
MemoryVirtual: tVmem,
|
||||
MemoryReserved: rMem,
|
||||
CPU: tCPU,
|
||||
CPUVirtual: tVCPU,
|
||||
StorageSize: tStore,
|
||||
Count: tCnt,
|
||||
Memory: tMem,
|
||||
MemoryVirtual: tVmem,
|
||||
MemoryReserved: rMem,
|
||||
CPU: tCPU,
|
||||
CPUVirtual: tVCPU,
|
||||
IsolatedReservedCpu: irCpu,
|
||||
IsolatedReservedMemory: irMem,
|
||||
IsolatedReservedStorage: irStore,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func (self *GuestStartTask) OnStartComplete(ctx context.Context, obj db.IStandal
|
||||
if guest.Hypervisor != api.HYPERVISOR_KVM {
|
||||
guest.StartSyncstatus(ctx, self.UserCred, self.GetTaskId())
|
||||
} else {
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_START, "", self.UserCred, true)
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_START, "success", self.UserCred, true)
|
||||
self.taskComplete(ctx, guest)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (self *GuestStopTask) OnGuestStopTaskComplete(ctx context.Context, guest *m
|
||||
if guest.Status == api.VM_READY && guest.DisableDelete.IsFalse() && guest.ShutdownBehavior == api.SHUTDOWN_TERMINATE {
|
||||
guest.StartAutoDeleteGuestTask(ctx, self.UserCred, "")
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_STOP, "", self.UserCred, true)
|
||||
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_STOP, "success", self.UserCred, true)
|
||||
}
|
||||
|
||||
func (self *GuestStopTask) OnGuestStopTaskCompleteFailed(ctx context.Context, guest *models.SGuest, reason jsonutils.JSONObject) {
|
||||
|
||||
@@ -712,6 +712,9 @@ func hostUsage(
|
||||
count[fmt.Sprintf("%s.memory.virtual", prefix)] = result.MemoryVirtual
|
||||
count[fmt.Sprintf("%s.cpu.virtual", prefix)] = result.CPUVirtual
|
||||
count[fmt.Sprintf("%s.memory.reserved", prefix)] = result.MemoryReserved
|
||||
count[fmt.Sprintf("%s.memory.reserved.isolated", prefix)] = result.IsolatedReservedMemory
|
||||
count[fmt.Sprintf("%s.cpu.reserved.isolated", prefix)] = result.IsolatedReservedCpu
|
||||
count[fmt.Sprintf("%s.storage.reserved.isolated", prefix)] = result.IsolatedReservedStorage
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -968,7 +968,7 @@ func (s *SKVMGuestInstance) Stop() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) scriptStart() error {
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("sh", s.GetStartScriptPath()).Output()
|
||||
output, err := procutils.NewRemoteCommandAsFarAsPossible("bash", s.GetStartScriptPath()).Output()
|
||||
if err != nil {
|
||||
s.scriptStop()
|
||||
return fmt.Errorf("Start VM Failed %s %s", output, err)
|
||||
@@ -977,7 +977,7 @@ func (s *SKVMGuestInstance) scriptStart() error {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) scriptStop() bool {
|
||||
_, err := procutils.NewRemoteCommandAsFarAsPossible("sh", s.GetStopScriptPath()).Output()
|
||||
_, err := procutils.NewRemoteCommandAsFarAsPossible("bash", s.GetStopScriptPath()).Output()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user