本文整理匯總了Golang中github.com/coreos/flannel/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/ec2.EC2.DescribeRouteTables方法的典型用法代碼示例。如果您正苦於以下問題:Golang EC2.DescribeRouteTables方法的具體用法?Golang EC2.DescribeRouteTables怎麽用?Golang EC2.DescribeRouteTables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/flannel/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/ec2.EC2
的用法示例。
在下文中一共展示了EC2.DescribeRouteTables方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkMatchingRoutes
func (m *AwsVpcBackend) checkMatchingRoutes(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{&m.cfg.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
}
示例2: 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
}