本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ecs.ECS类的典型用法代码示例。如果您正苦于以下问题:Golang ECS类的具体用法?Golang ECS怎么用?Golang ECS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ECS类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: VerifyServiceExists
// Verify that the ECS service exists.
func VerifyServiceExists(ecs_obj *ecs.ECS, cluster string, service string) error {
params := &ecs.DescribeServicesInput{
Cluster: &cluster,
Services: []*string{ // Required
aws.String(service), // Required
},
}
_, err := ecs_obj.DescribeServices(params)
if err != nil {
return fmt.Errorf("Cannot verify if ECS service exists: %s", FormatAwsError(err))
}
return nil
}
开发者ID:CpuID,项目名称:ecs-discoverer,代码行数:15,代码来源:shared.go
示例17: findClusterArn
// findClusterArn finds a cluster's arn from a more human
// readable name
func findClusterArn(svc *ecs.ECS, clusterName string) (string, error) {
params := &ecs.ListClustersInput{}
clusters, err := svc.ListClusters(params)
if err != nil {
return "", err
}
for _, clusterId := range clusters.ClusterArns {
var pattern string = `/` + clusterName + `$`
matched, _ := regexp.MatchString(pattern, *clusterId)
if matched {
return *clusterId, nil
}
}
return "", errors.New("Could not find cluster with name: " + clusterName)
}
开发者ID:oberd,项目名称:aws-rollout,代码行数:17,代码来源:aws-rollout.go
示例18: setImage
// setImage
// Create a new Task Definition based on an existing
// ARN, and a new image.
//
// Returns new task's ARN
//
func setImage(svc *ecs.ECS, taskArn string, image string) (string, error) {
params := &ecs.DescribeTaskDefinitionInput{TaskDefinition: aws.String(taskArn)}
resp, err := svc.DescribeTaskDefinition(params)
if err != nil {
return "", err
}
task := resp.TaskDefinition
task.ContainerDefinitions[0].Image = &image
regResp, err := svc.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{
Family: task.Family,
ContainerDefinitions: task.ContainerDefinitions,
Volumes: task.Volumes,
})
return *regResp.TaskDefinition.TaskDefinitionArn, nil
}
开发者ID:oberd,项目名称:aws-rollout,代码行数:21,代码来源:aws-rollout.go
示例19: GetContainerInstanceArnsForService
func GetContainerInstanceArnsForService(ecs_obj *ecs.ECS, cluster string, service string, local_container_instance_arn string, debug bool) ([]string, error) {
// Fetch a task list based on the service name.
list_tasks_params := &ecs.ListTasksInput{
Cluster: &cluster,
ServiceName: &service,
}
list_tasks_resp, list_tasks_err := ecs_obj.ListTasks(list_tasks_params)
if list_tasks_err != nil {
return []string{}, fmt.Errorf("Cannot retrieve ECS task list: %s", FormatAwsError(list_tasks_err))
}
if len(list_tasks_resp.TaskArns) <= 0 {
return []string{}, fmt.Errorf("No ECS tasks found with specified filter - cluster: ", cluster, ", service:", service)
}
// Describe the tasks retrieved above.
describe_tasks_params := &ecs.DescribeTasksInput{
Cluster: &cluster,
Tasks: list_tasks_resp.TaskArns,
}
describe_tasks_resp, describe_tasks_err := ecs_obj.DescribeTasks(describe_tasks_params)
if describe_tasks_err != nil {
return []string{}, fmt.Errorf("Cannot retrieve ECS task details:", FormatAwsError(describe_tasks_err))
}
if len(describe_tasks_resp.Tasks) <= 0 {
return []string{}, fmt.Errorf("No ECS task details found with specified filter - tasks:", strings.Join(aws.StringValueSlice(list_tasks_resp.TaskArns), ", "))
}
var result []string
for _, value := range describe_tasks_resp.Tasks {
if *value.LastStatus == "RUNNING" && *value.ContainerInstanceArn != local_container_instance_arn {
result = append(result, *value.ContainerInstanceArn)
} else {
if debug == true {
fmt.Println(*value.ContainerInstanceArn, "is not in a RUNNING state, or is this instance (we dont return ourself). Excluded from results.")
}
}
}
if len(result) == 0 {
return []string{}, fmt.Errorf("No ECS task results found in RUNNING state, no ECS container instances to return.")
}
return result, nil
}
开发者ID:CpuID,项目名称:ecs-discoverer,代码行数:47,代码来源:shared.go
示例20: findServiceArn
// findServiceArn finds a service arn from a more human
// readable name
func findServiceArn(svc *ecs.ECS, clusterArn string, serviceName string) (string, error) {
params := &ecs.ListServicesInput{
Cluster: aws.String(clusterArn),
}
services, err := svc.ListServices(params)
if err != nil {
return "", err
}
for _, serviceId := range services.ServiceArns {
var pattern string = `/` + serviceName + `$`
matched, _ := regexp.MatchString(pattern, *serviceId)
if matched {
return *serviceId, nil
}
}
return "", errors.New("Could not find service with name: " + serviceName)
}
开发者ID:oberd,项目名称:aws-rollout,代码行数:19,代码来源:aws-rollout.go
注:本文中的github.com/aws/aws-sdk-go/service/ecs.ECS类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论