From 67332c2e78aa00f323849d21a25ccb8218ca9989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Fri, 28 Jun 2024 15:58:41 +0800 Subject: [PATCH] fix(region): support eip search (#20682) --- pkg/apis/compute/elasticips_const.go | 7 +++++-- pkg/compute/models/elasticips.go | 21 +++++++++++++++++++++ pkg/mcclient/options/compute/eips.go | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pkg/apis/compute/elasticips_const.go b/pkg/apis/compute/elasticips_const.go index cce0b7e3b7c..caccae37813 100644 --- a/pkg/apis/compute/elasticips_const.go +++ b/pkg/apis/compute/elasticips_const.go @@ -91,10 +91,13 @@ type ElasticipListInput struct { IpAddr []string `json:"ip_addr"` // 绑定资源类型 - AssociateType string `json:"associate_type"` + AssociateType []string `json:"associate_type"` + + // 绑定资源名称,模糊查询 + AssociateName []string `json:"associate_name"` // 绑定资源Id - AssociateId string `json:"associate_id"` + AssociateId []string `json:"associate_id"` // 计费类型: 流量、带宽 // example: bandwidth diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 512ef8bb373..ec6bf7d0bf6 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -286,6 +286,27 @@ func (manager *SElasticipManager) ListItemFilter( q = q.IsFalse("auto_dellocate") } } + if len(query.AssociateName) > 0 { + filters := []sqlchemy.ICondition{} + likeQuery := func(sq *sqlchemy.SQuery) *sqlchemy.SQuery { + conditions := []sqlchemy.ICondition{} + for _, name := range query.AssociateName { + conditions = append(conditions, sqlchemy.Contains(sq.Field("name"), name)) + } + return sq.Filter(sqlchemy.OR(conditions...)) + } + for _, m := range []db.IModelManager{ + GuestManager, + GroupManager, + LoadbalancerManager, + NatGatewayManager, + } { + sq := m.Query("id") + sq = likeQuery(sq) + filters = append(filters, sqlchemy.In(q.Field("associate_id"), sq)) + } + q = q.Filter(sqlchemy.OR(filters...)) + } return q, nil } diff --git a/pkg/mcclient/options/compute/eips.go b/pkg/mcclient/options/compute/eips.go index 32d2dea3bcb..a7739b0549b 100644 --- a/pkg/mcclient/options/compute/eips.go +++ b/pkg/mcclient/options/compute/eips.go @@ -27,6 +27,9 @@ type ElasticipListOptions struct { UsableEipForAssociateType string `help:"With associate id filter which eip can associate" choices:"server|natgateway|loadbalancer"` UsableEipForAssociateId string `help:"With associate type filter which eip can associate"` OrderByIp string + AssociateId []string + AssociateType []string + AssociateName []string IpAddr []string options.BaseListOptions