当前位置: 首页>>代码示例>>Golang>>正文


Golang EC2.DescribeInternetGateways方法代码示例

本文整理汇总了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
	}
}
开发者ID:fromonesrc,项目名称:terraform,代码行数:27,代码来源:resource_aws_internet_gateway.go

示例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
}
开发者ID:podtools,项目名称:pod,代码行数:42,代码来源:Awsprovider.go

示例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
}
开发者ID:jamesunger,项目名称:saws,代码行数:20,代码来源:saws.go

示例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
	}
}
开发者ID:Zordrak,项目名称:terraform,代码行数:42,代码来源:resource_aws_internet_gateway.go


注:本文中的github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeInternetGateways方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。