本文整理匯總了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
}