예제 #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 linkContainers(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}

	t := defaultTransport.Get()

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

	gcmd.Executor{
		On: ids,
		Group: func(on ...gcmd.Locator) gcmd.JobRequest {
			links := &containers.ContainerLinks{make([]containers.ContainerLink, 0, len(on))}
			for i := range on {
				links.Links = append(links.Links, containers.ContainerLink{gcmd.AsIdentifier(on[i]), *networkLinks.NetworkLinks})
			}
			return &cjobs.LinkContainersRequest{links}
		},
		Output: os.Stdout,
		OnSuccess: func(r *gcmd.CliJobResponse, w io.Writer, job gcmd.JobRequest) {
			fmt.Fprintf(w, "Links set on %s\n", job.(*cjobs.LinkContainersRequest).ContainerLinks.String())
		},
		Transport: t,
	}.StreamAndExit()
}
예제 #3
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()
}
예제 #4
0
파일: commands.go 프로젝트: jhadvig/geard
func setEnvironment(cmd *cobra.Command, args []string) {
	if err := environment.ExtractVariablesFrom(&args, false); err != nil {
		gcmd.Fail(1, err.Error())
	}

	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <name>... <key>=<value>...")
	}

	t := defaultTransport.Get()

	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 {
			environment.Description.Id = gcmd.AsIdentifier(on)
			if resetEnv {
				return &cjobs.PutEnvironmentRequest{environment.Description}
			}

			return &cjobs.PatchEnvironmentRequest{environment.Description}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
예제 #5
0
파일: commands.go 프로젝트: jhadvig/geard
func installImage(cmd *cobra.Command, args []string) {
	if err := environment.ExtractVariablesFrom(&args, true); err != nil {
		gcmd.Fail(1, err.Error())
	}

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

	t := defaultTransport.Get()

	imageId := args[0]
	if imageId == "" {
		gcmd.Fail(1, "Argument 1 must be a Docker image to base the service on")
	}
	ids, err := gcmd.NewContainerLocators(t, args[1:]...)
	if err != nil {
		gcmd.Fail(1, "You must pass one or more valid service names: %s", err.Error())
	}

	for _, locator := range ids {
		if imageId == string(gcmd.AsIdentifier(locator)) {
			gcmd.Fail(1, "Image name and container id must not be the same: %s", imageId)
		}
	}

	gcmd.Executor{
		On: ids,
		Serial: func(on gcmd.Locator) gcmd.JobRequest {
			r := cjobs.InstallContainerRequest{
				RequestIdentifier: jobs.NewRequestIdentifier(),

				Id:               gcmd.AsIdentifier(on),
				Image:            imageId,
				Started:          start,
				Isolate:          isolate,
				SocketActivation: sockAct,

				Ports:        *portPairs.Get().(*port.PortPairs),
				Environment:  &environment.Description,
				NetworkLinks: networkLinks.NetworkLinks,
			}
			return &r
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
예제 #6
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)
}
예제 #7
0
파일: commands.go 프로젝트: jhadvig/geard
func showEnvironment(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		gcmd.Fail(1, "Valid arguments: <id> ...")
	}

	t := defaultTransport.Get()

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

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

	for i := range data {
		if buf, ok := data[i].(*bytes.Buffer); ok {
			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)
}