mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #7074 from ioito/hotfix/qx-secgroup-count
fix: 分开统计安全组关联虚拟机数量
This commit is contained in:
@@ -203,9 +203,16 @@ type SecgroupDetails struct {
|
||||
SSecurityGroup
|
||||
|
||||
// 关联云主机数量
|
||||
GuestCnt int `json:"guest_cnt"`
|
||||
GuestCnt int `json:"guest_cnt,allowempty"`
|
||||
|
||||
// 关联此安全组的云主机is_system为true数量
|
||||
SystemGuestCnt int `json:"system_guest_cnt,allowempty"`
|
||||
|
||||
// admin_secgrp_id为此安全组的云主机数量
|
||||
AdminGuestCnt int `json:"admin_guest_cnt,allowempty"`
|
||||
|
||||
// 安全组缓存数量
|
||||
CacheCnt int `json:"cache_cnt"`
|
||||
CacheCnt int `json:"cache_cnt,allowempty"`
|
||||
// 规则信息
|
||||
Rules []SSecurityGroupRule `json:"rules"`
|
||||
// 入方向规则信息
|
||||
|
||||
@@ -318,16 +318,27 @@ func (manager *SSecurityGroupManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
guestMaps := map[string]int{}
|
||||
adminGuestMaps := map[string]int{}
|
||||
systemGuestMaps := map[string]int{}
|
||||
normalGuestMaps := map[string]int{}
|
||||
for i := range guests {
|
||||
if _, ok := guestMaps[guests[i].SecgrpId]; !ok {
|
||||
guestMaps[guests[i].SecgrpId] = 0
|
||||
if guests[i].IsSystem {
|
||||
if _, ok := systemGuestMaps[guests[i].SecgrpId]; !ok {
|
||||
systemGuestMaps[guests[i].SecgrpId] = 0
|
||||
}
|
||||
systemGuestMaps[guests[i].SecgrpId]++
|
||||
} else {
|
||||
if _, ok := normalGuestMaps[guests[i].SecgrpId]; !ok {
|
||||
normalGuestMaps[guests[i].SecgrpId] = 0
|
||||
}
|
||||
normalGuestMaps[guests[i].SecgrpId]++
|
||||
}
|
||||
guestMaps[guests[i].SecgrpId]++
|
||||
if _, ok := guestMaps[guests[i].AdminSecgrpId]; !ok {
|
||||
guestMaps[guests[i].AdminSecgrpId] = 0
|
||||
if len(guests[i].AdminSecgrpId) > 0 {
|
||||
if _, ok := adminGuestMaps[guests[i].AdminSecgrpId]; !ok {
|
||||
adminGuestMaps[guests[i].AdminSecgrpId] = 0
|
||||
}
|
||||
adminGuestMaps[guests[i].AdminSecgrpId]++
|
||||
}
|
||||
guestMaps[guests[i].AdminSecgrpId]++
|
||||
}
|
||||
|
||||
guestSecgroups := []SGuestsecgroup{}
|
||||
@@ -339,10 +350,10 @@ func (manager *SSecurityGroupManager) FetchCustomizeColumns(
|
||||
}
|
||||
|
||||
for i := range guestSecgroups {
|
||||
if _, ok := guestMaps[guestSecgroups[i].SecgroupId]; !ok {
|
||||
guestMaps[guestSecgroups[i].SecgroupId] = 0
|
||||
if _, ok := normalGuestMaps[guestSecgroups[i].SecgroupId]; !ok {
|
||||
normalGuestMaps[guestSecgroups[i].SecgroupId] = 0
|
||||
}
|
||||
guestMaps[guestSecgroups[i].SecgroupId]++
|
||||
normalGuestMaps[guestSecgroups[i].SecgroupId]++
|
||||
}
|
||||
|
||||
rules := []SSecurityGroupRule{}
|
||||
@@ -390,7 +401,9 @@ func (manager *SSecurityGroupManager) FetchCustomizeColumns(
|
||||
rows[i].InRules = _inRules
|
||||
rows[i].OutRules = _outRules
|
||||
rows[i].CacheCnt, _ = cacheMaps[secgroupIds[i]]
|
||||
rows[i].GuestCnt, _ = guestMaps[secgroupIds[i]]
|
||||
rows[i].GuestCnt, _ = normalGuestMaps[secgroupIds[i]]
|
||||
rows[i].AdminGuestCnt, _ = adminGuestMaps[secgroupIds[i]]
|
||||
rows[i].SystemGuestCnt, _ = systemGuestMaps[secgroupIds[i]]
|
||||
}
|
||||
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user