當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ecs.ECS類代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/ecs.ECS的典型用法代碼示例。如果您正苦於以下問題:Golang ECS類的具體用法?Golang ECS怎麽用?Golang ECS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ECS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getServiceTasks

//
// Given a service, fetches the tasks associated with it and returns them in an array.
//
func getServiceTasks(awsConn *ecs.ECS, clusterName string, serviceName string) []*ecs.Task {
	taskOutput, err := awsConn.ListTasks(&ecs.ListTasksInput{
		Cluster:     &clusterName,
		ServiceName: &serviceName,
	})
	CheckError("fetching task list for service", err)
	var serviceTasks []*ecs.Task
	if len(taskOutput.TaskArns) > 0 {
		taskInfo, err := awsConn.DescribeTasks(&ecs.DescribeTasksInput{
			Tasks:   taskOutput.TaskArns,
			Cluster: &clusterName,
		})
		CheckError("fetching task data for service", err)
		serviceTasks = taskInfo.Tasks
	}
	return serviceTasks
}
開發者ID:masonoise,項目名稱:ecsman,代碼行數:20,代碼來源:tasks.go

示例2: ListClusters

// ListClusters will return a slice of ECS Clusters
func ListClusters(svc *ecs.ECS) ([]*string, error) {
	var clusters []*string

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

	for {
		resp, err := svc.ListClusters(reqParams)

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

		// Expand slice of clusters and append to our comprehensive list
		clusters = append(clusters, resp.ClusterArns...)

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

	}

	return clusters, nil
}
開發者ID:colinmutter,項目名稱:go-ecs,代碼行數:33,代碼來源:ecs.go

示例3: 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

示例4: 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

示例5: 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

示例6: PrintTaskDefinition

//
// Function to print the details of a service's task definition, since it's got a lot of fiddly details.
//
func PrintTaskDefinition(awsConn *ecs.ECS, taskDefinition *string, verboseFlag bool) {
	// Fetch the details of the task definition.
	taskDef, err := awsConn.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
		TaskDefinition: taskDefinition,
	})
	CheckError(fmt.Sprintf("fetching Task Definition for %s", *taskDefinition), err)
	fmt.Println("  - Task Definition:", *taskDefinition)
	fmt.Println("    - Family:", *taskDef.TaskDefinition.Family)
	for _, containerDef := range taskDef.TaskDefinition.ContainerDefinitions {
		fmt.Println("    - Container Definition:")
		fmt.Println("      - Image:", *containerDef.Image)
		if verboseFlag {
			fmt.Println("      - CPU:", *containerDef.Cpu)
			fmt.Println("      - Memory:", *containerDef.Memory)
		}
		for _, portMap := range containerDef.PortMappings {
			fmt.Println("      - Container Port", *portMap.ContainerPort, ": Host Port", *portMap.HostPort)
		}
		if len(containerDef.Command) > 0 {
			fmt.Printf("      - Command: %v\n", containerDef.Command)
		}
		if len(containerDef.EntryPoint) > 0 {
			fmt.Printf("      - Entry Point: %v\n", containerDef.EntryPoint)
		}
		if (len(containerDef.Environment) > 0) && (verboseFlag) {
			fmt.Println("      - Environment:")
			for _, envVariable := range containerDef.Environment {
				fmt.Println("       ", *envVariable.Name, "=", *envVariable.Value)
			}
		}
	}
}
開發者ID:masonoise,項目名稱:ecsman,代碼行數:35,代碼來源:tasks.go

示例7: ListClusters

// ListClusters List ECS clusters
func ListClusters(svc *ecs.ECS, maxResults *int64) (*ecs.ListClustersOutput, error) {
	params := &ecs.ListClustersInput{
		MaxResults: maxResults,
	}
	resp, err := svc.ListClusters(params)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:11,代碼來源:cluster.go

示例8: DeleteCluster

// DeleteCluster Removes an ECS cluster
func DeleteCluster(svc *ecs.ECS, name *string) (*ecs.DeleteClusterOutput, error) {
	params := &ecs.DeleteClusterInput{
		Cluster: name,
	}
	resp, err := svc.DeleteCluster(params)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:11,代碼來源:cluster.go

示例9: findTaskArn

// findTaskArn
// finds the first task definition in a cluster and service.
//
// Returns task ARN
//
// TODO:
//   filter the resulting tasks by essential: true
//   and only return the essential?
//   either that or assume that the new image will
//   somewhat match the old image, and use that to pick
//   one of the tasks.
func findTaskArn(svc *ecs.ECS, clusterArn string, serviceArn string) (string, error) {
	params := &ecs.DescribeServicesInput{
		Services: []*string{
			aws.String(serviceArn),
		},
		Cluster: aws.String(clusterArn),
	}
	resp, err := svc.DescribeServices(params)
	return *resp.Services[0].TaskDefinition, err
}
開發者ID:oberd,項目名稱:aws-rollout,代碼行數:21,代碼來源:aws-rollout.go

示例10: 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

示例11: ListTaskDefs

// ListTaskDefs Returns a list of task definitions that are registered to your account. You can filter the results by family name with the family parameter or by status with the status parameter.
func ListTaskDefs(svc *ecs.ECS, familyPrefix *string, status *string) (*ecs.ListTaskDefinitionsOutput, error) {
	params := &ecs.ListTaskDefinitionsInput{
		FamilyPrefix: familyPrefix,
		Status:       status,
	}
	resp, err := svc.ListTaskDefinitions(params)
	if err != nil {
		return resp, err
	}
	return resp, nil
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:12,代碼來源:task.go

示例12: StopTask

// StopTask Stops a task
func StopTask(svc *ecs.ECS, task *string, cluster *string) (*ecs.StopTaskOutput, error) {
	params := &ecs.StopTaskInput{
		Task:    task,
		Cluster: cluster,
	}
	resp, err := svc.StopTask(params)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:12,代碼來源:task.go

示例13: DescribeTasks

// DescribeTasks Describes an ECS task
func DescribeTasks(svc *ecs.ECS, taskArns []*string, cluster *string) (*ecs.DescribeTasksOutput, error) {
	if len(taskArns) == 0 {
		return nil, errors.New("Tasks can not be blank")
	}
	params := &ecs.DescribeTasksInput{
		Tasks:   taskArns,
		Cluster: cluster,
	}
	resp, err := svc.DescribeTasks(params)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:15,代碼來源:task.go

示例14: DescribeCluster

// DescribeCluster will return a Cluster (detail struct)
func DescribeCluster(svc *ecs.ECS, cluster *string) (*ecs.Cluster, error) {
	// Get cluster details for all the things...
	reqParams := &ecs.DescribeClustersInput{
		Clusters: []*string{cluster},
	}

	resp, err := svc.DescribeClusters(reqParams)

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

	return resp.Clusters[0], err
}
開發者ID:colinmutter,項目名稱:go-ecs,代碼行數:15,代碼來源:ecs.go

示例15: StartTask

// StartTask Starts a new task in ECS
func StartTask(svc *ecs.ECS, taskDef *string, containerInstances []*string, cluster *string, startedBy *string, overrides *ecs.TaskOverride) (*ecs.StartTaskOutput, error) {
	params := &ecs.StartTaskInput{
		Cluster:            cluster,
		ContainerInstances: containerInstances,
		TaskDefinition:     taskDef,
		StartedBy:          startedBy,
		Overrides:          overrides,
	}
	resp, err := svc.StartTask(params)
	if err != nil {
		return nil, err
	}
	return resp, err
}
開發者ID:gawkermedia,項目名稱:ecs,代碼行數:15,代碼來源:task.go


注:本文中的github.com/aws/aws-sdk-go/service/ecs.ECS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。