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


Golang EC2.DescribeRouteTables方法代码示例

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


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

示例1: findResourceRoute

// Helper: retrieve a route
func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, error) {
	routeTableID := rtbid

	findOpts := &ec2.DescribeRouteTablesInput{
		RouteTableIds: []*string{&routeTableID},
	}

	resp, err := conn.DescribeRouteTables(findOpts)
	if err != nil {
		return nil, err
	}

	if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil {
		return nil, fmt.Errorf("Route table %s is gone, so route does not exist.",
			routeTableID)
	}

	for _, route := range (*resp.RouteTables[0]).Routes {
		if *route.DestinationCidrBlock == cidr {
			return route, nil
		}
	}

	return nil, fmt.Errorf(`
error finding matching route for Route table (%s) and destination CIDR block (%s)`,
		rtbid, cidr)
}
开发者ID:tompao,项目名称:terraform,代码行数:28,代码来源:resource_aws_route.go

示例2: getPrivateRouteTable

func getPrivateRouteTable(svc *ec2.EC2, subnetid *string, VpcId string) (*string, error) {
	keyname := "association.subnet-id"
	filters := make([]*ec2.Filter, 0)
	filter := ec2.Filter{
		Name: &keyname, Values: []*string{subnetid}}
	filters = append(filters, &filter)

	//fmt.Println("Filters ", filters)

	drti := &ec2.DescribeRouteTablesInput{Filters: filters}
	drto, err := svc.DescribeRouteTables(drti)
	if err != nil {
		panic(err)
	}

	for i := range drto.RouteTables {
		if *drto.RouteTables[i].VpcId == VpcId {
			//fmt.Println("Route table is", *drto.RouteTables[i].RouteTableId)
			return drto.RouteTables[i].RouteTableId, nil
		}
	}

	return nil, errors.New(fmt.Sprintf("No route table found for subnet", *subnetid))

}
开发者ID:jamesunger,项目名称:saws,代码行数:25,代码来源:saws.go

示例3: resourceAwsVpcSetDefaultRouteTable

func resourceAwsVpcSetDefaultRouteTable(conn *ec2.EC2, d *schema.ResourceData) error {
	filter1 := &ec2.Filter{
		Name:   aws.String("association.main"),
		Values: []*string{aws.String("true")},
	}
	filter2 := &ec2.Filter{
		Name:   aws.String("vpc-id"),
		Values: []*string{aws.String(d.Id())},
	}

	findOpts := &ec2.DescribeRouteTablesInput{
		Filters: []*ec2.Filter{filter1, filter2},
	}

	resp, err := conn.DescribeRouteTables(findOpts)
	if err != nil {
		return err
	}

	if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil {
		return fmt.Errorf("Default Route table not found")
	}

	// There Can Be Only 1 ... Default Route Table
	d.Set("default_route_table_id", resp.RouteTables[0].RouteTableId)

	return nil
}
开发者ID:koding,项目名称:terraform,代码行数:28,代码来源:resource_aws_vpc.go

示例4: getMainRouteTableFromVPC

func getMainRouteTableFromVPC(svc *ec2.EC2, VpcId *string) (*string, error) {

	keyname := "association.main"
	asbool := "true"
	filters := make([]*ec2.Filter, 0)
	filter := ec2.Filter{
		Name: &keyname, Values: []*string{&asbool}}
	filters = append(filters, &filter)

	//fmt.Println("Filters ", filters)

	drti := &ec2.DescribeRouteTablesInput{Filters: filters}
	drto, err := svc.DescribeRouteTables(drti)
	if err != nil {
		panic(err)
	}

	for i := range drto.RouteTables {
		if *drto.RouteTables[i].VpcId == *VpcId {
			//fmt.Println("Route table is", *drto.RouteTables[i].RouteTableId)
			return drto.RouteTables[i].RouteTableId, nil
		}
	}

	return nil, errors.New(fmt.Sprintf("No main route table found for vpc", *VpcId))

}
开发者ID:jamesunger,项目名称:saws,代码行数:27,代码来源:saws.go

示例5: checkMatchingRoutes

func (be *AwsVpcBackend) checkMatchingRoutes(routeTableID, instanceID, subnet string, ec2c *ec2.EC2) (bool, error) {
	matchingRouteFound := false

	filter := newFilter()
	filter.Add("route.destination-cidr-block", subnet)
	filter.Add("route.state", "active")

	input := ec2.DescribeRouteTablesInput{Filters: filter, RouteTableIds: []*string{&routeTableID}}

	resp, err := ec2c.DescribeRouteTables(&input)
	if err != nil {
		return matchingRouteFound, err
	}

	for _, routeTable := range resp.RouteTables {
		for _, route := range routeTable.Routes {
			if subnet == *route.DestinationCidrBlock && *route.State == "active" {

				if *route.InstanceId == instanceID {
					matchingRouteFound = true
					break
				}

				log.Errorf("Deleting invalid *active* matching route: %s, %s \n", *route.DestinationCidrBlock, *route.InstanceId)
			}
		}
	}

	return matchingRouteFound, nil
}
开发者ID:luxas,项目名称:flannel,代码行数:30,代码来源:awsvpc.go

示例6: detectRouteTableID

func (be *AwsVpcBackend) detectRouteTableID(instanceID string, ec2c *ec2.EC2) (string, error) {
	instancesInput := &ec2.DescribeInstancesInput{
		InstanceIds: []*string{&instanceID},
	}

	resp, err := ec2c.DescribeInstances(instancesInput)
	if err != nil {
		return "", fmt.Errorf("error getting instance info: %v", err)
	}

	if len(resp.Reservations) == 0 {
		return "", fmt.Errorf("no reservations found")
	}

	if len(resp.Reservations[0].Instances) == 0 {
		return "", fmt.Errorf("no matching instance found with id: %v", instanceID)
	}

	subnetID := resp.Reservations[0].Instances[0].SubnetId
	vpcID := resp.Reservations[0].Instances[0].VpcId

	log.Info("Subnet-ID: ", *subnetID)
	log.Info("VPC-ID: ", *vpcID)

	filter := newFilter()
	filter.Add("association.subnet-id", *subnetID)

	routeTablesInput := &ec2.DescribeRouteTablesInput{
		Filters: filter,
	}

	res, err := ec2c.DescribeRouteTables(routeTablesInput)
	if err != nil {
		return "", fmt.Errorf("error describing routeTables for subnetID %s: %v", *subnetID, err)
	}

	if len(res.RouteTables) != 0 {
		return *res.RouteTables[0].RouteTableId, nil
	}

	filter = newFilter()
	filter.Add("association.main", "true")
	filter.Add("vpc-id", *vpcID)

	routeTablesInput = &ec2.DescribeRouteTablesInput{
		Filters: filter,
	}

	res, err = ec2c.DescribeRouteTables(routeTablesInput)
	if err != nil {
		log.Info("error describing route tables: ", err)
	}

	if len(res.RouteTables) == 0 {
		return "", fmt.Errorf("main route table not found")
	}

	return *res.RouteTables[0].RouteTableId, nil
}
开发者ID:luxas,项目名称:flannel,代码行数:59,代码来源:awsvpc.go

示例7: findMainRouteTable

func findMainRouteTable(conn *ec2.EC2, vpcId string) (*ec2.RouteTable, error) {
	mainFilter := &ec2.Filter{
		Name:   aws.String("association.main"),
		Values: []*string{aws.String("true")},
	}
	vpcFilter := &ec2.Filter{
		Name:   aws.String("vpc-id"),
		Values: []*string{aws.String(vpcId)},
	}
	routeResp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
		Filters: []*ec2.Filter{mainFilter, vpcFilter},
	})
	if err != nil {
		return nil, err
	} else if len(routeResp.RouteTables) != 1 {
		return nil, nil
	}

	return routeResp.RouteTables[0], nil
}
开发者ID:rgl,项目名称:terraform,代码行数:20,代码来源:resource_aws_main_route_table_association.go

示例8: findResourceRoute

// Helper: retrieve a route
func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, error) {
	routeTableID := rtbid

	findOpts := &ec2.DescribeRouteTablesInput{
		RouteTableIds: []*string{&routeTableID},
	}

	resp, err := conn.DescribeRouteTables(findOpts)
	if err != nil {
		return nil, err
	}

	for _, route := range (*resp.RouteTables[0]).Routes {
		if *route.DestinationCidrBlock == cidr {
			return route, nil
		}
	}

	return nil, nil
}
开发者ID:morts1a,项目名称:terraform,代码行数:21,代码来源:resource_aws_route.go

示例9: instanceIDToRouteTableID

// 指定したInstance IDが登録されているRouteTable IDを返す
// ToDo: MySQL VIP用RouteTableが複数返されたらどーすんべ対応
func instanceIDToRouteTableID(svc *ec2.EC2, InstanceID string) string {
	findOpts := &ec2.DescribeRouteTablesInput{
		Filters: []*ec2.Filter{
			{
				Name: aws.String("route.instance-id"),
				Values: []*string{
					aws.String(InstanceID),
				},
			},
		},
	}
	resp, err := svc.DescribeRouteTables(findOpts)
	var routetableID string
	for _, idx := range resp.RouteTables {
		for _, rtbs := range idx.Associations {
			routetableID = *rtbs.RouteTableId
		}
	}
	if err != nil {
		panic(err)
	}
	return routetableID
}
开发者ID:SatoHiroyuki,项目名称:mysqlfailgover,代码行数:25,代码来源:main.go

示例10: resourceAwsRouteTableStateRefreshFunc

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

		rt := resp.RouteTables[0]
		return rt, "ready", nil
	}
}
开发者ID:mnbbrown,项目名称:terraform,代码行数:26,代码来源:resource_aws_route_table.go

示例11: validateRouteTable

func validateRouteTable(ec2Client *ec2.EC2, routeTable *providers.RouteTable, vpc *providers.Vpc, createIfNotFound bool) (success bool, warnings []string, err []error) {

	routeTableName := routeTable.RouteTableName
	log.WithFields(log.Fields{
		"VpcID":          vpc.VpcID,
		"RouteTableName": routeTableName,
	}).Info("Querying AWS for VPC Route Table")
	filters := []*ec2.Filter{}
	if routeTable.IsMain {
		filters = append(filters, newEc2Filter("association.main", "true"))
	} else {
		filters = append(filters, newEc2Filter("tag:"+nameTag, routeTableName))
	}
	filters = append(filters, newEc2Filter("vpc-id", vpc.VpcID))
	//Query route table
	log.Debugf("Filters are : %v", filters)
	params := &ec2.DescribeRouteTablesInput{Filters: filters}
	routeTableQueryOutput, rtErr := ec2Client.DescribeRouteTables(params)

	if rtErr != nil {
		success = false
		err = append(err, rtErr)
	} else {
		//RouteTable exists
		if len(routeTableQueryOutput.RouteTables) > 0 {
			if routeTable.IsMain {
				log.WithFields(log.Fields{
					"routeTable": *routeTableQueryOutput.RouteTables[0].RouteTableID,
				}).Info("Configuring main route table")
				//Lets check and see if the route table we found is the default route table, and use that one
				for tag := range routeTableQueryOutput.RouteTables[0].Tags {
					log.Infof("tag %v key is %s and value is %s", *routeTableQueryOutput.RouteTables[0].Tags[tag].Key, *routeTableQueryOutput.RouteTables[0].Tags[tag].Value)
				}
				if tagContains(routeTableQueryOutput.RouteTables[0].Tags, "Name", routeTable.RouteTableName) {
					success = true
					routeTable.RouteTableID = *routeTableQueryOutput.RouteTables[0].RouteTableID
				} else {
					tagCreated, tagErr := addDockerTagToResource(ec2Client, *routeTableQueryOutput.RouteTables[0].RouteTableID, vpc.Name, routeTableName)
					if tagErr != nil {
						log.WithFields(log.Fields{
							"AWS Error": err,
						}).Error("Error Tagging Route Table")
						//This will not stop the processing of the provider configuration, but we will return a warning so the user knows
						success = true
						warnings = append(warnings, "WARNING: Error creating tag for "+routeTableName+", processing will continue")
					} else {
						log.WithFields(log.Fields{
							"Created": tagCreated,
						}).Info("Tag Created")
						success = true
					}
				}
			}
			for r := range routeTable.Routes {
				vrSuccess, vrWarnings, vrErrors := validateRoute(ec2Client, &routeTable.Routes[r], routeTableQueryOutput, vpc.InternetGateway.InternetGatewayID)
				if vrSuccess {
					for vrw := range vrWarnings {
						warnings = append(warnings, vrWarnings[vrw])
					}
					success = true
				} else {
					for vre := range vrErrors {
						err = append(err, vrErrors[vre])
					}
					success = false
				}
			}
			if success && !routeTable.IsMain {
				log.Infof("Starting to validate Assocoations for %v", routeTableQueryOutput)
				vaSuccess, vaWarnings, vaErrors := validateAssociations(ec2Client, routeTable, routeTableQueryOutput.RouteTables[0].Associations, vpc.Subnets)
				if vaSuccess {
					for vaw := range vaWarnings {
						warnings = append(warnings, vaWarnings[vaw])
					}
					success = true
				} else {
					for vae := range vaErrors {
						err = append(err, vaErrors[vae])
					}
					success = false
				}
			}

		} else {
			//Does not exist
			callSuccess, rtCreateWarn, rtCreateErr := addRouteTable(ec2Client, routeTable, vpc)
			if callSuccess {
				//call was successful
				if len(rtCreateWarn) > 0 {
					outputWarnings("Adding Route Table", "addRouteTable", rtCreateWarn)
				}
				success = true
				//now lets retrieve the new routetable from aws
				rtFilters := []*ec2.Filter{}
				rtFilters = append(rtFilters, newEc2Filter("tag:"+nameTag, routeTableName))
				rtFilters = append(rtFilters, newEc2Filter("vpc-id", vpc.VpcID))
				rtParams := &ec2.DescribeRouteTablesInput{Filters: rtFilters}

				newRouteTableQueryOutput, rtErr := ec2Client.DescribeRouteTables(rtParams)
				if rtErr != nil {
//.........这里部分代码省略.........
开发者ID:podtools,项目名称:pod,代码行数:101,代码来源:Awsprovider.go


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