예제 #1
0
func (s *S) newContainer(opts *newContainerOpts, p *dockerProvisioner) (*container.Container, error) {
	container := container.Container{
		Id:       "id",
		PublicIp: "10.10.10.10",
		HostPort: "3333",
		HostAddr: "127.0.0.1",
	}
	if p == nil {
		p = s.p
	}
	image := "github.com/megamsys/vertice/python:latest"
	var customData map[string]interface{}
	if opts != nil {
		if opts.Image != "" {
			image = opts.Image
		}
		container.Status = opts.Status
		container.BoxName = opts.BoxName
		if opts.Provisioner != nil {
			p = opts.Provisioner
		}
	}
	err := s.newFakeImage(p, image, customData)
	if err != nil {
		return nil, err
	}
	if container.BoxName == "" {
		container.BoxName = "container"
	}
	port := "9999"
	if err != nil {
		return nil, err
	}
	ports := map[docker.Port]struct{}{
		docker.Port(port + "/tcp"): {},
	}
	config := docker.Config{
		Image:        image,
		Cmd:          []string{"ps"},
		ExposedPorts: ports,
	}
	_, c, err := p.Cluster().CreateContainer(docker.CreateContainerOptions{Config: &config})
	if err != nil {
		return nil, err
	}
	container.Id = c.ID
	container.Image = image
	imageId := "testimageid"

	err = s.newFakeImage(p, imageId, nil)
	if err != nil {
		return nil, err
	}
	return &container, nil
}
예제 #2
0
	return nil
}

var updateStatusInRiak = action.Action{
	Name: "update-status-riak",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		args := ctx.Params[0].(runContainerActionsArgs)
		var cont container.Container

		if ctx.Previous != nil {
			cont = ctx.Previous.(container.Container)
		} else {
			ncont, _ := args.provisioner.GetContainerByBox(args.box)
			cont = *ncont
			cont.Image = args.imageId
		}

		if err := cont.SetStatus(args.containerStatus); err != nil {
			return nil, err
		}
		return cont, nil
	},
	Backward: func(ctx action.BWContext) {
		c := ctx.FWResult.(container.Container)
		c.SetStatus(provision.StatusError)
	},
}

var createContainer = action.Action{
	Name: "create-container",