fix(region): support eip search (#20683)

This commit is contained in:
屈轩
2024-06-28 15:58:44 +08:00
committed by GitHub
parent b4d1a1beeb
commit 12c6181721
3 changed files with 29 additions and 2 deletions
+5 -2
View File
@@ -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
+21
View File
@@ -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
}
+3
View File
@@ -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