本文整理汇总了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
}
示例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)
}
示例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
}