mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: 默认不自动合并安全组
This commit is contained in:
@@ -15,194 +15,23 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type SecGroupsListOptions struct {
|
||||
Equals string `help:"Secgroup ID or Name, filter secgroups whose rules equals the specified one"`
|
||||
Server string `help:"Filter secgroups bound to specified server"`
|
||||
options.BaseListOptions
|
||||
Ip string `help:"Filter secgroup by ip"`
|
||||
Ports string `help:"Filter secgroup by ports"`
|
||||
Direction string `help:"Filter secgroup by ports" choices:"all|in|out"`
|
||||
}
|
||||
|
||||
R(&SecGroupsListOptions{}, "secgroup-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupsListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.SecGroups.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.SecGroups.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type SecGroupsCreateOptions struct {
|
||||
NAME string `help:"Name of security group to create"`
|
||||
RULES []string `help:"security rule to create"`
|
||||
Desc string `help:"Description"`
|
||||
}
|
||||
|
||||
R(&SecGroupsCreateOptions{}, "secgroup-create", "Create a security group", func(s *mcclient.ClientSession, args *SecGroupsCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
for i, a := range args.RULES {
|
||||
params.Add(jsonutils.NewString(a), fmt.Sprintf("rule.%d", i))
|
||||
}
|
||||
secgroups, err := modules.SecGroups.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
type SecGroupsUnionOptions struct {
|
||||
ID string `help:"ID or Name of security group destination"`
|
||||
SECGROUPS []string `help:"source IDs or Names of secgroup"`
|
||||
}
|
||||
|
||||
R(&SecGroupsUnionOptions{}, "secgroup-union", "Union secgroups to one secgroup", func(s *mcclient.ClientSession, args *SecGroupsUnionOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
secgroups := jsonutils.NewArray()
|
||||
for i := 0; i < len(args.SECGROUPS); i++ {
|
||||
secgroups.Add(jsonutils.NewString(args.SECGROUPS[i]))
|
||||
}
|
||||
params.Add(secgroups, "secgroups")
|
||||
secgroup, err := modules.SecGroups.PerformAction(s, args.ID, "union", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroup)
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
type SecGroupsDetailOptions struct {
|
||||
ID string `help:"ID or Name of security group"`
|
||||
}
|
||||
R(&SecGroupsDetailOptions{}, "secgroup-show", "Show details of a security group", func(s *mcclient.ClientSession, args *SecGroupsDetailOptions) error {
|
||||
result, err := modules.SecGroups.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
R(&SecGroupsDetailOptions{}, "secgroup-delete", "Delete a security group", func(s *mcclient.ClientSession, args *SecGroupsDetailOptions) error {
|
||||
secgroups, err := modules.SecGroups.Delete(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&SecGroupsDetailOptions{}, "secgroup-public", "Make a security group publicly available", func(s *mcclient.ClientSession, args *SecGroupsDetailOptions) error {
|
||||
result, err := modules.SecGroups.PerformAction(s, args.ID, "public", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&SecGroupsDetailOptions{}, "secgroup-private", "Make a security group private", func(s *mcclient.ClientSession, args *SecGroupsDetailOptions) error {
|
||||
result, err := modules.SecGroups.PerformAction(s, args.ID, "private", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type SecGroupsUpdateOptions struct {
|
||||
ID string `help:"ID of security group"`
|
||||
Name string `help:"Name of security group to update"`
|
||||
Desc string `help:"Description of security groups"`
|
||||
}
|
||||
|
||||
R(&SecGroupsUpdateOptions{}, "secgroup-update", "Update details of a security group", func(s *mcclient.ClientSession, args *SecGroupsUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Name) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
secgroups, err := modules.SecGroups.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
})
|
||||
|
||||
type SecGroupsAddRuleOptions struct {
|
||||
ID string `help:"ID or Name of security group"`
|
||||
DIRECTION string `help:"Direction of rule" choices:"in|out"`
|
||||
PROTOCOL string `help:"Protocol of rule" choices:"any|tcp|udp|icmp"`
|
||||
ACTION string `help:"Actin of rule" choices:"allow|deny"`
|
||||
PRIORITY int `help:"Priority for rule, range 1 ~ 100"`
|
||||
Cidr string `help:"IP or CIRD for rule"`
|
||||
Description string `help:"Desciption for rule"`
|
||||
Ports string `help:"Port for rule"`
|
||||
}
|
||||
|
||||
R(&SecGroupsAddRuleOptions{}, "secgroup-add-rule", "Add rule for a security group", func(s *mcclient.ClientSession, args *SecGroupsAddRuleOptions) error {
|
||||
params, err := options.StructToParams(args)
|
||||
secgroups, err := modules.SecGroups.PerformAction(s, args.ID, "add-rule", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
})
|
||||
|
||||
type SecurityGroupCacheSecurityGroup struct {
|
||||
ID string `help:"ID or Name of security group"`
|
||||
VPC string `help:"ID or Name of vpc"`
|
||||
Classic *bool `help:"Is classic vpc"`
|
||||
}
|
||||
|
||||
R(&SecurityGroupCacheSecurityGroup{}, "secgroup-cache-secgroup", "Cache security group for special vpc", func(s *mcclient.ClientSession, args *SecurityGroupCacheSecurityGroup) error {
|
||||
params, err := options.StructToParams(args)
|
||||
secgroups, err := modules.SecGroups.PerformAction(s, args.ID, "cache-secgroup", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
})
|
||||
|
||||
type SecurityGroupUncacheSecurityGroup struct {
|
||||
ID string `help:"ID or Name of security group"`
|
||||
CACHE string `help:"ID of secgroup cache"`
|
||||
}
|
||||
|
||||
R(&SecurityGroupUncacheSecurityGroup{}, "secgroup-uncache-secgroup", "Unache special secgroup cache", func(s *mcclient.ClientSession, args *SecurityGroupUncacheSecurityGroup) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.CACHE), "secgroupcache")
|
||||
secgroups, err := modules.SecGroups.PerformAction(s, args.ID, "uncache-secgroup", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(secgroups)
|
||||
return nil
|
||||
})
|
||||
|
||||
cmd := shell.NewResourceCmd(&modules.SecGroups)
|
||||
cmd.List(&options.SecgroupListOptions{})
|
||||
cmd.Create(&options.SecgroupCreateOptions{})
|
||||
cmd.Show(&options.SecgroupIdOptions{})
|
||||
cmd.Update(&options.BaseUpdateOptions{})
|
||||
cmd.Delete(&options.SecgroupIdOptions{})
|
||||
cmd.Perform("merge", &options.SecgroupMergeOptions{})
|
||||
cmd.Perform("public", &options.SecgroupIdOptions{})
|
||||
cmd.Perform("private", &options.SecgroupIdOptions{})
|
||||
cmd.Perform("add-rule", &options.SecgroupsAddRuleOptions{})
|
||||
cmd.Perform("cache-secgroup", &options.SecurityGroupCacheOptions{})
|
||||
cmd.Perform("uncache-secgroup", &options.SecurityGroupUncacheSecurityGroup{})
|
||||
cmd.Perform("purge", &options.SecgroupIdOptions{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user