本文整理汇总了Golang中launchpad/net/goamz/ec2.EC2.SecurityGroups方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.SecurityGroups方法的具体用法?Golang EC2.SecurityGroups怎么用?Golang EC2.SecurityGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/goamz/ec2.EC2
的用法示例。
在下文中一共展示了EC2.SecurityGroups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: groups
func groups(c cmd, conn *ec2.EC2, _ []string) {
resp, err := conn.SecurityGroups(nil, nil)
check(err, "list groups")
var b bytes.Buffer
printf := func(f string, a ...interface{}) {
fmt.Fprintf(&b, f, a...)
}
for _, g := range resp.Groups {
switch {
case groupsFlags.vv:
printf("%s:%s %s %q\n", g.OwnerId, g.Name, g.Id, g.Description)
for _, p := range g.IPPerms {
printf("\t")
printf("\t-proto %s -from %d -to %d", p.Protocol, p.FromPort, p.ToPort)
for _, g := range p.SourceGroups {
printf(" %s", g.Id)
}
for _, ip := range p.SourceIPs {
printf(" %s", ip)
}
printf("\n")
}
case groupsFlags.v:
printf("%s %s %q\n", g.Name, g.Id, g.Description)
case groupsFlags.ids:
printf("%s\n", g.Id)
default:
printf("%s\n", g.Name)
}
}
os.Stdout.Write(b.Bytes())
}
示例2: createGroup
// createGroup creates a new EC2 group and returns it. If it already exists,
// it revokes all its permissions and returns the existing group.
func createGroup(c *C, ec2conn *amzec2.EC2, name, descr string) amzec2.SecurityGroup {
resp, err := ec2conn.CreateSecurityGroup(name, descr)
if err == nil {
return resp.SecurityGroup
}
if err.(*amzec2.Error).Code != "InvalidGroup.Duplicate" {
c.Fatalf("cannot make group %q: %v", name, err)
}
// Found duplicate group, so revoke its permissions and return it.
gresp, err := ec2conn.SecurityGroups(amzec2.SecurityGroupNames(name), nil)
c.Assert(err, IsNil)
gi := gresp.Groups[0]
if len(gi.IPPerms) > 0 {
_, err = ec2conn.RevokeSecurityGroup(gi.SecurityGroup, gi.IPPerms)
c.Assert(err, IsNil)
}
return gi.SecurityGroup
}