From f7d0085af809dd781c8a71f7811458a919c9bce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 21 Aug 2024 10:51:07 +0800 Subject: [PATCH] fix(region): filter eips by associated (#21067) --- pkg/apis/compute/elasticips_const.go | 3 +++ pkg/compute/models/elasticips.go | 8 ++++++++ pkg/mcclient/options/compute/eips.go | 1 + 3 files changed, 12 insertions(+) diff --git a/pkg/apis/compute/elasticips_const.go b/pkg/apis/compute/elasticips_const.go index caccae3781..a8a1fd08e7 100644 --- a/pkg/apis/compute/elasticips_const.go +++ b/pkg/apis/compute/elasticips_const.go @@ -87,6 +87,9 @@ type ElasticipListInput struct { // example: elastic_ip Mode string `json:"mode"` + // 是否已关联资源 + IsAssociated *bool `json:"is_associated"` + // IP地址 IpAddr []string `json:"ip_addr"` diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 8fbd909d62..aba8e25d81 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -257,6 +257,14 @@ func (manager *SElasticipManager) ListItemFilter( q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("associate_id")), sqlchemy.IsEmpty(q.Field("associate_id")))) } + if query.IsAssociated != nil { + if *query.IsAssociated { + q = q.IsNotEmpty("associate_type") + } else { + q = q.IsNullOrEmpty("associate_type") + } + } + if len(query.Mode) > 0 { q = q.In("mode", query.Mode) } diff --git a/pkg/mcclient/options/compute/eips.go b/pkg/mcclient/options/compute/eips.go index a7739b0549..6023eabaa4 100644 --- a/pkg/mcclient/options/compute/eips.go +++ b/pkg/mcclient/options/compute/eips.go @@ -30,6 +30,7 @@ type ElasticipListOptions struct { AssociateId []string AssociateType []string AssociateName []string + IsAssociated *bool IpAddr []string options.BaseListOptions