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