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


Golang ec2.EC2类代码示例

本文整理汇总了Golang中github.com/coreos/flannel/Godeps/_workspace/src/github.com/mitchellh/goamz/ec2.EC2的典型用法代码示例。如果您正苦于以下问题:Golang EC2类的具体用法?Golang EC2怎么用?Golang EC2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkMatchingRoutes

func (m *AwsVpcBackend) checkMatchingRoutes(instanceID, subnet string, ec2c *ec2.EC2) (bool, error) {

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

	matchingRouteFound := false

	resp, err := ec2c.DescribeRouteTables([]string{m.cfg.RouteTableID}, filter)
	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:nathanleiby,项目名称:flannel,代码行数:29,代码来源:awsvpc.go

示例2: disableSrcDestCheck

func (m *AwsVpcBackend) disableSrcDestCheck(instanceID string, ec2c *ec2.EC2) (*ec2.ModifyInstanceResp, error) {
	modifyAttributes := &ec2.ModifyInstance{
		SourceDestCheck:    false,
		SetSourceDestCheck: true,
	}

	return ec2c.ModifyInstance(instanceID, modifyAttributes)
}
开发者ID:nathanleiby,项目名称:flannel,代码行数:8,代码来源:awsvpc.go

示例3: createRoute

func (m *AwsVpcBackend) createRoute(instanceID, subnet string, ec2c *ec2.EC2) (*ec2.SimpleResp, error) {
	route := &ec2.CreateRoute{
		RouteTableId:         m.cfg.RouteTableID,
		InstanceId:           instanceID,
		DestinationCidrBlock: subnet,
	}

	return ec2c.CreateRoute(route)
}
开发者ID:nathanleiby,项目名称:flannel,代码行数:9,代码来源:awsvpc.go

示例4: terminateInstances

func terminateInstances(c *C, e *ec2.EC2, insts []*ec2.Instance) {
	var ids []string
	for _, inst := range insts {
		if inst != nil {
			ids = append(ids, inst.InstanceId)
		}
	}
	_, err := e.TerminateInstances(ids)
	c.Check(err, IsNil, Commentf("%d INSTANCES LEFT RUNNING!!!", len(ids)))
}
开发者ID:MarkBruns,项目名称:flannel,代码行数:10,代码来源:ec2t_test.go

示例5: 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
}
开发者ID:MarkBruns,项目名称:flannel,代码行数:19,代码来源:awsvpc.go

示例6: 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
}
开发者ID:nathanleiby,项目名称:flannel,代码行数:50,代码来源:awsvpc.go


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