~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to cmd/juju/deploy.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:
17
17
 
18
18
type DeployCommand struct {
19
19
        EnvCommandBase
20
 
        CharmName      string
21
 
        ServiceName    string
22
 
        Config         cmd.FileVar
23
 
        Constraints    constraints.Value
24
 
        NumUnits       int // defaults to 1
25
 
        BumpRevision   bool
26
 
        RepoPath       string // defaults to JUJU_REPOSITORY
27
 
        ForceMachineId string
 
20
        CharmName        string
 
21
        ServiceName      string
 
22
        Config           cmd.FileVar
 
23
        Constraints      constraints.Value
 
24
        NumUnits         int // defaults to 1
 
25
        BumpRevision     bool
 
26
        RepoPath         string // defaults to JUJU_REPOSITORY
 
27
        ForceMachineSpec string
28
28
}
29
29
 
30
30
const deployDoc = `
61
61
        c.EnvCommandBase.SetFlags(f)
62
62
        f.IntVar(&c.NumUnits, "n", 1, "number of service units to deploy for principal charms")
63
63
        f.IntVar(&c.NumUnits, "num-units", 1, "")
64
 
        f.StringVar(&c.ForceMachineId, "force-machine", "", "Machine to deploy initial unit, bypasses constraints")
 
64
        f.StringVar(&c.ForceMachineSpec, "force-machine", "", "machine/container to deploy initial unit, bypasses constraints")
65
65
        f.BoolVar(&c.BumpRevision, "u", false, "increment local charm directory revision")
66
66
        f.BoolVar(&c.BumpRevision, "upgrade", false, "")
67
67
        f.Var(&c.Config, "config", "path to yaml-formatted service config")
91
91
        if c.NumUnits < 1 {
92
92
                return errors.New("--num-units must be a positive integer")
93
93
        }
94
 
        if c.ForceMachineId != "" {
 
94
        if c.ForceMachineSpec != "" {
95
95
                if c.NumUnits > 1 {
96
 
                        return errors.New("cannot use --num-units with --force-machine")
 
96
                        return errors.New("cannot use --num-units > 1 with --force-machine")
97
97
                }
98
 
                if !state.IsMachineId(c.ForceMachineId) {
99
 
                        return fmt.Errorf("invalid machine id %q", c.ForceMachineId)
 
98
                if !state.IsMachineOrNewContainer(c.ForceMachineSpec) {
 
99
                        return fmt.Errorf("invalid --force-machine parameter %q", c.ForceMachineSpec)
100
100
                }
101
101
        }
102
102
        return nil
135
135
                if c.Constraints != empty {
136
136
                        return errors.New("cannot use --constraints with subordinate service")
137
137
                }
138
 
                if numUnits == 1 && c.ForceMachineId == "" {
 
138
                if numUnits == 1 && c.ForceMachineSpec == "" {
139
139
                        numUnits = 0
140
140
                } else {
141
141
                        return errors.New("cannot use --num-units or --force-machine with subordinate service")
157
157
                }
158
158
        }
159
159
        _, err = conn.DeployService(juju.DeployServiceParams{
160
 
                ServiceName:    serviceName,
161
 
                Charm:          ch,
162
 
                NumUnits:       numUnits,
163
 
                ConfigSettings: settings,
164
 
                Constraints:    c.Constraints,
165
 
                ForceMachineId: c.ForceMachineId,
 
160
                ServiceName:      serviceName,
 
161
                Charm:            ch,
 
162
                NumUnits:         numUnits,
 
163
                ConfigSettings:   settings,
 
164
                Constraints:      c.Constraints,
 
165
                ForceMachineSpec: c.ForceMachineSpec,
166
166
        })
167
167
        return err
168
168
}