当前位置: 首页>>代码示例>>Golang>>正文


Golang locator.NewContainerLocators函数代码示例

本文整理汇总了Golang中github.com/openshift/geard/containers/locator.NewContainerLocators函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContainerLocators函数的具体用法?Golang NewContainerLocators怎么用?Golang NewContainerLocators使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewContainerLocators函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: restartContainer

func (ctx *CommandContext) restartContainer(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

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

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.RestartContainerRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:25,代码来源:cmd.go

示例2: linkContainers

func (ctx *CommandContext) linkContainers(c *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}

	t := ctx.Transport.Get()

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

	cmd.Executor{
		On: ids,
		Group: func(on ...cmd.Locator) cmd.JobRequest {
			links := &containers.ContainerLinks{make([]containers.ContainerLink, 0, len(on))}
			for i := range on {
				links.Links = append(links.Links, containers.ContainerLink{cloc.AsIdentifier(on[i]), *ctx.networkLinks.NetworkLinks})
			}
			return &cjobs.LinkContainersRequest{links}
		},
		Output: os.Stdout,
		OnSuccess: func(r *cmd.CliJobResponse, w io.Writer, job cmd.RequestedJob) {
			fmt.Fprintf(w, "Links set on %s\n", job.Request.(*cjobs.LinkContainersRequest).ContainerLinks.String())
		},
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:31,代码来源:cmd.go

示例3: deleteContainer

func (ctx *CommandContext) deleteContainer(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

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

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

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

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.DeleteContainerRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		Output: os.Stdout,
		OnSuccess: func(r *cmd.CliJobResponse, w io.Writer, job cmd.RequestedJob) {
			fmt.Fprintf(w, "Deleted %s", string(job.Request.(*cjobs.DeleteContainerRequest).Id))
		},
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:30,代码来源:cmd.go

示例4: setEnvironment

func (ctx *CommandContext) setEnvironment(c *cobra.Command, args []string) {
	if err := ctx.environment.ExtractVariablesFrom(&args, false); err != nil {
		cmd.Fail(1, err.Error())
	}

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

	t := ctx.Transport.Get()

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

	cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			ctx.environment.Description.Id = cloc.AsIdentifier(on)
			if ctx.resetEnv {
				return &cjobs.PutEnvironmentRequest{ctx.environment.Description}
			}

			return &cjobs.PatchEnvironmentRequest{ctx.environment.Description}
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:pmorie,项目名称:geard,代码行数:30,代码来源:cmd.go

示例5: installImage

func (ctx *CommandContext) installImage(c *cobra.Command, args []string) {
	if err := ctx.environment.ExtractVariablesFrom(&args, true); err != nil {
		cmd.Fail(1, err.Error())
	}

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

	t := ctx.Transport.Get()

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

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

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

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

				Ports:        *ctx.portPairs.Get().(*port.PortPairs),
				Environment:  &ctx.environment.Description,
				NetworkLinks: ctx.networkLinks.NetworkLinks,
				VolumeConfig: ctx.volumeConfig.VolumeConfig,
				SystemdSlice: ctx.systemdSlice,
			}
			return &r
		},
		Output:    os.Stdout,
		Transport: t,
	}.StreamAndExit()
}
开发者ID:jcantrill,项目名称:geard,代码行数:50,代码来源:cmd.go

示例6: containerStatus

func (ctx *CommandContext) containerStatus(c *cobra.Command, args []string) {
	t := ctx.Transport.Get()

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

	data, errors := cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.ContainerStatusRequest{
				Id: cloc.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)
}
开发者ID:pmorie,项目名称:geard,代码行数:41,代码来源:cmd.go

示例7: showEnvironment

func (ctx *CommandContext) showEnvironment(c *cobra.Command, args []string) {
	if len(args) < 1 {
		cmd.Fail(1, "Valid arguments: <id> ...")
	}

	t := ctx.Transport.Get()

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

	data, errors := cmd.Executor{
		On: ids,
		Serial: func(on cmd.Locator) cmd.JobRequest {
			return &cjobs.GetEnvironmentRequest{
				Id: cloc.AsIdentifier(on),
			}
		},
		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)
}
开发者ID:pmorie,项目名称:geard,代码行数:36,代码来源:cmd.go


注:本文中的github.com/openshift/geard/containers/locator.NewContainerLocators函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。