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


Golang Container.ID方法代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/provision/docker/container.Container.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.ID方法的具体用法?Golang Container.ID怎么用?Golang Container.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tsuru/tsuru/provision/docker/container.Container的用法示例。


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

示例1: moveOneContainer

func (p *FakeDockerProvisioner) moveOneContainer(cont container.Container, toHost string) (container.Container, error) {
	cont, index, err := p.findContainer(cont.ID)
	if err != nil {
		return cont, err
	}
	if cont.HostAddr == toHost {
		return cont, nil
	}
	if toHost == "" {
		for host := range p.containers {
			if host != cont.HostAddr {
				toHost = host
				break
			}
		}
	}
	originHost := cont.HostAddr
	moving := ContainerMoving{
		ContainerID: cont.ID,
		HostFrom:    originHost,
		HostTo:      toHost,
	}
	p.movings = append(p.movings, moving)
	if toHost == "" {
		cont.ID += "-recreated"
		p.containers[originHost][index] = cont
		return cont, nil
	}
	cont.HostAddr = toHost
	cont.ID += "-moved"
	last := len(p.containers[originHost]) - 1
	p.containers[originHost][index] = p.containers[originHost][last]
	p.containers[originHost] = p.containers[originHost][:last]
	p.containers[cont.HostAddr] = append(p.containers[cont.HostAddr], cont)
	return cont, nil
}
开发者ID:tsuru,项目名称:tsuru,代码行数:36,代码来源:provisioner.go

示例2: TestUpdateContainerInDBForward

func (s *S) TestUpdateContainerInDBForward(c *check.C) {
	cont := container.Container{Name: "myName"}
	coll := s.p.Collection()
	defer coll.Close()
	err := coll.Insert(cont)
	c.Assert(err, check.IsNil)
	cont.ID = "myID"
	context := action.FWContext{Previous: cont, Params: []interface{}{runContainerActionsArgs{
		provisioner: s.p,
	}}}
	r, err := updateContainerInDB.Forward(context)
	c.Assert(r, check.FitsTypeOf, container.Container{})
	retrieved, err := s.p.GetContainer(cont.ID)
	c.Assert(err, check.IsNil)
	c.Assert(retrieved.ID, check.Equals, cont.ID)
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:16,代码来源:actions_test.go

示例3: newContainer

func (s *S) newContainer(opts *newContainerOpts, p *dockerProvisioner) (*container.Container, error) {
	container := container.Container{
		ID:          "id",
		IP:          "10.10.10.10",
		HostPort:    "3333",
		HostAddr:    "127.0.0.1",
		ProcessName: "web",
		ExposedPort: "8888/tcp",
	}
	if p == nil {
		p = s.p
	}
	image := "tsuru/python:latest"
	var customData map[string]interface{}
	if opts != nil {
		if opts.Image != "" {
			image = opts.Image
		}
		container.Status = opts.Status
		container.AppName = opts.AppName
		container.ProcessName = opts.ProcessName
		customData = opts.ImageCustomData
		if opts.Provisioner != nil {
			p = opts.Provisioner
		}
	}
	err := s.newFakeImage(p, image, customData)
	if err != nil {
		return nil, err
	}
	if container.AppName == "" {
		container.AppName = "container"
	}
	routertest.FakeRouter.AddBackend(container.AppName)
	routertest.FakeRouter.AddRoute(container.AppName, container.Address())
	ports := map[docker.Port]struct{}{
		docker.Port(s.port + "/tcp"): {},
	}
	config := docker.Config{
		Image:        image,
		Cmd:          []string{"ps"},
		ExposedPorts: ports,
	}
	createOptions := docker.CreateContainerOptions{Config: &config}
	createOptions.Name = randomString()
	_, c, err := p.Cluster().CreateContainer(createOptions)
	if err != nil {
		return nil, err
	}
	container.ID = c.ID
	container.Image = image
	container.Name = createOptions.Name
	conn, err := db.Conn()
	if err != nil {
		return nil, err
	}
	defer conn.Close()
	err = conn.Collection(s.collName).Insert(&container)
	if err != nil {
		return nil, err
	}
	imageId, err := appCurrentImageName(container.AppName)
	if err != nil {
		return nil, err
	}
	err = s.newFakeImage(p, imageId, nil)
	if err != nil {
		return nil, err
	}
	return &container, nil
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:71,代码来源:docker_test.go


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