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


Golang EC2.DescribeVPCs方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeVPCs方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.DescribeVPCs方法的具体用法?Golang EC2.DescribeVPCs怎么用?Golang EC2.DescribeVPCs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/ec2.EC2的用法示例。


在下文中一共展示了EC2.DescribeVPCs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: VPCStateRefreshFunc

// VPCStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// a VPC.
func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		DescribeVpcOpts := &ec2.DescribeVPCsInput{
			VPCIDs: []*string{aws.String(id)},
		}
		resp, err := conn.DescribeVPCs(DescribeVpcOpts)
		if err != nil {
			if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
				resp = nil
			} else {
				log.Printf("Error on VPCStateRefresh: %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
		}

		vpc := resp.VPCs[0]
		return vpc, *vpc.State, nil
	}
}
开发者ID:sheldonh,项目名称:terraform,代码行数:27,代码来源:resource_aws_vpc.go

示例2: getAllVPCs

// Get all of the VPCs configured in the environment
func getAllVPCs(ec2client *ec2.EC2) ([]*ec2.VPC, error) {
	//Get all of the VPCs
	vpcs, err := ec2client.DescribeVPCs(&ec2.DescribeVPCsInput{})

	//If we had an error, return it
	if err != nil {
		return []*ec2.VPC{}, err
	}

	//Otherwise, return all of our VPCs
	return vpcs.VPCs, nil
}
开发者ID:NecroApps,项目名称:cracklord,代码行数:13,代码来源:aws-api.go

示例3: validateVPC

/*
validateVPC will query ec2 and see if the VPC exists. If it does not exist, then if
createIfNotFound is true, it will attempt to create it
*/
func validateVPC(ec2Client *ec2.EC2, providerConfig *providers.JSONObject, createIfNotFound bool) (success bool, warnings []string, err []error) {
	vpcName := providerConfig.Provider.ProviderConfig.Aws.Vpc.Name
	log.WithFields(log.Fields{
		"VPC Name": vpcName,
	}).Info("Validating if VPC exists")
	//See if VPC exists
	filters := []*ec2.Filter{newEc2Filter("tag:"+nameTag, vpcName)}
	params := &ec2.DescribeVPCsInput{Filters: filters}
	vpcQueryOutput, callErr := ec2Client.DescribeVPCs(params)

	if err != nil {
		err = append(err, callErr)
		log.WithFields(log.Fields{
			"AWS Error": err,
		}).Error("Error Querying VPC")
	} else {
		if len(vpcQueryOutput.VPCs) > 0 {
			//Found VPC
			log.WithFields(log.Fields{
				"VpcID": providerConfig.Provider.ProviderConfig.Aws.Vpc.VpcID,
			}).Info("VPC Found")
			providerConfig.Provider.ProviderConfig.Aws.Vpc.VpcID = *vpcQueryOutput.VPCs[0].VPCID
			success = true
		} else {
			if createIfNotFound {
				//create new VPC
				createSuccess, createWarning, createError := addVPC(ec2Client, providerConfig)
				if createSuccess {
					success = true
					for w := range createWarning {
						warnings = append(warnings, createWarning[w])
					}
				} else {
					success = false
					for e := range createError {
						err = append(err, createError[e])
					}
				}
			} else {
				//VPC not found and createIfNotFound is false
				err = append(err, errors.New("VPC does not exist and create if not found is false"))
				success = false
			}
		}
	}

	return success, warnings, err
}
开发者ID:podtools,项目名称:pod,代码行数:52,代码来源:Awsprovider.go

示例4: findVPCsByDHCPOptionsID

func findVPCsByDHCPOptionsID(conn *ec2.EC2, id string) ([]*ec2.VPC, error) {
	req := &ec2.DescribeVPCsInput{
		Filters: []*ec2.Filter{
			&ec2.Filter{
				Name: aws.String("dhcp-options-id"),
				Values: []*string{
					aws.String(id),
				},
			},
		},
	}

	resp, err := conn.DescribeVPCs(req)
	if err != nil {
		if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpcID.NotFound" {
			return nil, nil
		}
		return nil, err
	}

	return resp.VPCs, nil
}
开发者ID:rgl,项目名称:terraform,代码行数:22,代码来源:resource_aws_vpc_dhcp_options.go


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