Skip to content

Commit

Permalink
fix(region): support eip search (#20682)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Jun 28, 2024
1 parent 85e75c0 commit 67332c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/apis/compute/elasticips_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pkg/compute/models/elasticips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/mcclient/options/compute/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67332c2

Please sign in to comment.