當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。