From 3db15d59f75b011d6bfda71642264d8d8cdaf687 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Tue, 7 Jul 2020 11:16:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=86=E5=BC=80=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BB=84=E5=85=B3=E8=81=94=E8=99=9A=E6=8B=9F?= =?UTF-8?q?=E6=9C=BA=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/apis/compute/secgroup.go | 11 +++++++++-- pkg/compute/models/secgroups.go | 35 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pkg/apis/compute/secgroup.go b/pkg/apis/compute/secgroup.go index 1d842a0f45..376031b07b 100644 --- a/pkg/apis/compute/secgroup.go +++ b/pkg/apis/compute/secgroup.go @@ -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"` // 入方向规则信息 diff --git a/pkg/compute/models/secgroups.go b/pkg/compute/models/secgroups.go index 4e0d133be1..67625f6cf3 100644 --- a/pkg/compute/models/secgroups.go +++ b/pkg/compute/models/secgroups.go @@ -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