예제 #1
0
파일: commands.go 프로젝트: jhadvig/geard
func restartContainer(cmd *cobra.Command, args []string) {
	t := defaultTransport.Get()

	if err := gcmd.ExtractContainerLocatorsFromDeployment(t, deploymentPath, &args); err != nil {
		gcmd.Fail(1, err.Error())
	}
	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}
	ids, err := gcmd.NewContainerLocators(t, args...)
	if err != nil {
		gcmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	gcmd.Executor{
		On: ids,
		Serial: func(on gcmd.Locator) gcmd.JobRequest {
			return &cjobs.RestartContainerRequest{
				Id: gcmd.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
예제 #2
0
파일: commands.go 프로젝트: jhadvig/geard
func deleteContainer(cmd *cobra.Command, args []string) {
	t := defaultTransport.Get()

	if err := gcmd.ExtractContainerLocatorsFromDeployment(t, deploymentPath, &args); err != nil {
		gcmd.Fail(1, err.Error())
	}

	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}

	ids, err := gcmd.NewContainerLocators(t, args...)
	if err != nil {
		gcmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	gcmd.Executor{
		On: ids,
		Serial: func(on gcmd.Locator) gcmd.JobRequest {
			return &cjobs.DeleteContainerRequest{
				Id: gcmd.AsIdentifier(on),
			}
		},
		Output: os.Stdout,
		OnSuccess: func(r *gcmd.CliJobResponse, w io.Writer, job gcmd.JobRequest) {
			fmt.Fprintf(w, "Deleted %s", string(job.(*cjobs.DeleteContainerRequest).Id))
		},
		Transport: t,
	}.StreamAndExit()
}
예제 #3
0
파일: commands.go 프로젝트: jhadvig/geard
func containerStatus(cmd *cobra.Command, args []string) {
	t := defaultTransport.Get()

	if err := gcmd.ExtractContainerLocatorsFromDeployment(t, deploymentPath, &args); err != nil {
		gcmd.Fail(1, err.Error())
	}
	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}
	ids, err := gcmd.NewContainerLocators(t, args...)
	if err != nil {
		gcmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	data, errors := gcmd.Executor{
		On: ids,
		Serial: func(on gcmd.Locator) gcmd.JobRequest {
			return &cjobs.ContainerStatusRequest{
				Id: gcmd.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.Gather()

	for i := range data {
		if buf, ok := data[i].(*bytes.Buffer); ok {
			if i > 0 {
				fmt.Fprintf(os.Stdout, "\n-------------\n")
			}
			buf.WriteTo(os.Stdout)
		}
	}
	if len(errors) > 0 {
		for i := range errors {
			fmt.Fprintf(os.Stderr, "Error: %s\n", errors[i])
		}
		os.Exit(1)
	}
	os.Exit(0)
}