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


Golang ECS.DescribeContainerInstances方法代码示例

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


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

示例1: describeEc2Instances

// describeEc2Instances Describes EC2 instances by container istance ID
func describeEc2Instances(svc *ecs.ECS, cluster *string, containerInstances []*string) (*ec2.DescribeInstancesOutput, error) {

	params := &ecs.DescribeContainerInstancesInput{
		Cluster:            cluster,
		ContainerInstances: containerInstances,
	}
	ins, err := svc.DescribeContainerInstances(params)
	if err != nil {
		return nil, err
	}
	insfail := cli.Failure(ins.Failures, err)
	if insfail != nil {
		return nil, insfail
	}
	var ec2Instances = make([]*string, len(ins.ContainerInstances))
	for i, v := range ins.ContainerInstances {
		ec2Instances[i] = v.Ec2InstanceId
	}
	ec2client := ec2.New(sess.InitSession())
	ec2params := &ec2.DescribeInstancesInput{
		DryRun:      aws.Bool(false),
		InstanceIds: ec2Instances,
	}
	return ec2client.DescribeInstances(ec2params)
}
开发者ID:gawkermedia,项目名称:ecs,代码行数:26,代码来源:task.go

示例2: GetEc2InstanceIdsFromContainerInstances

func GetEc2InstanceIdsFromContainerInstances(ecs_obj *ecs.ECS, cluster string, container_instances []string, debug bool) ([]string, error) {
	params := &ecs.DescribeContainerInstancesInput{
		Cluster:            aws.String(cluster),
		ContainerInstances: aws.StringSlice(container_instances),
	}
	resp, err := ecs_obj.DescribeContainerInstances(params)

	if err != nil {
		return []string{}, fmt.Errorf("Cannot retrieve ECS container instance information: %s", FormatAwsError(err))
	}

	if len(resp.ContainerInstances) <= 0 {
		return []string{}, fmt.Errorf("No ECS container instances found with specified filter - cluster:", cluster, "- instances:", strings.Join(container_instances, ", "))
	}

	var result []string
	for _, value := range resp.ContainerInstances {
		if *value.Status == "ACTIVE" {
			result = append(result, *value.Ec2InstanceId)
		} else {
			if debug == true {
				fmt.Println(*value.Ec2InstanceId, "is not in an ACTIVE state, excluded from results.")
			}
		}
	}

	if len(result) == 0 {
		return []string{}, fmt.Errorf("No running ECS container instances found in result set, cannot proceed.")
	}
	return result, nil
}
开发者ID:CpuID,项目名称:ecs-discoverer,代码行数:31,代码来源:shared.go

示例3: GetContainerInstances

// GetContainerInstances will return a slice of ECS Container Instances within a cluster
func GetContainerInstances(svc *ecs.ECS, ec2svc *ec2.EC2, cluster *string) (containerInstances []*ecs.ContainerInstance, instances []*ec2.Reservation, e error) {

	var ciArns []*string

	// List clusters
	reqParams := &ecs.ListContainerInstancesInput{
		Cluster:    cluster,
		MaxResults: aws.Int64(100),
		NextToken:  aws.String(""),
	}

	// Loop through tokens until no more results remain
	for {
		resp, err := svc.ListContainerInstances(reqParams)

		// Error check
		if err != nil {
			return nil, nil, fmt.Errorf("ecs.ListContainerInstances: %s", err.Error())
		}

		// Expand slice of container instances and append to our comprehensive list
		ciArns = append(ciArns, resp.ContainerInstanceArns...)

		// Cycle token
		if resp.NextToken != nil {
			reqParams.NextToken = resp.NextToken
		} else {
			// Kill loop ... out of response pages
			break
		}

	}

	// Describe the tasks that we just got back
	ciResponse, err := svc.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
		Cluster:            cluster,
		ContainerInstances: ciArns,
	})

	if err != nil {
		return nil, nil, fmt.Errorf("ecs.DescribeContainerInstances: %s", err.Error())
	}

	var instanceIds []*string
	for _, k := range ciResponse.ContainerInstances {
		instanceIds = append(instanceIds, k.Ec2InstanceId)
	}

	// Create a map of container instances by ci arn...
	// Note: Will work for <= 1000 instances w/o having to use NextToken
	ec2Resp, err := ec2svc.DescribeInstances(&ec2.DescribeInstancesInput{
		InstanceIds: instanceIds,
	})

	if err != nil {
		return nil, nil, fmt.Errorf("ec2.DescribeInstances: %s", err.Error())
	}

	return ciResponse.ContainerInstances, ec2Resp.Reservations, nil
}
开发者ID:colinmutter,项目名称:go-ecs,代码行数:61,代码来源:ecs.go

示例4: instanceIds

func instanceIds(e *ecspkg.ECS, containerInstances []*string) []*string {
	output, err := e.DescribeContainerInstances(&ecspkg.DescribeContainerInstancesInput{
		ContainerInstances: containerInstances,
	})
	log.Check(err)
	var ids []*string
	for _, i := range output.ContainerInstances {
		ids = append(ids, i.Ec2InstanceId)
	}
	return ids
}
开发者ID:travisjeffery,项目名称:ecs-exec,代码行数:11,代码来源:exec.go


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