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


Golang EC2.DescribeSubnets方法代码示例

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


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

示例1: getAzFromSubnetId

func getAzFromSubnetId(subnetId string, conn *ec2.EC2) (string, error) {
	input := ec2.DescribeSubnetsInput{
		SubnetIds: []*string{aws.String(subnetId)},
	}
	out, err := conn.DescribeSubnets(&input)
	if err != nil {
		return "", err
	}

	if l := len(out.Subnets); l != 1 {
		return "", fmt.Errorf("Expected exactly 1 subnet returned for %q, got: %d", subnetId, l)
	}

	return *out.Subnets[0].AvailabilityZone, nil
}
开发者ID:partamonov,项目名称:terraform,代码行数:15,代码来源:resource_aws_efs_mount_target.go

示例2: getSubnetsInVPC

// Gets a slice of subnets from the API for the specified VPC
func getSubnetsInVPC(vpcid string, ec2client *ec2.EC2) ([]*ec2.Subnet, error) {
	subnetReq := ec2.DescribeSubnetsInput{
		Filters: []*ec2.Filter{
			{
				Name: aws.String("vpc-id"),
				Values: []*string{
					aws.String(vpcid),
				},
			},
		},
	}

	subnetResp, err := ec2client.DescribeSubnets(&subnetReq)
	if err != nil {
		return []*ec2.Subnet{}, err
	}

	return subnetResp.Subnets, nil
}
开发者ID:roo7break,项目名称:cracklord,代码行数:20,代码来源:aws-api.go

示例3: validateSubnet

func validateSubnet(ec2Client *ec2.EC2, subnet *providers.Subnet, providerConfig *providers.JSONObject, createIfNotFound bool) (success bool, warnings []string, err []error) {
	//Query for Subnet by Name
	filters := []*ec2.Filter{newEc2Filter("tag:"+nameTag, subnet.SubnetName)}
	params := &ec2.DescribeSubnetsInput{Filters: filters}
	subnetDescribeOutput, callErr := ec2Client.DescribeSubnets(params)
	if callErr != nil {
		err = append(err, callErr)
		success = false
	} else {
		if len(subnetDescribeOutput.Subnets) == 0 {
			//Subnet does not exists
			if createIfNotFound {
				//create subnet
				createSubnetSuccess, createSubnetWarnings, createSubnetErrors := addSubnet(ec2Client, subnet, providerConfig)
				if createSubnetSuccess {
					success = true
					for w := range createSubnetWarnings {
						warnings = append(warnings, createSubnetWarnings[w])
					}
				} else {
					success = false
					for e := range createSubnetErrors {
						err = append(err, createSubnetErrors[e])
					}
				}
			} else {
				err = append(err, errors.New("Subnet does not exist and create if not found is false"))
				success = false
			}
		} else {
			//subnet exists
			success = true
		}
	}

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

示例4: SubnetStateRefreshFunc

// SubnetStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch a Subnet.
func SubnetStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		resp, err := conn.DescribeSubnets(&ec2.DescribeSubnetsInput{
			SubnetIds: []*string{aws.String(id)},
		})
		if err != nil {
			if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidSubnetID.NotFound" {
				resp = nil
			} else {
				log.Printf("Error on SubnetStateRefresh: %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
		}

		subnet := resp.Subnets[0]
		return subnet, *subnet.State, nil
	}
}
开发者ID:morts1a,项目名称:terraform,代码行数:25,代码来源:resource_aws_subnet.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.DescribeSubnets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。