本文整理汇总了Golang中github.com/coreos/flannel/Godeps/_workspace/src/github.com/mitchellh/goamz/ec2.EC2.Instances方法的典型用法代码示例。如果您正苦于以下问题:Golang EC2.Instances方法的具体用法?Golang EC2.Instances怎么用?Golang EC2.Instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/flannel/Godeps/_workspace/src/github.com/mitchellh/goamz/ec2.EC2
的用法示例。
在下文中一共展示了EC2.Instances方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: detectRouteTableID
func (m *AwsVpcBackend) detectRouteTableID(instanceID string, ec2c *ec2.EC2) error {
resp, err := ec2c.Instances([]string{instanceID}, nil)
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 := ec2.NewFilter()
filter.Add("association.subnet-id", subnetID)
res, err := ec2c.DescribeRouteTables(nil, filter)
if err != nil {
return fmt.Errorf("error describing routeTables for subnetID %s: %v", subnetID, err)
}
if len(res.RouteTables) != 0 {
m.cfg.RouteTableID = res.RouteTables[0].RouteTableId
return nil
}
filter = ec2.NewFilter()
filter.Add("association.main", "true")
filter.Add("vpc-id", vpcID)
res, err = ec2c.DescribeRouteTables(nil, filter)
if err != nil {
log.Info("error describing route tables: ", err)
}
if len(res.RouteTables) == 0 {
return fmt.Errorf("main route table not found")
}
m.cfg.RouteTableID = res.RouteTables[0].RouteTableId
return nil
}
示例2: DetectRouteTableID
func (m *AwsVpcBackend) DetectRouteTableID(instanceID string, ec2c *ec2.EC2) (string, error) {
resp, err := ec2c.Instances([]string{instanceID}, nil)
if err != nil {
return "", fmt.Errorf("error getting instance info: %v", err)
}
subnetID := resp.Reservations[0].Instances[0].SubnetId
log.Info("SubnetId: ", subnetID)
filter := ec2.NewFilter()
filter.Add("association.subnet-id", subnetID)
res, err := ec2c.DescribeRouteTables(nil, filter)
if err != nil {
return "", fmt.Errorf("error describing routeTables for subnetID %s: %v", subnetID, err)
}
return res.RouteTables[0].RouteTableId, nil
}