~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to cmd/juju/addmachine.go

[r=wallyworld] Add container support to force-machine

The deploy --force-machine option now supports containers,
either deploying to existing containers or creating new
ones on nominated machines.

Example syntax:

 juju deploy mysql --force-machine 23
 juju deploy mysql --force-machine 24/lxc/3
 juju deploy mysql --force-machine lxc:25

The last example creates a new lxc container on
machine 25.

The add-machine syntax has been tweaked to remove the
leading "/" from the container arg.

https://codereview.appspot.com/10777044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
func (c *AddMachineCommand) Info() *cmd.Info {
30
30
        return &cmd.Info{
31
31
                Name:    "add-machine",
32
 
                Args:    "[<machine>/<container> | /<container>]",
 
32
                Args:    "[<container>:machine | <container>]",
33
33
                Purpose: "start a new, empty machine and optionally a container, or add a container to a machine",
34
34
                Doc:     "Machines are created in a clean state and ready to have units deployed.",
35
35
        }
52
52
        if containerSpec == "" {
53
53
                return nil
54
54
        }
55
 
        // container arg can either be 'machine/type' or '/type'
56
 
        sep := strings.Index(containerSpec, "/")
57
 
        if sep < 0 {
58
 
                return fmt.Errorf("malformed container argument %q", containerSpec)
 
55
        // container arg can either be 'type:machine' or 'type'
 
56
        if c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec); err != nil {
 
57
                if !state.IsMachineOrNewContainer(containerSpec) {
 
58
                        return fmt.Errorf("malformed container argument %q", containerSpec)
 
59
                }
 
60
                sep := strings.Index(containerSpec, ":")
 
61
                c.MachineId = containerSpec[sep+1:]
 
62
                c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec[:sep])
59
63
        }
60
 
        c.MachineId = containerSpec[:sep]
61
 
        c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec[sep+1:])
62
64
        return err
63
65
}
64
66