本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeInternetGateways方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.DescribeInternetGateways方法的具体用法?Golang EC2.DescribeInternetGateways怎么用?Golang EC2.DescribeInternetGateways使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/aws-sdk-go/service/ec2.EC2
的用法示例。
在下文中一共展示了EC2.DescribeInternetGateways方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: IGStateRefreshFunc
// IGStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// an internet gateway.
func IGStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysInput{
InternetGatewayIds: []*string{aws.String(id)},
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
resp = nil
} else {
log.Printf("[ERROR] Error on IGStateRefresh: %s", err)
return nil, "", err
}
}
if resp == nil {
// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
}
ig := resp.InternetGateways[0]
return ig, "available", nil
}
}
示例2: validateInternetGateway
func validateInternetGateway(ec2Client *ec2.EC2, providerConfig *providers.JSONObject, createIfNotFound bool) (success bool, warnings []string, err []error) {
filters := []*ec2.Filter{newEc2Filter("attachment.vpc-id", providerConfig.Provider.ProviderConfig.Aws.Vpc.VpcID)}
params := &ec2.DescribeInternetGatewaysInput{Filters: filters}
internetGatewayOutput, callErr := ec2Client.DescribeInternetGateways(params)
if callErr != nil {
err = append(err, callErr)
success = false
} else {
if len(internetGatewayOutput.InternetGateways) > 0 {
providerConfig.Provider.ProviderConfig.Aws.Vpc.InternetGateway.InternetGatewayID = *internetGatewayOutput.InternetGateways[0].InternetGatewayID
success = true
} else {
//Does not exist
createSuccess, createWarning, createError := addInternetGateway(ec2Client, providerConfig)
if createSuccess {
for w := range createWarning {
warnings = append(warnings, createWarning[w])
}
attachSuccess, attachWarnings, attachErrors := attachGatewayToVpc(ec2Client, providerConfig.Provider.ProviderConfig.Aws.Vpc.InternetGateway.InternetGatewayID, providerConfig.Provider.ProviderConfig.Aws.Vpc.VpcID)
if attachSuccess {
for w := range attachWarnings {
warnings = append(warnings, attachWarnings[w])
}
success = true
} else {
for e := range attachErrors {
err = append(err, attachErrors[e])
}
success = false
}
} else {
success = false
for e := range createError {
err = append(err, createError[e])
}
}
}
}
return success, warnings, err
}
示例3: getGatewayIds
func getGatewayIds(c *ec2.EC2, vpcid string) ([]string, error) {
gatewayids := []string{}
filters := make([]*ec2.Filter, 0)
keyname := "attachment.vpc-id"
filter := ec2.Filter{
Name: &keyname, Values: []*string{&vpcid}}
filters = append(filters, &filter)
digi := &ec2.DescribeInternetGatewaysInput{Filters: filters}
digo, err := c.DescribeInternetGateways(digi)
if err != nil {
return gatewayids, err
}
for i := range digo.InternetGateways {
gatewayids = append(gatewayids, *digo.InternetGateways[i].InternetGatewayId)
}
return gatewayids, nil
}
示例4: IGAttachStateRefreshFunc
// IGAttachStateRefreshFunc returns a resource.StateRefreshFunc that is used
// watch the state of an internet gateway's attachment.
func IGAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resource.StateRefreshFunc {
var start time.Time
return func() (interface{}, string, error) {
if start.IsZero() {
start = time.Now()
}
resp, err := conn.DescribeInternetGateways(&ec2.DescribeInternetGatewaysInput{
InternetGatewayIds: []*string{aws.String(id)},
})
if err != nil {
ec2err, ok := err.(awserr.Error)
if ok && ec2err.Code() == "InvalidInternetGatewayID.NotFound" {
resp = nil
} else {
log.Printf("[ERROR] Error on IGStateRefresh: %s", err)
return nil, "", err
}
}
if resp == nil {
// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
}
ig := resp.InternetGateways[0]
if time.Now().Sub(start) > 10*time.Second {
return ig, expected, nil
}
if len(ig.Attachments) == 0 {
// No attachments, we're detached
return ig, "detached", nil
}
return ig, *ig.Attachments[0].State, nil
}
}