mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #7174 from ioito/hotfix/qx-secgroup-rule-export
fix: 添加secgroup rule过滤参数
This commit is contained in:
@@ -25,33 +25,18 @@ import (
|
||||
func init() {
|
||||
type SecGroupRulesListOptions struct {
|
||||
options.BaseListOptions
|
||||
Secgroup string `help:"Secgroup ID or Name"`
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
R(&SecGroupRulesListOptions{}, "secgroup-rule-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupRulesListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
{
|
||||
var err error
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
if len(args.Secgroup) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Secgroup), "secgroup")
|
||||
}
|
||||
if len(args.Direction) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Direction), "direction")
|
||||
}
|
||||
if len(args.Protocol) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Protocol), "protocol")
|
||||
}
|
||||
if len(args.Action) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Action), "action")
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.SecGroupRules.List(s, params)
|
||||
if err != nil {
|
||||
|
||||
@@ -189,6 +189,11 @@ type SecgroupResourceInput struct {
|
||||
// Deprecated
|
||||
// filter by secgroup_id
|
||||
SecgroupId string `json:"secgroup_id" "yunion:deprecated-by":"secgroup"`
|
||||
|
||||
// 模糊匹配安全组规则名称
|
||||
SecgroupName string `json:"secgroup_name"`
|
||||
|
||||
apis.ProjectizedResourceInput
|
||||
}
|
||||
|
||||
type SecgroupFilterListInput struct {
|
||||
|
||||
@@ -114,6 +114,18 @@ func (manager *SSecurityGroupResourceBaseManager) ListItemFilter(
|
||||
}
|
||||
q = q.Equals("secgroup_id", secgrpObj.GetId())
|
||||
}
|
||||
if len(query.SecgroupName) > 0 {
|
||||
sq := SecurityGroupManager.Query("id").Like("name", "%"+query.SecgroupName+"%")
|
||||
q = q.In("secgroup_id", sq.SubQuery())
|
||||
}
|
||||
if len(query.Project) > 0 {
|
||||
tenant, err := db.TenantCacheManager.FetchTenantByIdOrName(ctx, query.Project)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewResourceNotFoundError2("projects", query.Project)
|
||||
}
|
||||
sq := SecurityGroupManager.Query("id").Equals("tenant_id", tenant.Id)
|
||||
q = q.In("secgroup_id", sq.SubQuery())
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(
|
||||
if len(query.Protocol) > 0 {
|
||||
sql = sql.Equals("protocol", query.Protocol)
|
||||
}
|
||||
sql = sql.GroupBy("secgroup_id")
|
||||
return sql, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func init() {
|
||||
SecGroupRules = NewComputeManager("secgrouprule", "secgrouprules",
|
||||
[]string{"ID", "Name", "Direction",
|
||||
"Action", "Protocol", "Ports", "Priority",
|
||||
"Cidr", "Description"},
|
||||
"Cidr", "Secgroup", "Tenant", "Description"},
|
||||
[]string{"SecGroups"})
|
||||
|
||||
registerCompute(&SecGroupRules)
|
||||
|
||||
Reference in New Issue
Block a user