예제 #1
0
// Run is Command implementation method for ClusterListCommand.
func (c *ClusterListCommand) Run(args []string) int {
	var nextToken string
	var max int64
	flags := flag.NewFlagSet("cluster", flag.ContinueOnError)
	flags.StringVar(&nextToken, "next", "", "next token")
	flags.Int64Var(&max, "max", 10, "the number of cluster to show")
	flags.Usage = func() { c.Help() }

	if err := flags.Parse(args); err != nil {
		utils.ErrorOutputf("Error parsing CLI flags: %s", err)
		fmt.Println(c.Help())
		return 1
	}

	input := &ecs.ListClustersInput{
		NextToken:  &nextToken,
		MaxResults: &max,
	}

	client := aws.GetClient()
	resp, err := client.ClusterList(input)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			utils.ErrorOutput(err.Error())
		}
		return 1
	}
	fmt.Println(awsutil.StringValue(resp))
	return 0
}
예제 #2
0
// Run is Command implementation method for ServiceCreateCommand
func (c *ServiceCreateCommand) Run(args []string) int {
	// FIXME support ELB
	// FIXME support idempotent
	var cluster, name, task string
	var desire int64
	flags := flag.NewFlagSet("create", flag.ContinueOnError)
	flags.StringVar(&cluster, "cluster", "default", "cluster name you want service belong to")
	flags.Int64Var(&desire, "desire", 0, "desire count to keep the number of running task")
	flags.StringVar(&name, "name", "", "service name")
	flags.StringVar(&task, "task", "", "task definition you want to attach")
	flags.Usage = func() { c.Help() }

	if err := flags.Parse(args); err != nil {
		utils.ErrorOutputf("Error parsing CLI flags: %s", err)
		fmt.Println(c.Help())
		return 1
	}

	input, err := generateCreateServiceInput(cluster, name, task, desire)
	if err != nil {
		utils.ErrorOutput(err.Error())
		return 1
	}

	client := aws.GetClient()
	resp, err := client.ServiceCreate(input)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			utils.ErrorOutput(err.Error())
		}
		return 1
	}

	fmt.Printf("Success create service %s.", name)
	fmt.Println(awsutil.StringValue(resp))
	return 0
}
예제 #3
0
// Run is Command implementation method for TaskRegisterCommand.
func (c *TaskRegisterCommand) Run(args []string) int {
	var family, path string
	flags := flag.NewFlagSet("regsiter", flag.ContinueOnError)
	flags.StringVar(&family, "family", "", "task definition family name.")
	flags.StringVar(&path, "path", "task.yml", "the path of configuration file.")
	flags.Usage = func() { c.Help() }

	if err := flags.Parse(args); err != nil {
		utils.ErrorOutputf("Error parsing CLI flags: %s", err)
		fmt.Println(c.Help())
		return 1
	}

	input, err := generateRegisterTaskDefinitionInput(family, path)
	if err != nil {
		utils.ErrorOutput(err.Error())
		return 1
	}

	client := aws.GetClient()
	resp, err := client.TaskRegister(input)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			utils.ErrorOutput(err.Error())
		}
		return 1
	}

	fmt.Printf("Success register task %s.", family)
	fmt.Println(awsutil.StringValue(resp))
	return 0
}
예제 #4
0
// Run is Command implementation method for ClusterCreateCommand.
func (c *ClusterCreateCommand) Run(args []string) int {
	var name string
	flags := flag.NewFlagSet("cluster", flag.ContinueOnError)
	flags.StringVar(&name, "name", "", "cluster name")
	flags.Usage = func() { c.Help() }

	if err := flags.Parse(args); err != nil {
		utils.ErrorOutputf("Error parsing CLI flags: %s", err)
		fmt.Println(c.Help())
		return 1
	}

	if name == "" {
		utils.ErrorOutput("Error: -name option required.")
		return 1
	}

	input := &ecs.CreateClusterInput{
		ClusterName: &name,
	}

	client := aws.GetClient()
	resp, err := client.ClusterCreate(input)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			utils.ErrorOutput(err.Error())
		}
		return 1
	}
	fmt.Println(awsutil.StringValue(resp))
	return 0
}
예제 #5
0
// Run is Command implementation method for TaskDefsCommand.
func (c *TaskDefsCommand) Run(args []string) int {
	var familyPrefix, nextToken, status string
	var max int64
	var desc bool
	flags := flag.NewFlagSet("defs", flag.ContinueOnError)
	flags.StringVar(&familyPrefix, "prefix", "", "task definition family prefix string(require full family name)")
	flags.Int64Var(&max, "max", 10, "the number of task definition to show")
	flags.StringVar(&nextToken, "next", "", "next token")
	flags.BoolVar(&desc, "desc", false, "sort task definitions ASC or DESC")
	flags.StringVar(&status, "status", "ACTIVE", "task definition status")
	flags.Usage = func() { c.Help() }

	if err := flags.Parse(args); err != nil {
		utils.ErrorOutputf("Error parsing CLI flags: %s", err)
		fmt.Println(c.Help())
		return 1
	}

	input := generateListTaskDefinitionsInput(familyPrefix, max, nextToken, desc, status)

	client := aws.GetClient()
	resp, err := client.TaskDefs(input)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			utils.ErrorOutput(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				utils.ErrorOutput(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			utils.ErrorOutput(err.Error())
		}
		return 1
	}
	fmt.Println(awsutil.StringValue(resp))
	return 0
}