mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #7313 from ioito/automated-cherry-pick-of-#7310-upstream-release-3.2
Automated cherry pick of #7310: fix: 支持多项目安全组规则过滤
This commit is contained in:
@@ -25,14 +25,14 @@ import (
|
||||
func init() {
|
||||
type SecGroupRulesListOptions struct {
|
||||
options.BaseListOptions
|
||||
Secgroup string `help:"Secgroup ID or Name"`
|
||||
SecgroupName string `help:"Search rules by fuzzy secgroup name"`
|
||||
Project string `help:"Filter rules by project"`
|
||||
Direction string `help:"filter Direction of rule" choices:"in|out"`
|
||||
Protocol string `help:"filter Protocol of rule" choices:"any|tcp|udp|icmp"`
|
||||
Action string `help:"filter Actin of rule" choices:"allow|deny"`
|
||||
Ports string `help:"filter Ports of rule"`
|
||||
Ip string `help:"filter cidr of rule"`
|
||||
Secgroup string `help:"Secgroup ID or Name"`
|
||||
SecgroupName string `help:"Search rules by fuzzy secgroup name"`
|
||||
Projects []string `help:"Filter rules by project"`
|
||||
Direction string `help:"filter Direction of rule" choices:"in|out"`
|
||||
Protocol string `help:"filter Protocol of rule" choices:"any|tcp|udp|icmp"`
|
||||
Action string `help:"filter Actin of rule" choices:"allow|deny"`
|
||||
Ports string `help:"filter Ports of rule"`
|
||||
Ip string `help:"filter cidr of rule"`
|
||||
}
|
||||
|
||||
R(&SecGroupRulesListOptions{}, "secgroup-rule-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupRulesListOptions) error {
|
||||
|
||||
@@ -174,6 +174,8 @@ type SecurityGroupRuleListInput struct {
|
||||
apis.ResourceBaseListInput
|
||||
SecgroupFilterListInput
|
||||
|
||||
Projects []string `json:"projects"`
|
||||
|
||||
// 以direction字段过滤安全组规则
|
||||
Direction string `json:"direction"`
|
||||
// 以action字段过滤安全组规则
|
||||
|
||||
@@ -176,6 +176,16 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SSecurityGroupResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if len(query.Projects) > 0 {
|
||||
sq := SecurityGroupManager.Query("id")
|
||||
tenants := db.TenantCacheManager.GetTenantQuery().SubQuery()
|
||||
subq := tenants.Query(tenants.Field("id")).Filter(sqlchemy.OR(
|
||||
sqlchemy.In(tenants.Field("id"), query.Projects),
|
||||
sqlchemy.In(tenants.Field("name"), query.Projects),
|
||||
)).SubQuery()
|
||||
sq = sq.In("tenant_id", subq)
|
||||
sql = sql.In("secgroup_id", sq.SubQuery())
|
||||
}
|
||||
if len(query.Direction) > 0 {
|
||||
sql = sql.Equals("direction", query.Direction)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user