當前位置: 首頁>>代碼示例>>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方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:koding,項目名稱: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:roo7break,項目名稱:cracklord,代碼行數:13,代碼來源:aws-api.go

示例3: processVpcs

func processVpcs(svc *ec2.EC2, pageSize int64, apply func([]*string)) {
	vpcsOut, err := svc.DescribeVpcs(&ec2.DescribeVpcsInput{})

	kingpin.FatalIfError(err, "Could not retrieve EC2 VPCs")

	var vpcIds []*string
	for _, vpc := range vpcsOut.Vpcs {
		vpcIds = append(vpcIds, vpc.VpcId)
	}

	apply(vpcIds)
}
開發者ID:sh0tt,項目名稱:awstagger,代碼行數:12,代碼來源:resources.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:mnbbrown,項目名稱:terraform,代碼行數:22,代碼來源:resource_aws_vpc_dhcp_options.go

示例5: verifyAndCreateVPC

func verifyAndCreateVPC(c *ec2.EC2, config *Config) error {

	dvi := &ec2.DescribeVpcsInput{}
	dvo, err := c.DescribeVpcs(dvi)
	if err != nil {
		return err
	}

	vpc := &ec2.Vpc{}
	vpcexists := false
	for i := range dvo.Vpcs {
		if *dvo.Vpcs[i].CidrBlock == config.VPC {
			vpc = dvo.Vpcs[i]
			vpcexists = true
			config.VpcId = *dvo.Vpcs[i].VpcId
			//fmt.Println("VPC already exists.")
		}
	}

	if vpcexists {

		err = createSecurityGroups(c, config)
		if err != nil {
			fmt.Println("Failed to create security groups.")
			panic(err)
		}

		/*
			sgids := getSecurityGroupIds(c,config,
			err = applySecurityGroups(c, config)
			if err != nil {
				fmt.Println("Failed to apply security groups.")
				panic(err)
			}
		*/

		dsi := &ec2.DescribeSubnetsInput{}
		dso, err := c.DescribeSubnets(dsi)
		if err != nil {
			panic(err)
		}

		haspriv := false
		haspub := false
		for i := range dso.Subnets {
			if *dso.Subnets[i].CidrBlock == config.PublicNet {
				//fmt.Println("Subnet for public VPC already exists.")
				config.PublicSubnetId = *dso.Subnets[i].SubnetId
				haspub = true
				continue
			}

			if *dso.Subnets[i].CidrBlock == config.PrivateNet {
				//fmt.Println("Subnet for private VPC already exists.")
				config.PrivateSubnetId = *dso.Subnets[i].SubnetId
				haspriv = true
				continue
			}
		}

		if haspub && haspriv {
			return nil
		}

		cso1, cso2, err := createSubnets(c, config)
		if err != nil {
			panic(err)
		}
		config.PublicSubnetId = *cso1.Subnet.SubnetId
		config.PrivateSubnetId = *cso2.Subnet.SubnetId

		_, err = createPrivateRouteTable(c, config)
		if err != nil {
			panic(err)
		}

		return createGateway(c, vpc, cso1.Subnet.SubnetId)

	}

	cvi := &ec2.CreateVpcInput{CidrBlock: &config.VPC}
	cvo, err := c.CreateVpc(cvi)

	if err != nil {
		return err
	}
	config.VpcId = *cvo.Vpc.VpcId
	fmt.Println("Created new VPC: " + config.VpcId)

	//fmt.Println(cvo)
	err = createSecurityGroups(c, config)
	if err != nil {
		fmt.Println("Failed to create security groups.")
		panic(err)
	}

	/*
		err = applySecurityGroups(c, config)
		if err != nil {
			fmt.Println("Failed to apply security groups.")
//.........這裏部分代碼省略.........
開發者ID:jamesunger,項目名稱:saws,代碼行數:101,代碼來源:saws.go


注:本文中的github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeVpcs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。